@@ -68,6 +68,46 @@ fn create_working_directory(
6868 Ok ( temp_dir)
6969}
7070
71+ /// Create the working directory and the test files.
72+ fn create_test_directory_with_sized_files (
73+ directories : & [ & ' static str ] ,
74+ files : & [ ( & ' static str , usize ) ] ,
75+ ) -> Result < TempDir , io:: Error > {
76+ let temp_dir = tempfile:: Builder :: new ( ) . prefix ( "fd-tests" ) . tempdir ( ) ?;
77+
78+ {
79+ let root = temp_dir. path ( ) ;
80+
81+ // Pretend that this is a Git repository in order for `.gitignore` files to be respected
82+ fs:: create_dir_all ( root. join ( ".git" ) ) ?;
83+
84+ for directory in directories {
85+ fs:: create_dir_all ( root. join ( directory) ) ?;
86+ }
87+
88+ for ( file, size) in files {
89+ let fp = fs:: File :: create ( root. join ( file) ) ?;
90+
91+ // Create a file with the specified size.
92+ fp. set_len ( * size as u64 ) ?;
93+ }
94+
95+ #[ cfg( unix) ]
96+ unix:: fs:: symlink ( root. join ( "one/two" ) , root. join ( "symlink" ) ) ?;
97+
98+ // Note: creating symlinks on Windows requires the `SeCreateSymbolicLinkPrivilege` which
99+ // is by default only granted for administrators.
100+ #[ cfg( windows) ]
101+ windows:: fs:: symlink_dir ( root. join ( "one/two" ) , root. join ( "symlink" ) ) ?;
102+
103+ fs:: File :: create ( root. join ( ".fdignore" ) ) ?. write_all ( b"fdignored.foo" ) ?;
104+
105+ fs:: File :: create ( root. join ( ".gitignore" ) ) ?. write_all ( b"gitignored.foo" ) ?;
106+ }
107+
108+ Ok ( temp_dir)
109+ }
110+
71111fn create_config_directory_with_global_ignore ( ignore_file_content : & str ) -> io:: Result < TempDir > {
72112 let config_dir = tempfile:: Builder :: new ( ) . prefix ( "fd-config" ) . tempdir ( ) ?;
73113 let fd_dir = config_dir. path ( ) . join ( "fd" ) ;
@@ -159,6 +199,7 @@ fn trim_lines(s: &str) -> String {
159199}
160200
161201impl TestEnv {
202+ /// Create a test environment with a temporary folder, empty files, directories, and symlinks.
162203 pub fn new ( directories : & [ & ' static str ] , files : & [ & ' static str ] ) -> TestEnv {
163204 let temp_dir = create_working_directory ( directories, files) . expect ( "working directory" ) ;
164205 let fd_exe = find_fd_exe ( ) ;
@@ -172,6 +213,23 @@ impl TestEnv {
172213 }
173214 }
174215
216+ pub fn new_with_sized_files (
217+ directories : & [ & ' static str ] ,
218+ files : & [ ( & ' static str , usize ) ] ,
219+ ) -> TestEnv {
220+ let temp_dir =
221+ create_test_directory_with_sized_files ( directories, files) . expect ( "working directory" ) ;
222+ let fd_exe = find_fd_exe ( ) ;
223+
224+ TestEnv {
225+ temp_dir,
226+ fd_exe,
227+ normalize_line : false ,
228+ allow_random_result_order : true ,
229+ config_dir : None ,
230+ }
231+ }
232+
175233 /// Sets whether output lines should be normalized before comparison.
176234 ///
177235 /// Normalization sorts whitespace-separated elements in each line to ensure consistent comparison.
0 commit comments