⭐️ A friendly language for building type-safe, scalable systems!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix tests by using 'files'

authored by

PgBiel and committed by
Louis Pilfold
04765337 42c1cba1

+13 -20
+9 -12
compiler-core/src/io/memory.rs
··· 64 64 .collect() 65 65 } 66 66 67 - /// All paths (files and directories) currently in the filesystem, 68 - /// excluding the filesystem root ("/"). 69 - pub fn subpaths(&self) -> Vec<Utf8PathBuf> { 67 + /// All files currently in the filesystem (directories are not included). 68 + pub fn files(&self) -> Vec<Utf8PathBuf> { 70 69 self.files 71 70 .borrow() 72 - .keys() 73 - .filter(|p| p.as_path() != Utf8Path::new("/")) 71 + .iter() 72 + .filter(|(_, f)| !f.is_directory()) 73 + .map(|(path, _)| path) 74 74 .cloned() 75 75 .collect() 76 76 } ··· 468 468 } 469 469 470 470 #[test] 471 - fn test_subpaths_exclude_root() -> Result<(), Error> { 471 + fn test_files() -> Result<(), Error> { 472 472 let imfs = InMemoryFileSystem::new(); 473 473 imfs.write(&Utf8PathBuf::from("/a/b/c.txt"), "a")?; 474 474 imfs.write(&Utf8PathBuf::from("/d/e.txt"), "a")?; 475 475 476 - let mut subpaths = imfs.subpaths(); 476 + let mut files = imfs.files(); 477 477 478 478 // Sort for test determinism due to hash map usage. 479 - subpaths.sort_unstable(); 479 + files.sort_unstable(); 480 480 481 481 assert_eq!( 482 482 vec![ 483 - Utf8PathBuf::from("/a"), 484 - Utf8PathBuf::from("/a/b"), 485 483 Utf8PathBuf::from("/a/b/c.txt"), 486 - Utf8PathBuf::from("/d"), 487 484 Utf8PathBuf::from("/d/e.txt"), 488 485 ], 489 - subpaths 486 + files 490 487 ); 491 488 492 489 Ok(())
+2 -4
test-package-compiler/src/lib.rs
··· 40 40 let warnings = VectorWarningEmitterIO::default(); 41 41 let warning_emitter = WarningEmitter::new(Rc::new(warnings.clone())); 42 42 let filesystem = test_helpers_rs::to_in_memory_filesystem(&root); 43 - let initial_files = filesystem.subpaths(); 43 + let initial_files = filesystem.files(); 44 44 let root = Utf8PathBuf::from(""); 45 45 let out = Utf8PathBuf::from("/out/lib/the_package"); 46 46 let lib = Utf8PathBuf::from("/out/lib"); ··· 69 69 match result { 70 70 Outcome::Ok(_) => { 71 71 for path in initial_files { 72 - if filesystem.is_directory(&path) { 73 - filesystem.delete_directory(&path).unwrap(); 74 - } else { 72 + if filesystem.is_file(&path) { 75 73 filesystem.delete_file(&path).unwrap(); 76 74 } 77 75 }
+2 -4
test-project-compiler/src/lib.rs
··· 15 15 pub fn prepare(path: &str, mode: Mode) -> String { 16 16 let root = Utf8PathBuf::from(path).canonicalize_utf8().unwrap(); 17 17 let filesystem = test_helpers_rs::to_in_memory_filesystem(&root); 18 - let initial_files = filesystem.subpaths(); 18 + let initial_files = filesystem.files(); 19 19 20 20 let toml = std::fs::read_to_string(root.join("gleam.toml")).unwrap(); 21 21 let config: PackageConfig = toml::from_str(&toml).unwrap(); ··· 45 45 compiler.compile().unwrap(); 46 46 47 47 for path in initial_files { 48 - if filesystem.is_directory(&path) { 49 - filesystem.delete_directory(&path).unwrap(); 50 - } else { 48 + if filesystem.is_file(&path) { 51 49 filesystem.delete_file(&path).unwrap(); 52 50 } 53 51 }