Skip to content

Commit c6d2fb9

Browse files
authored
Merge pull request #164 from rustcoreutils/hacking
Moar test work
2 parents 231fa77 + 9519f25 commit c6d2fb9

34 files changed

+292
-107
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,9 @@ Because it is a FAQ, the major differences between this project and uutils are:
6969
- [x] dirname
7070
- [x] expand
7171
- [x] expr
72-
- [x] file
7372
- [x] false
73+
- [x] file
74+
- [x] fold
7475
- [x] head
7576
- [x] ls
7677
- [x] mv
@@ -104,7 +105,6 @@ Because it is a FAQ, the major differences between this project and uutils are:
104105
- [x] chown
105106
- [x] date
106107
- [x] env
107-
- [x] fold
108108
- [x] ipcrm (IPC)
109109
- [x] link
110110
- [x] ln

Diff for: file/tests/dd-tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use plib::{run_test_u8, TestPlanU8};
77
fn get_test_file_path(filename: &str) -> PathBuf {
88
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
99
path.push("tests");
10+
path.push("dd");
1011
path.push(filename);
1112
path
1213
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: file/tests/dd.ibm renamed to file/tests/dd/dd.ibm

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: text/src/fold.rs

-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
// file in the root directory of this project.
77
// SPDX-License-Identifier: MIT
88
//
9-
// TODO:
10-
// - integration tests
11-
// - verify break-with-spaces correctness
12-
//
139

1410
extern crate clap;
1511
extern crate plib;

Diff for: text/tests/expand-tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn expand_test_noargs(test_data: &str, expected_output: &str) {
2222
}
2323

2424
#[test]
25-
fn test_expand_basic() {
25+
fn expand_basic() {
2626
expand_test_noargs("", "");
2727
expand_test_noargs("a\tb\tc\n", "a b c\n");
2828
}

Diff for: text/tests/fold-tests.rs

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//
2+
// Copyright (c) 2024 Hemi Labs, Inc.
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::testing::{run_test, TestPlan};
11+
use std::fs::File;
12+
use std::io::Read;
13+
use std::path::PathBuf;
14+
15+
fn get_test_file_path(filename: &str) -> PathBuf {
16+
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
17+
path.push("tests/fold");
18+
path.push(filename);
19+
path
20+
}
21+
22+
fn run_fold_test(args: Vec<&str>, input_filename: &str, expected_output_filename: &str) {
23+
let input_file_path = get_test_file_path(input_filename);
24+
let input_data = match File::open(input_file_path) {
25+
Ok(mut file) => {
26+
let mut data = String::new();
27+
file.read_to_string(&mut data).unwrap();
28+
data
29+
}
30+
Err(e) => {
31+
panic!("Error opening file: {}", e);
32+
}
33+
};
34+
35+
let expected_output_file_path = get_test_file_path(expected_output_filename);
36+
37+
let mut expected_output = String::new();
38+
File::open(expected_output_file_path)
39+
.unwrap()
40+
.read_to_string(&mut expected_output)
41+
.unwrap();
42+
43+
let args: Vec<String> = args.iter().map(|s| s.to_string()).collect();
44+
run_test(TestPlan {
45+
cmd: String::from("fold"),
46+
args,
47+
expected_out: expected_output,
48+
expected_err: String::new(),
49+
expected_exit_code: 0,
50+
stdin_data: input_data,
51+
});
52+
}
53+
54+
#[test]
55+
fn fold_default_behavior() {
56+
run_fold_test(vec![], "input1.txt", "output_default.txt");
57+
}
58+
59+
#[test]
60+
fn fold_custom_width() {
61+
run_fold_test(vec!["-w", "40"], "input1.txt", "output_width40.txt");
62+
}
63+
64+
#[test]
65+
fn fold_bytes_mode() {
66+
run_fold_test(vec!["-b"], "input1.txt", "output_bytes.txt");
67+
}
68+
69+
#[test]
70+
fn fold_spaces_mode() {
71+
run_fold_test(vec!["-s"], "input2.txt", "output_spaces.txt");
72+
}
73+
74+
#[test]
75+
fn fold_bytes_and_spaces_mode() {
76+
run_fold_test(vec!["-b", "-s"], "input2.txt", "output_bytes_spaces.txt");
77+
}

Diff for: text/tests/fold/input1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test file with several lines of varying lengths.

Diff for: text/tests/fold/input2.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Another example of a file with different line lengths and characters.

Diff for: text/tests/fold/output_bytes.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test file with several lines of varying lengths.

Diff for: text/tests/fold/output_bytes_spaces.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Another example of a file with different line lengths and characters.

Diff for: text/tests/fold/output_default.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a test file with several lines of varying lengths.

Diff for: text/tests/fold/output_spaces.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Another example of a file with different line lengths and characters.

Diff for: text/tests/fold/output_width40.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This is a test file with several lines o
2+
f varying lengths.

Diff for: text/tests/paste-tests.rs

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//
2+
// Copyright (c) 2024 Jeff Garzik
3+
// Copyright (c) 2024 Hemi Labs, Inc.
4+
//
5+
// This file is part of the posixutils-rs project covered under
6+
// the MIT License. For the full license text, please see the LICENSE
7+
// file in the root directory of this project.
8+
// SPDX-License-Identifier: MIT
9+
//
10+
11+
use plib::testing::{run_test, TestPlan};
12+
use std::fs::File;
13+
use std::io::Read;
14+
use std::path::PathBuf;
15+
16+
fn get_test_file_path(filename: &str) -> PathBuf {
17+
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
18+
path.push("tests/paste");
19+
path.push(filename);
20+
path
21+
}
22+
23+
fn run_paste_test(args: Vec<&str>, expected_output_filename: &str) {
24+
let expected_output_file_path = get_test_file_path(expected_output_filename);
25+
26+
let mut expected_output = String::new();
27+
File::open(expected_output_file_path)
28+
.unwrap()
29+
.read_to_string(&mut expected_output)
30+
.unwrap();
31+
32+
let args: Vec<String> = args.iter().map(|s| s.to_string()).collect();
33+
run_test(TestPlan {
34+
cmd: String::from("paste"),
35+
args,
36+
expected_out: expected_output,
37+
expected_err: String::new(),
38+
stdin_data: String::new(),
39+
expected_exit_code: 0,
40+
});
41+
}
42+
43+
#[test]
44+
fn paste_default_behavior() {
45+
run_paste_test(
46+
vec!["tests/paste/input1.txt", "tests/paste/input2.txt"],
47+
"output_default.txt",
48+
);
49+
}
50+
51+
#[test]
52+
fn paste_serial_mode() {
53+
run_paste_test(
54+
vec!["-s", "tests/paste/input1.txt", "tests/paste/input2.txt"],
55+
"output_serial.txt",
56+
);
57+
}
58+
59+
#[test]
60+
fn paste_custom_delimiter() {
61+
run_paste_test(
62+
vec![
63+
"-d",
64+
",",
65+
"tests/paste/input1.txt",
66+
"tests/paste/input2.txt",
67+
],
68+
"output_custom_delim.txt",
69+
);
70+
}
71+
72+
#[test]
73+
fn paste_serial_custom_delimiter() {
74+
run_paste_test(
75+
vec![
76+
"-s",
77+
"-d",
78+
",",
79+
"tests/paste/input1.txt",
80+
"tests/paste/input2.txt",
81+
],
82+
"output_serial_custom_delim.txt",
83+
);
84+
}

Diff for: text/tests/paste/input1.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apple
2+
banana
3+
carrot

Diff for: text/tests/paste/input2.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1
2+
2
3+
3

Diff for: text/tests/paste/input3.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
one
2+
two
3+
three

Diff for: text/tests/paste/output_custom_delim.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apple,1
2+
banana,2
3+
carrot,3

Diff for: text/tests/paste/output_default.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apple 1
2+
banana 2
3+
carrot 3

Diff for: text/tests/paste/output_serial.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
apple banana carrot
2+
1 2 3

Diff for: text/tests/paste/output_serial_custom_delim.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
apple,banana,carrot
2+
1,2,3

Diff for: text/tests/pr-tests.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn pr_read_test_file(
6060
}
6161

6262
#[test]
63-
fn test_pr_single_column() {
63+
fn pr_single_column() {
6464
let input = "tests/pr/lorem_ipsum.txt";
6565
let output = pr_read_test_file(
6666
"tests/pr/lorem_ipsum_output_single_column.txt",
@@ -72,14 +72,14 @@ fn test_pr_single_column() {
7272
}
7373

7474
#[test]
75-
fn test_pr_multi_column() {
75+
fn pr_multi_column() {
7676
let input = "tests/pr/lorem_ipsum.txt";
7777
let output = pr_read_test_file("tests/pr/lorem_ipsum_output_9_cols.txt", input, None, None);
7878
pr_test(&["-9", &input], "", &output);
7979
}
8080

8181
#[test]
82-
fn test_pr_multi_column_across() {
82+
fn pr_multi_column_across() {
8383
let input = "tests/pr/lorem_ipsum.txt";
8484
let output = pr_read_test_file(
8585
"tests/pr/lorem_ipsum_output_2_cols_across.txt",
@@ -91,7 +91,7 @@ fn test_pr_multi_column_across() {
9191
}
9292

9393
#[test]
94-
fn test_pr_multi_column_merge() {
94+
fn pr_multi_column_merge() {
9595
// This test requires the current timestamp.
9696
//
9797
// It's possible to inject the current timestamp to the expected output
@@ -135,7 +135,7 @@ fn test_pr_multi_column_merge() {
135135
}
136136

137137
#[test]
138-
fn test_pr_page_skip() {
138+
fn pr_page_skip() {
139139
let input = "tests/pr/numbers.txt";
140140
let output = pr_read_test_file(
141141
"tests/pr/numbers_output_9_cols_page15.txt",
@@ -147,7 +147,7 @@ fn test_pr_page_skip() {
147147
}
148148

149149
#[test]
150-
fn test_pr_header_replacement() {
150+
fn pr_header_replacement() {
151151
let header = "custom";
152152
let input = "tests/pr/lorem_ipsum.txt";
153153
let output = pr_read_test_file(
@@ -160,36 +160,36 @@ fn test_pr_header_replacement() {
160160
}
161161

162162
#[test]
163-
fn test_pr_limit_lines() {
163+
fn pr_limit_lines() {
164164
let input = "tests/pr/numbers.txt";
165165
let output = pr_read_test_file("tests/pr/numbers_output_l20.txt", input, None, None);
166166
pr_test(&["+1:1", "-l20", &input], "", &output);
167167
}
168168

169169
#[test]
170-
fn test_pr_limit_lines_trim() {
170+
fn pr_limit_lines_trim() {
171171
// Lines <= 10 behave like -t is used
172172
let input = "tests/pr/numbers.txt";
173173
let output = pr_read_test_file("tests/pr/numbers_output_l10.txt", input, None, None);
174174
pr_test(&["+1:1", "-l10", &input], "", &output);
175175
}
176176

177177
#[test]
178-
fn test_pr_omit_header() {
178+
fn pr_omit_header() {
179179
let input = "tests/pr/numbers.txt";
180180
let output = pr_read_test_file("tests/pr/numbers_output_omit_header.txt", input, None, None);
181181
pr_test(&["+1:1", "-l20", "-t", &input], "", &output);
182182
}
183183

184184
#[test]
185-
fn test_pr_offset() {
185+
fn pr_offset() {
186186
let input = "tests/pr/numbers.txt";
187187
let output = pr_read_test_file("tests/pr/numbers_output_offset.txt", input, None, None);
188188
pr_test(&["+1:1", "-o7", &input], "", &output);
189189
}
190190

191191
#[test]
192-
fn test_pr_width() {
192+
fn pr_width() {
193193
let input = "tests/pr/long_line.txt";
194194
let output = pr_read_test_file("tests/pr/long_line_output_w72.txt", input, None, None);
195195
pr_test(&["-2", "-t", "-w72", &input], "", &output);
@@ -203,7 +203,7 @@ fn test_pr_width() {
203203
}
204204

205205
#[test]
206-
fn test_pr_number_line() {
206+
fn pr_number_line() {
207207
let input = "tests/pr/lorem_ipsum.txt";
208208
let output = pr_read_test_file(
209209
"tests/pr/lorem_ipsum_output_number_line.txt",
@@ -215,7 +215,7 @@ fn test_pr_number_line() {
215215
}
216216

217217
#[test]
218-
fn test_pr_expand_and_replace() {
218+
fn pr_expand_and_replace() {
219219
let input = "tests/pr/spaces_and_tabs.txt";
220220
let output = pr_read_test_file(
221221
"tests/pr/spaces_and_tabs_expand_and_replace.txt",

0 commit comments

Comments
 (0)