Skip to content

Commit b86f761

Browse files
committed
[find] fix fails
1 parent ffefe01 commit b86f761

File tree

7 files changed

+32
-70
lines changed

7 files changed

+32
-70
lines changed

Cargo.lock

Lines changed: 0 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

file/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ regex.workspace = true
1616
walkdir = "2"
1717
users = "0.11"
1818

19-
[dev-dependencies]
20-
whoami = "1.5"
21-
2219
[[bin]]
2320
name = "cat"
2421
path = "src/cat.rs"

file/tests/find/mod.rs

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use std::fs::{remove_file, File};
2+
use std::io::Write;
3+
14
use plib::{run_test, TestPlan};
25

36
fn run_test_find(
@@ -21,18 +24,18 @@ fn run_test_find(
2124
#[test]
2225
fn find_size_test() {
2326
let project_root = env!("CARGO_MANIFEST_DIR");
24-
let test_dir = format!("{}/tests/find", project_root);
27+
let test_dir = format!("{}/tests/find/other", project_root);
2528
let args = [&test_dir, "-size", "+4"];
2629

27-
let expected_output = format!("{}\n{}/file1.txt\n{}/mod.rs\n", test_dir, test_dir, test_dir);
30+
let expected_output = format!("{}\n{}/file1.txt\n", test_dir, test_dir);
2831

2932
run_test_find(&args, &expected_output, "", 0)
3033
}
3134

3235
#[test]
3336
fn find_name_test() {
3437
let project_root = env!("CARGO_MANIFEST_DIR");
35-
let test_dir = format!("{}/tests/find", project_root);
38+
let test_dir = format!("{}/tests/find/other", project_root);
3639
let args = [&test_dir, "-name", "empty_file.txt"];
3740

3841
let expected_output = format!("{}/empty_file.txt\n", test_dir);
@@ -43,18 +46,18 @@ fn find_name_test() {
4346
#[test]
4447
fn find_type_test() {
4548
let project_root = env!("CARGO_MANIFEST_DIR");
46-
let test_dir = format!("{}/tests/find", project_root);
49+
let test_dir = format!("{}/tests/find/other", project_root);
4750
let args = [&test_dir, "-type", "f"];
4851

49-
let expected_output = format!("{}/empty_file.txt\n{}/file with space.txt\n{}/file1.txt\n{}/mod.rs\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir, test_dir);
52+
let expected_output = format!("{}/empty_file.txt\n{}/file with space.txt\n{}/file1.txt\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir);
5053

5154
run_test_find(&args, &expected_output, "", 0)
5255
}
5356

5457
#[test]
5558
fn find_mtime_test() {
5659
let project_root = env!("CARGO_MANIFEST_DIR");
57-
let test_dir = format!("{}/tests/find", project_root);
60+
let test_dir = format!("{}/tests/find/other", project_root);
5861
let args = [&test_dir, "-mtime", "7"];
5962

6063
run_test_find(&args, "", "", 0)
@@ -63,40 +66,40 @@ fn find_mtime_test() {
6366
#[test]
6467
fn find_combination_test() {
6568
let project_root = env!("CARGO_MANIFEST_DIR");
66-
let test_dir = format!("{}/tests/find", project_root);
69+
let test_dir = format!("{}/tests/find/other", project_root);
6770
let args = [&test_dir, "-size", "+4", "-print", "-size", "+2", "-print"];
6871

69-
let expected_output = format!("{}\n{}\n{}/file1.txt\n{}/file1.txt\n{}/mod.rs\n{}/mod.rs\n", test_dir, test_dir, test_dir, test_dir, test_dir, test_dir);
72+
let expected_output = format!("{}\n{}\n{}/file1.txt\n{}/file1.txt\n", test_dir, test_dir, test_dir, test_dir);
7073

7174
run_test_find(&args, &expected_output, "", 0)
7275
}
7376

7477
#[test]
7578
fn find_not_test() {
7679
let project_root = env!("CARGO_MANIFEST_DIR");
77-
let test_dir = format!("{}/tests/find", project_root);
80+
let test_dir = format!("{}/tests/find/other", project_root);
7881
let args = [&test_dir, "!", "-path", "*.txt"];
7982

80-
let expected_output = format!("{}\n{}/mod.rs\n{}/rust_file.rs\n", test_dir, test_dir, test_dir);
83+
let expected_output = format!("{}\n{}/rust_file.rs\n", test_dir, test_dir);
8184

8285
run_test_find(&args, &expected_output, "", 0)
8386
}
8487

8588
#[test]
8689
fn find_or_test() {
8790
let project_root = env!("CARGO_MANIFEST_DIR");
88-
let test_dir = format!("{}/tests/find", project_root);
91+
let test_dir = format!("{}/tests/find/other", project_root);
8992
let args = [&test_dir, "-path", "*.rs", "-o", "-path", "*.txt"];
9093

91-
let expected_output = format!("{}/empty_file.txt\n{}/file with space.txt\n{}/file1.txt\n{}/mod.rs\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir, test_dir);
94+
let expected_output = format!("{}/empty_file.txt\n{}/file with space.txt\n{}/file1.txt\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir);
9295

9396
run_test_find(&args, &expected_output, "", 0)
9497
}
9598

9699
#[test]
97100
fn find_and_test() {
98101
let project_root = env!("CARGO_MANIFEST_DIR");
99-
let test_dir = format!("{}/tests/find", project_root);
102+
let test_dir = format!("{}/tests/find/other", project_root);
100103
let args = [&test_dir, "-path", "*.txt", "-a", "-size", "+2"];
101104

102105
let expected_output = format!("{}/file1.txt\n", test_dir);
@@ -107,7 +110,7 @@ fn find_and_test() {
107110
#[test]
108111
fn find_space_argument_test() {
109112
let project_root = env!("CARGO_MANIFEST_DIR");
110-
let test_dir = format!("{}/tests/find", project_root);
113+
let test_dir = format!("{}/tests/find/other", project_root);
111114
let args = [&test_dir, "-name", "file with space.txt"];
112115

113116
let expected_output = format!("{}/file with space.txt\n", test_dir);
@@ -118,7 +121,7 @@ fn find_space_argument_test() {
118121
#[test]
119122
fn find_no_user_test() {
120123
let project_root = env!("CARGO_MANIFEST_DIR");
121-
let test_dir = format!("{}/tests/find", project_root);
124+
let test_dir = format!("{}/tests/find/other", project_root);
122125
let args = [&test_dir, "-nouser"];
123126

124127
run_test_find(&args, "", "", 0)
@@ -127,7 +130,7 @@ fn find_no_user_test() {
127130
#[test]
128131
fn find_no_group_test() {
129132
let project_root = env!("CARGO_MANIFEST_DIR");
130-
let test_dir = format!("{}/tests/find", project_root);
133+
let test_dir = format!("{}/tests/find/other", project_root);
131134
let args = [&test_dir, "-nogroup"];
132135

133136
run_test_find(&args, "", "", 0)
@@ -136,18 +139,18 @@ fn find_no_group_test() {
136139
#[test]
137140
fn find_x_dev_test() {
138141
let project_root = env!("CARGO_MANIFEST_DIR");
139-
let test_dir = format!("{}/tests/find", project_root);
142+
let test_dir = format!("{}/tests/find/other", project_root);
140143
let args = [&test_dir, "-xdev"];
141144

142-
let expected_output = format!("{}\n{}/empty_file.txt\n{}/file with space.txt\n{}/file1.txt\n{}/mod.rs\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir, test_dir, test_dir);
145+
let expected_output = format!("{}\n{}/empty_file.txt\n{}/file with space.txt\n{}/file1.txt\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir, test_dir);
143146

144147
run_test_find(&args, &expected_output, "", 0)
145148
}
146149

147150
#[test]
148151
fn find_perm_test() {
149152
let project_root = env!("CARGO_MANIFEST_DIR");
150-
let test_dir = format!("{}/tests/find", project_root);
153+
let test_dir = format!("{}/tests/find/other", project_root);
151154
let args = [&test_dir, "-perm", "777"];
152155

153156
run_test_find(&args, "", "", 0)
@@ -156,30 +159,18 @@ fn find_perm_test() {
156159
#[test]
157160
fn find_links_test() {
158161
let project_root = env!("CARGO_MANIFEST_DIR");
159-
let test_dir = format!("{}/tests/find", project_root);
162+
let test_dir = format!("{}/tests/find/other", project_root);
160163
let args = [&test_dir, "-links", "1"];
161164

162-
let expected_output = format!("{}/empty_file.txt\n{}/file with space.txt\n{}/file1.txt\n{}/mod.rs\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir, test_dir);
163-
164-
run_test_find(&args, &expected_output, "", 0)
165-
}
166-
167-
#[test]
168-
fn find_user_test() {
169-
let project_root = env!("CARGO_MANIFEST_DIR");
170-
let test_dir = format!("{}/tests/find", project_root);
171-
let username = whoami::username();
172-
let args = [&test_dir, "-user", &username];
173-
174-
let expected_output = format!("{}\n{}/empty_file.txt\n{}/file with space.txt\n{}/file1.txt\n{}/mod.rs\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir, test_dir, test_dir);
165+
let expected_output = format!("{}/empty_file.txt\n{}/file with space.txt\n{}/file1.txt\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir);
175166

176167
run_test_find(&args, &expected_output, "", 0)
177168
}
178169

179170
#[test]
180171
fn find_group_test() {
181172
let project_root = env!("CARGO_MANIFEST_DIR");
182-
let test_dir = format!("{}/tests/find", project_root);
173+
let test_dir = format!("{}/tests/find/other", project_root);
183174
let args = [&test_dir, "-group", "name"];
184175

185176
run_test_find(&args, "", "", 0)
@@ -188,11 +179,13 @@ fn find_group_test() {
188179
#[test]
189180
fn find_newer_test() {
190181
let project_root = env!("CARGO_MANIFEST_DIR");
191-
let test_dir = format!("{}/tests/find", project_root);
192-
let test_file = format!("{}/empty_file.txt", test_dir);
193-
let args = [&test_dir, "-newer", &test_file];
182+
let test_dir = format!("{}/tests/find/newer", project_root);
183+
let path_to_test_file = format!("{}/qwe.txt", test_dir);
184+
let mut file = File::create(&path_to_test_file).unwrap();
185+
writeln!(file, "File content").unwrap();
186+
let args = [&test_dir, "-newer", &path_to_test_file];
194187

195-
let expected_output = format!("{}\n{}/file with space.txt\n{}/mod.rs\n{}/rust_file.rs\n", test_dir, test_dir, test_dir, test_dir);
188+
run_test_find(&args, "", "", 0);
196189

197-
run_test_find(&args, &expected_output, "", 0)
190+
remove_file(&path_to_test_file).unwrap();
198191
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)