From b290c108454c67411dfd662b96b88638f83b12c2 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Fri, 25 Mar 2016 19:05:41 -0400 Subject: [PATCH 1/3] tests/sort: refactor to match other tests Instead of using numerals to denote individual cases, I used descriptive case names. I also changed the extension for the expected output fixture to match other tests. I removed one redundant test and another unnecessary helper function. --- ...{human1.ans => human_block_sizes.expected} | 0 .../{human1.txt => human_block_sizes.txt} | 0 .../{month1.ans => month_default.expected} | 0 .../sort/{month1.txt => month_default.txt} | 0 tests/fixtures/sort/numeric5.ans | 2 - tests/fixtures/sort/numeric5.txt | 2 - ...ric4.ans => numeric_fixed_floats.expected} | 0 ...{numeric4.txt => numeric_fixed_floats.txt} | 0 .../{numeric2.ans => numeric_floats.expected} | 0 .../sort/{numeric2.txt => numeric_floats.txt} | 0 ...1.ans => numeric_floats_and_ints.expected} | 0 ...meric1.txt => numeric_floats_and_ints.txt} | 0 ...c3.ans => numeric_unfixed_floats.expected} | 0 ...umeric3.txt => numeric_unfixed_floats.txt} | 0 ...ic6.ans => numeric_unsorted_ints.expected} | 0 ...numeric6.txt => numeric_unsorted_ints.txt} | 0 tests/sort.rs | 41 ++++++++----------- 17 files changed, 16 insertions(+), 29 deletions(-) rename tests/fixtures/sort/{human1.ans => human_block_sizes.expected} (100%) rename tests/fixtures/sort/{human1.txt => human_block_sizes.txt} (100%) rename tests/fixtures/sort/{month1.ans => month_default.expected} (100%) rename tests/fixtures/sort/{month1.txt => month_default.txt} (100%) delete mode 100644 tests/fixtures/sort/numeric5.ans delete mode 100644 tests/fixtures/sort/numeric5.txt rename tests/fixtures/sort/{numeric4.ans => numeric_fixed_floats.expected} (100%) rename tests/fixtures/sort/{numeric4.txt => numeric_fixed_floats.txt} (100%) rename tests/fixtures/sort/{numeric2.ans => numeric_floats.expected} (100%) rename tests/fixtures/sort/{numeric2.txt => numeric_floats.txt} (100%) rename tests/fixtures/sort/{numeric1.ans => numeric_floats_and_ints.expected} (100%) rename tests/fixtures/sort/{numeric1.txt => numeric_floats_and_ints.txt} (100%) rename tests/fixtures/sort/{numeric3.ans => numeric_unfixed_floats.expected} (100%) rename tests/fixtures/sort/{numeric3.txt => numeric_unfixed_floats.txt} (100%) rename tests/fixtures/sort/{numeric6.ans => numeric_unsorted_ints.expected} (100%) rename tests/fixtures/sort/{numeric6.txt => numeric_unsorted_ints.txt} (100%) diff --git a/tests/fixtures/sort/human1.ans b/tests/fixtures/sort/human_block_sizes.expected similarity index 100% rename from tests/fixtures/sort/human1.ans rename to tests/fixtures/sort/human_block_sizes.expected diff --git a/tests/fixtures/sort/human1.txt b/tests/fixtures/sort/human_block_sizes.txt similarity index 100% rename from tests/fixtures/sort/human1.txt rename to tests/fixtures/sort/human_block_sizes.txt diff --git a/tests/fixtures/sort/month1.ans b/tests/fixtures/sort/month_default.expected similarity index 100% rename from tests/fixtures/sort/month1.ans rename to tests/fixtures/sort/month_default.expected diff --git a/tests/fixtures/sort/month1.txt b/tests/fixtures/sort/month_default.txt similarity index 100% rename from tests/fixtures/sort/month1.txt rename to tests/fixtures/sort/month_default.txt diff --git a/tests/fixtures/sort/numeric5.ans b/tests/fixtures/sort/numeric5.ans deleted file mode 100644 index 4c59f5cda..000000000 --- a/tests/fixtures/sort/numeric5.ans +++ /dev/null @@ -1,2 +0,0 @@ -.022 -.024 diff --git a/tests/fixtures/sort/numeric5.txt b/tests/fixtures/sort/numeric5.txt deleted file mode 100644 index 4c59f5cda..000000000 --- a/tests/fixtures/sort/numeric5.txt +++ /dev/null @@ -1,2 +0,0 @@ -.022 -.024 diff --git a/tests/fixtures/sort/numeric4.ans b/tests/fixtures/sort/numeric_fixed_floats.expected similarity index 100% rename from tests/fixtures/sort/numeric4.ans rename to tests/fixtures/sort/numeric_fixed_floats.expected diff --git a/tests/fixtures/sort/numeric4.txt b/tests/fixtures/sort/numeric_fixed_floats.txt similarity index 100% rename from tests/fixtures/sort/numeric4.txt rename to tests/fixtures/sort/numeric_fixed_floats.txt diff --git a/tests/fixtures/sort/numeric2.ans b/tests/fixtures/sort/numeric_floats.expected similarity index 100% rename from tests/fixtures/sort/numeric2.ans rename to tests/fixtures/sort/numeric_floats.expected diff --git a/tests/fixtures/sort/numeric2.txt b/tests/fixtures/sort/numeric_floats.txt similarity index 100% rename from tests/fixtures/sort/numeric2.txt rename to tests/fixtures/sort/numeric_floats.txt diff --git a/tests/fixtures/sort/numeric1.ans b/tests/fixtures/sort/numeric_floats_and_ints.expected similarity index 100% rename from tests/fixtures/sort/numeric1.ans rename to tests/fixtures/sort/numeric_floats_and_ints.expected diff --git a/tests/fixtures/sort/numeric1.txt b/tests/fixtures/sort/numeric_floats_and_ints.txt similarity index 100% rename from tests/fixtures/sort/numeric1.txt rename to tests/fixtures/sort/numeric_floats_and_ints.txt diff --git a/tests/fixtures/sort/numeric3.ans b/tests/fixtures/sort/numeric_unfixed_floats.expected similarity index 100% rename from tests/fixtures/sort/numeric3.ans rename to tests/fixtures/sort/numeric_unfixed_floats.expected diff --git a/tests/fixtures/sort/numeric3.txt b/tests/fixtures/sort/numeric_unfixed_floats.txt similarity index 100% rename from tests/fixtures/sort/numeric3.txt rename to tests/fixtures/sort/numeric_unfixed_floats.txt diff --git a/tests/fixtures/sort/numeric6.ans b/tests/fixtures/sort/numeric_unsorted_ints.expected similarity index 100% rename from tests/fixtures/sort/numeric6.ans rename to tests/fixtures/sort/numeric_unsorted_ints.expected diff --git a/tests/fixtures/sort/numeric6.txt b/tests/fixtures/sort/numeric_unsorted_ints.txt similarity index 100% rename from tests/fixtures/sort/numeric6.txt rename to tests/fixtures/sort/numeric_unsorted_ints.txt diff --git a/tests/sort.rs b/tests/sort.rs index ef6bdc4b1..9edfa52d3 100644 --- a/tests/sort.rs +++ b/tests/sort.rs @@ -7,54 +7,45 @@ static UTIL_NAME: &'static str = "sort"; #[test] -fn numeric1() { - numeric_helper(1); +fn test_numeric_floats_and_ints() { + test_helper("numeric_floats_and_ints", &String::from("-n")); } #[test] -fn numeric2() { - numeric_helper(2); +fn test_numeric_floats() { + test_helper("numeric_floats", &String::from("-n")); } #[test] -fn numeric3() { - numeric_helper(3); +fn test_numeric_unfixed_floats() { + test_helper("numeric_unfixed_floats", &String::from("-n")); } #[test] -fn numeric4() { - numeric_helper(4); +fn test_numeric_fixed_floats() { + test_helper("numeric_fixed_floats", &String::from("-n")); } #[test] -fn numeric5() { - numeric_helper(5); +fn test_numeric_unsorted_ints() { + test_helper("numeric_unsorted_ints", &String::from("-n")); } #[test] -fn numeric6() { - numeric_helper(6); +fn test_human_block_sizes() { + test_helper("human_block_sizes", &String::from("-h")); } #[test] -fn human1() { - test_helper(&String::from("human1"), &String::from("-h")); +fn test_month_default() { + test_helper("month_default", &String::from("-M")); } -#[test] -fn month1() { - test_helper(&String::from("month1"), &String::from("-M")); -} - -fn numeric_helper(test_num: isize) { - test_helper(&format!("numeric{}", test_num), &String::from("-n")) -} - -fn test_helper(file_name: &String, args: &String) { +fn test_helper(file_name: &str, args: &String) { let (at, mut ucmd) = testing(UTIL_NAME); ucmd.arg(args); let out = ucmd.arg(format!("{}{}", file_name, ".txt")).run().stdout; - let filename = format!("{}{}", file_name, ".ans"); + let filename = format!("{}{}", file_name, ".expected"); assert_eq!(out, at.read(&filename)); } From 6b129887d6446d12ed91f8e3a5253f1b2bbe2913 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Fri, 25 Mar 2016 21:27:12 -0400 Subject: [PATCH 2/3] tests/sort: add test for default mode --- .../sort/default_unsorted_ints.expected | 100 ++++++++++++++++++ tests/fixtures/sort/default_unsorted_ints.txt | 100 ++++++++++++++++++ tests/sort.rs | 5 + 3 files changed, 205 insertions(+) create mode 100644 tests/fixtures/sort/default_unsorted_ints.expected create mode 100644 tests/fixtures/sort/default_unsorted_ints.txt diff --git a/tests/fixtures/sort/default_unsorted_ints.expected b/tests/fixtures/sort/default_unsorted_ints.expected new file mode 100644 index 000000000..5c8fcffdf --- /dev/null +++ b/tests/fixtures/sort/default_unsorted_ints.expected @@ -0,0 +1,100 @@ +1 +10 +100 +11 +12 +13 +14 +15 +16 +17 +18 +19 +2 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +3 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +4 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +5 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +6 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +7 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +8 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +9 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 diff --git a/tests/fixtures/sort/default_unsorted_ints.txt b/tests/fixtures/sort/default_unsorted_ints.txt new file mode 100644 index 000000000..d3c2bb861 --- /dev/null +++ b/tests/fixtures/sort/default_unsorted_ints.txt @@ -0,0 +1,100 @@ +33 +16 +35 +56 +72 +37 +21 +49 +70 +48 +90 +83 +44 +79 +10 +20 +4 +26 +27 +63 +29 +47 +51 +85 +88 +46 +30 +61 +93 +81 +78 +53 +87 +18 +98 +38 +13 +39 +23 +71 +5 +100 +96 +8 +24 +14 +28 +15 +25 +43 +36 +67 +75 +66 +31 +57 +34 +80 +40 +86 +17 +55 +9 +1 +62 +12 +74 +58 +69 +76 +11 +73 +68 +59 +41 +45 +52 +97 +82 +6 +7 +77 +42 +84 +95 +94 +89 +19 +64 +2 +22 +50 +60 +32 +92 +3 +99 +65 +54 +91 diff --git a/tests/sort.rs b/tests/sort.rs index 9edfa52d3..a12388378 100644 --- a/tests/sort.rs +++ b/tests/sort.rs @@ -41,6 +41,11 @@ fn test_month_default() { test_helper("month_default", &String::from("-M")); } +#[test] +fn test_default_unsorted_ints() { + test_helper("default_unsorted_ints", &String::from("")); +} + fn test_helper(file_name: &str, args: &String) { let (at, mut ucmd) = testing(UTIL_NAME); ucmd.arg(args); From fb0e6a9deedd2135a4afabbd1abe50b69b4b1a6c Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Fri, 25 Mar 2016 21:29:11 -0400 Subject: [PATCH 3/3] tests/sort: simplify input to helper --- tests/sort.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/sort.rs b/tests/sort.rs index a12388378..5544290c8 100644 --- a/tests/sort.rs +++ b/tests/sort.rs @@ -8,45 +8,45 @@ static UTIL_NAME: &'static str = "sort"; #[test] fn test_numeric_floats_and_ints() { - test_helper("numeric_floats_and_ints", &String::from("-n")); + test_helper("numeric_floats_and_ints", "-n"); } #[test] fn test_numeric_floats() { - test_helper("numeric_floats", &String::from("-n")); + test_helper("numeric_floats", "-n"); } #[test] fn test_numeric_unfixed_floats() { - test_helper("numeric_unfixed_floats", &String::from("-n")); + test_helper("numeric_unfixed_floats", "-n"); } #[test] fn test_numeric_fixed_floats() { - test_helper("numeric_fixed_floats", &String::from("-n")); + test_helper("numeric_fixed_floats", "-n"); } #[test] fn test_numeric_unsorted_ints() { - test_helper("numeric_unsorted_ints", &String::from("-n")); + test_helper("numeric_unsorted_ints", "-n"); } #[test] fn test_human_block_sizes() { - test_helper("human_block_sizes", &String::from("-h")); + test_helper("human_block_sizes", "-h"); } #[test] fn test_month_default() { - test_helper("month_default", &String::from("-M")); + test_helper("month_default", "-M"); } #[test] fn test_default_unsorted_ints() { - test_helper("default_unsorted_ints", &String::from("")); + test_helper("default_unsorted_ints", ""); } -fn test_helper(file_name: &str, args: &String) { +fn test_helper(file_name: &str, args: &str) { let (at, mut ucmd) = testing(UTIL_NAME); ucmd.arg(args); let out = ucmd.arg(format!("{}{}", file_name, ".txt")).run().stdout;