Skip to content

Commit 9842bf2

Browse files
authored
Merge pull request #168 from rustcoreutils/hacking
Modularize test suite
2 parents 665d048 + bdf1402 commit 9842bf2

File tree

53 files changed

+948
-817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+948
-817
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ fn test_bc_with_math_library(program: &str, expected_output: &str) {
3434
macro_rules! test_bc {
3535
($test_name:ident) => {
3636
test_bc(
37-
include_str!(concat!("bc/", stringify!($test_name), ".bc")),
38-
include_str!(concat!("bc/", stringify!($test_name), ".out")),
37+
include_str!(concat!("./", stringify!($test_name), ".bc")),
38+
include_str!(concat!("./", stringify!($test_name), ".out")),
3939
)
4040
};
4141
}
4242

4343
macro_rules! test_bc_l {
4444
($test_name:ident) => {
4545
test_bc_with_math_library(
46-
include_str!(concat!("bc/", stringify!($test_name), ".bc")),
47-
include_str!(concat!("bc/", stringify!($test_name), ".out")),
46+
include_str!(concat!("./", stringify!($test_name), ".bc")),
47+
include_str!(concat!("./", stringify!($test_name), ".out")),
4848
)
4949
};
5050
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//
2-
// Copyright (c) 2024 Hemi Labs, Inc.
2+
// Copyright (c) 2024 Jeff Garzik
33
//
44
// This file is part of the posixutils-rs project covered under
55
// the MIT License. For the full license text, please see the LICENSE
66
// file in the root directory of this project.
77
// SPDX-License-Identifier: MIT
88
//
99

10-
mod ls;
10+
mod bc;
11+
mod expr;
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//
2-
// Copyright (c) 2024 Hemi Labs, Inc.
2+
// Copyright (c) 2024 Jeff Garzik
33
//
44
// This file is part of the posixutils-rs project covered under
55
// the MIT License. For the full license text, please see the LICENSE
66
// file in the root directory of this project.
77
// SPDX-License-Identifier: MIT
88
//
99

10-
mod mv;
10+
mod echo;
11+
mod printf;

file/tests/cmp/mod.rs

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//
2+
// Copyright (c) 2024 Jeff Garzik
3+
//
4+
// This file is part of the posixutils-rs project covered under
5+
// the MIT License. For the full license text, please see the LICENSE
6+
// file in the root directory of this project.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
10+
use plib::{run_test, TestPlan};
11+
12+
fn run_test_helper(
13+
args: &[&str],
14+
expected_output: &str,
15+
expected_error: &str,
16+
expected_exit_code: i32,
17+
) {
18+
let str_args: Vec<String> = args.iter().map(|s| String::from(*s)).collect();
19+
20+
run_test(TestPlan {
21+
cmd: String::from("cmp"),
22+
args: str_args,
23+
stdin_data: String::new(),
24+
expected_out: String::from(expected_output),
25+
expected_err: String::from(expected_error),
26+
expected_exit_code,
27+
});
28+
}
29+
30+
#[test]
31+
fn cmp_same() {
32+
let mut files = vec![String::from("tests/cmp/lorem_ipsum.txt")];
33+
let indices = [0, 45, 90, 135, 180, 225, 270, 315, 360, 405, 450];
34+
for i in indices {
35+
files.push(format!("tests/cmp/lorem_ipsum_{i}.txt"));
36+
}
37+
38+
for file in &files {
39+
run_test_helper(&[file, file], "", "", 0);
40+
}
41+
}
42+
43+
#[test]
44+
fn cmp_different() {
45+
let original = "tests/cmp/lorem_ipsum.txt";
46+
47+
let indices = [0, 45, 90, 135, 180, 225, 270, 315, 360, 405, 450];
48+
let bytes = [1, 46, 91, 136, 181, 226, 271, 316, 361, 406, 451];
49+
let lines = [1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 7];
50+
51+
for i in 0..indices.len() {
52+
let modified = format!("tests/cmp/lorem_ipsum_{}.txt", indices[i]);
53+
run_test_helper(
54+
&[original, &modified],
55+
&format!(
56+
"{original} {modified} differ: char {}, line {}\n",
57+
bytes[i], lines[i]
58+
),
59+
"",
60+
1,
61+
);
62+
}
63+
}
64+
65+
#[test]
66+
fn cmp_different_silent() {
67+
let original = "tests/cmp/lorem_ipsum.txt";
68+
69+
let indices = [0, 45, 90, 135, 180, 225, 270, 315, 360, 405, 450];
70+
71+
for i in 0..indices.len() {
72+
let modified = format!("tests/cmp/lorem_ipsum_{}.txt", indices[i]);
73+
run_test_helper(&["-s", original, &modified], "", "", 1);
74+
}
75+
}
76+
77+
#[test]
78+
fn cmp_different_less_verbose() {
79+
let original = "tests/cmp/lorem_ipsum.txt";
80+
81+
let indices = [0, 45, 90, 135, 180, 225, 270, 315, 360, 405, 450];
82+
let bytes = [1, 46, 91, 136, 181, 226, 271, 316, 361, 406, 451];
83+
let chars_original = ['L', 's', ' ', ' ', 'a', 'o', 'r', ' ', 'a', ' ', '.'];
84+
85+
for i in 0..indices.len() {
86+
let modified = format!("tests/cmp/lorem_ipsum_{}.txt", indices[i]);
87+
run_test_helper(
88+
&["-l", original, &modified],
89+
&format!(
90+
"{} {:o} {:o}\n",
91+
bytes[i], chars_original[i] as u8, '?' as u8
92+
),
93+
"",
94+
1,
95+
);
96+
}
97+
}
98+
99+
#[test]
100+
fn cmp_eof() {
101+
let original = "tests/cmp/lorem_ipsum.txt";
102+
let truncated = "tests/cmp/lorem_ipsum_trunc.txt";
103+
104+
// Status code must be 1. From the specification:
105+
//
106+
// "...this includes the case where one file is identical to the first part
107+
// of the other."
108+
run_test_helper(
109+
&[original, truncated],
110+
"",
111+
&format!("cmp: EOF on {truncated}\n"),
112+
1,
113+
);
114+
}

file/tests/file-tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// Copyright (c) 2024 Jeff Garzik
3+
//
4+
// This file is part of the posixutils-rs project covered under
5+
// the MIT License. For the full license text, please see the LICENSE
6+
// file in the root directory of this project.
7+
// SPDX-License-Identifier: MIT
8+
//
9+
10+
mod cmp;
11+
mod dd;
12+
mod file;
13+
mod od;

0 commit comments

Comments
 (0)