@@ -85,49 +85,87 @@ pub fn check_nixpkgs<W: io::Write>(
8585#[ cfg( test) ]
8686mod tests {
8787 use crate :: check_nixpkgs;
88+ use crate :: structure;
8889 use anyhow:: Context ;
8990 use std:: env;
9091 use std:: fs;
91- use std:: path:: PathBuf ;
92+ use std:: path:: Path ;
93+ use tempfile:: { tempdir, tempdir_in} ;
9294
9395 #[ test]
94- fn test_cases ( ) -> anyhow:: Result < ( ) > {
95- let extra_nix_path = PathBuf :: from ( "tests/mock-nixpkgs.nix" ) ;
96-
97- // We don't want coloring to mess up the tests
98- env:: set_var ( "NO_COLOR" , "1" ) ;
99-
100- for entry in PathBuf :: from ( "tests" ) . read_dir ( ) ? {
96+ fn tests_dir ( ) -> anyhow:: Result < ( ) > {
97+ for entry in Path :: new ( "tests" ) . read_dir ( ) ? {
10198 let entry = entry?;
10299 let path = entry. path ( ) ;
103100 let name = entry. file_name ( ) . to_string_lossy ( ) . into_owned ( ) ;
104101
105- if !entry . path ( ) . is_dir ( ) {
102+ if !path. is_dir ( ) {
106103 continue ;
107104 }
108105
109- // This test explicitly makes sure we don't add files that would cause problems on
110- // Darwin, so we cannot test it on Darwin itself
111- #[ cfg( not( target_os = "linux" ) ) ]
112- if name == "case-sensitive-duplicate-package" {
113- continue ;
114- }
115-
116- let mut writer = vec ! [ ] ;
117- check_nixpkgs ( & path, vec ! [ & extra_nix_path] , & mut writer)
118- . context ( format ! ( "Failed test case {name}" ) ) ?;
119-
120- let actual_errors = String :: from_utf8_lossy ( & writer) ;
121106 let expected_errors =
122107 fs:: read_to_string ( path. join ( "expected" ) ) . unwrap_or ( String :: new ( ) ) ;
123108
124- if actual_errors != expected_errors {
125- panic ! (
126- "Failed test case {name}, expected these errors:\n \n {}\n \n but got these:\n \n {}" ,
127- expected_errors, actual_errors
128- ) ;
129- }
109+ test_nixpkgs ( & name, & path, & expected_errors) ?;
110+ }
111+ Ok ( ( ) )
112+ }
113+
114+ // We cannot check case-conflicting files into Nixpkgs (the channel would fail to
115+ // build), so we generate the case-conflicting file instead.
116+ #[ test]
117+ fn test_case_sensitive ( ) -> anyhow:: Result < ( ) > {
118+ let temp_nixpkgs = tempdir ( ) ?;
119+ let path = temp_nixpkgs. path ( ) ;
120+
121+ if is_case_insensitive_fs ( & path) ? {
122+ eprintln ! ( "We're on a case-insensitive filesystem, skipping case-sensitivity test" ) ;
123+ return Ok ( ( ) ) ;
124+ }
125+
126+ let base = path. join ( structure:: BASE_SUBPATH ) ;
127+
128+ fs:: create_dir_all ( base. join ( "fo/foo" ) ) ?;
129+ fs:: write ( base. join ( "fo/foo/package.nix" ) , "{ someDrv }: someDrv" ) ?;
130+
131+ fs:: create_dir_all ( base. join ( "fo/foO" ) ) ?;
132+ fs:: write ( base. join ( "fo/foO/package.nix" ) , "{ someDrv }: someDrv" ) ?;
133+
134+ test_nixpkgs (
135+ "case_sensitive" ,
136+ & path,
137+ "pkgs/by-name/fo: Duplicate case-sensitive package directories \" foO\" and \" foo\" .\n " ,
138+ ) ?;
139+
140+ Ok ( ( ) )
141+ }
142+
143+ fn test_nixpkgs ( name : & str , path : & Path , expected_errors : & str ) -> anyhow:: Result < ( ) > {
144+ let extra_nix_path = Path :: new ( "tests/mock-nixpkgs.nix" ) ;
145+
146+ // We don't want coloring to mess up the tests
147+ env:: set_var ( "NO_COLOR" , "1" ) ;
148+
149+ let mut writer = vec ! [ ] ;
150+ check_nixpkgs ( & path, vec ! [ & extra_nix_path] , & mut writer)
151+ . context ( format ! ( "Failed test case {name}" ) ) ?;
152+
153+ let actual_errors = String :: from_utf8_lossy ( & writer) ;
154+
155+ if actual_errors != expected_errors {
156+ panic ! (
157+ "Failed test case {name}, expected these errors:\n \n {}\n \n but got these:\n \n {}" ,
158+ expected_errors, actual_errors
159+ ) ;
130160 }
131161 Ok ( ( ) )
132162 }
163+
164+ /// Check whether a path is in a case-insensitive filesystem
165+ fn is_case_insensitive_fs ( path : & Path ) -> anyhow:: Result < bool > {
166+ let dir = tempdir_in ( path) ?;
167+ let base = dir. path ( ) ;
168+ fs:: write ( base. join ( "aaa" ) , "" ) ?;
169+ Ok ( base. join ( "AAA" ) . exists ( ) )
170+ }
133171}
0 commit comments