From f21993da52cbf2c96ae55a1ab1d532a1cf72fefb Mon Sep 17 00:00:00 2001 From: wtlin1228 Date: Sat, 5 Oct 2024 18:27:53 +0800 Subject: [PATCH] test: system call for filesystem might be different for different OS --- crates/dt_scheduler/tests/scheduler.rs | 70 +++++++++++++++++--------- 1 file changed, 45 insertions(+), 25 deletions(-) diff --git a/crates/dt_scheduler/tests/scheduler.rs b/crates/dt_scheduler/tests/scheduler.rs index bdb057b..710e22a 100644 --- a/crates/dt_scheduler/tests/scheduler.rs +++ b/crates/dt_scheduler/tests/scheduler.rs @@ -1,40 +1,60 @@ -use std::path::PathBuf; - use dt_scheduler::ParserCandidateScheduler; +use std::{collections::HashSet, path::PathBuf}; #[test] fn topological_order() { let root = "tests/fixture"; let mut scheduler = ParserCandidateScheduler::new(root); - let topological_order = [ - "blocker.js", - "reexport/default-alias.js", - "reexport/wildcard-alias.js", - "reexport/named-alias.js", - "reexport/named.js", - "reexport/default.js", - "non-blocker.js", - "import/side-effect.js", - "import/default-alias.js", - "import/named-alias.js", - "import/named.js", - "import/default.js", - "reexport/wildcard.js", - "import/namespace.js", - "index.js", - ]; + let mut not_parsed = HashSet::from( + [ + "blocker.js", + "reexport/default-alias.js", + "reexport/wildcard-alias.js", + "reexport/named-alias.js", + "reexport/named.js", + "reexport/default.js", + "non-blocker.js", + "import/side-effect.js", + "import/default-alias.js", + "import/named-alias.js", + "import/named.js", + "import/default.js", + "reexport/wildcard.js", + "import/namespace.js", + "index.js", + ] + .map(|s| PathBuf::from(root).join(s).canonicalize().unwrap()), + ); + + let wildcard_reexport = PathBuf::from(root) + .join("reexport/wildcard.js") + .canonicalize() + .unwrap(); + let namespace_import = PathBuf::from(root) + .join("import/namespace.js") + .canonicalize() + .unwrap(); + let blocker = PathBuf::from(root) + .join("blocker.js") + .canonicalize() + .unwrap(); assert_eq!( scheduler.get_total_remaining_candidate_count(), - topological_order.len() + not_parsed.len() ); - for expected in topological_order { + for _ in 0..not_parsed.len() { let candidate = scheduler.get_one_candidate().unwrap(); - assert_eq!( - candidate, - PathBuf::from(root).join(expected).canonicalize().unwrap() - ); + assert!(not_parsed.contains(&candidate)); + + // `reexport/wildcard.js` and `import/namespace.js` are blocked by `blocker.js` + if candidate == blocker { + assert!(not_parsed.contains(&wildcard_reexport)); + assert!(not_parsed.contains(&namespace_import)); + } + + not_parsed.remove(&candidate); scheduler.mark_candidate_as_parsed(candidate); } assert_eq!(scheduler.get_total_remaining_candidate_count(), 0);