1
+ use std:: fs:: { remove_file, File } ;
2
+ use std:: io:: Write ;
3
+
1
4
use plib:: { run_test, TestPlan } ;
2
5
3
6
fn run_test_find (
@@ -21,18 +24,18 @@ fn run_test_find(
21
24
#[ test]
22
25
fn find_size_test ( ) {
23
26
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) ;
25
28
let args = [ & test_dir, "-size" , "+4" ] ;
26
29
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) ;
28
31
29
32
run_test_find ( & args, & expected_output, "" , 0 )
30
33
}
31
34
32
35
#[ test]
33
36
fn find_name_test ( ) {
34
37
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) ;
36
39
let args = [ & test_dir, "-name" , "empty_file.txt" ] ;
37
40
38
41
let expected_output = format ! ( "{}/empty_file.txt\n " , test_dir) ;
@@ -43,18 +46,18 @@ fn find_name_test() {
43
46
#[ test]
44
47
fn find_type_test ( ) {
45
48
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) ;
47
50
let args = [ & test_dir, "-type" , "f" ] ;
48
51
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) ;
50
53
51
54
run_test_find ( & args, & expected_output, "" , 0 )
52
55
}
53
56
54
57
#[ test]
55
58
fn find_mtime_test ( ) {
56
59
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) ;
58
61
let args = [ & test_dir, "-mtime" , "7" ] ;
59
62
60
63
run_test_find ( & args, "" , "" , 0 )
@@ -63,40 +66,40 @@ fn find_mtime_test() {
63
66
#[ test]
64
67
fn find_combination_test ( ) {
65
68
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) ;
67
70
let args = [ & test_dir, "-size" , "+4" , "-print" , "-size" , "+2" , "-print" ] ;
68
71
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) ;
70
73
71
74
run_test_find ( & args, & expected_output, "" , 0 )
72
75
}
73
76
74
77
#[ test]
75
78
fn find_not_test ( ) {
76
79
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) ;
78
81
let args = [ & test_dir, "!" , "-path" , "*.txt" ] ;
79
82
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) ;
81
84
82
85
run_test_find ( & args, & expected_output, "" , 0 )
83
86
}
84
87
85
88
#[ test]
86
89
fn find_or_test ( ) {
87
90
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) ;
89
92
let args = [ & test_dir, "-path" , "*.rs" , "-o" , "-path" , "*.txt" ] ;
90
93
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) ;
92
95
93
96
run_test_find ( & args, & expected_output, "" , 0 )
94
97
}
95
98
96
99
#[ test]
97
100
fn find_and_test ( ) {
98
101
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) ;
100
103
let args = [ & test_dir, "-path" , "*.txt" , "-a" , "-size" , "+2" ] ;
101
104
102
105
let expected_output = format ! ( "{}/file1.txt\n " , test_dir) ;
@@ -107,7 +110,7 @@ fn find_and_test() {
107
110
#[ test]
108
111
fn find_space_argument_test ( ) {
109
112
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) ;
111
114
let args = [ & test_dir, "-name" , "file with space.txt" ] ;
112
115
113
116
let expected_output = format ! ( "{}/file with space.txt\n " , test_dir) ;
@@ -118,7 +121,7 @@ fn find_space_argument_test() {
118
121
#[ test]
119
122
fn find_no_user_test ( ) {
120
123
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) ;
122
125
let args = [ & test_dir, "-nouser" ] ;
123
126
124
127
run_test_find ( & args, "" , "" , 0 )
@@ -127,7 +130,7 @@ fn find_no_user_test() {
127
130
#[ test]
128
131
fn find_no_group_test ( ) {
129
132
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) ;
131
134
let args = [ & test_dir, "-nogroup" ] ;
132
135
133
136
run_test_find ( & args, "" , "" , 0 )
@@ -136,18 +139,18 @@ fn find_no_group_test() {
136
139
#[ test]
137
140
fn find_x_dev_test ( ) {
138
141
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) ;
140
143
let args = [ & test_dir, "-xdev" ] ;
141
144
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) ;
143
146
144
147
run_test_find ( & args, & expected_output, "" , 0 )
145
148
}
146
149
147
150
#[ test]
148
151
fn find_perm_test ( ) {
149
152
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) ;
151
154
let args = [ & test_dir, "-perm" , "777" ] ;
152
155
153
156
run_test_find ( & args, "" , "" , 0 )
@@ -156,30 +159,18 @@ fn find_perm_test() {
156
159
#[ test]
157
160
fn find_links_test ( ) {
158
161
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) ;
160
163
let args = [ & test_dir, "-links" , "1" ] ;
161
164
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) ;
175
166
176
167
run_test_find ( & args, & expected_output, "" , 0 )
177
168
}
178
169
179
170
#[ test]
180
171
fn find_group_test ( ) {
181
172
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) ;
183
174
let args = [ & test_dir, "-group" , "name" ] ;
184
175
185
176
run_test_find ( & args, "" , "" , 0 )
@@ -188,11 +179,13 @@ fn find_group_test() {
188
179
#[ test]
189
180
fn find_newer_test ( ) {
190
181
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] ;
194
187
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 ) ;
196
189
197
- run_test_find ( & args , & expected_output , "" , 0 )
190
+ remove_file ( & path_to_test_file ) . unwrap ( ) ;
198
191
}
0 commit comments