plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


44752a1 — Peter John 2026-11-10T23:12:53+05:30
plum test: the shared durations file drops files that are gone
Files changed (1) hide show
  1. compiler/cli/src/main.rs +24 -3
compiler/cli/src/main.rs CHANGED
@@ -785,16 +785,27 @@ fn loadTestDurations() -> std::collections::HashMap<String, f64> {
785
785
  }
786
786
 
787
787
  /// Written to a temporary file and renamed, so sweeps running side by side never read half a file.
788
+ /// The file is shared by every checkout and branch (a sweep only reads its own files' times);
789
+ /// a file that is gone, such as a test's scratch folder, is dropped from it.
788
790
  fn saveTestDurations(durations: &std::collections::HashMap<String, f64>) {
789
- let mut lines: Vec<String> = durations.iter().map(|(p, s)| format!("{s:.3}\t{p}")).collect();
790
- lines.sort();
791
791
  let path = testDurationsPath();
792
792
  let tmp = path.with_extension(format!("{}.tmp", process::id()));
793
- if fs::write(&tmp, lines.join("\n") + "\n").is_ok() && fs::rename(&tmp, &path).is_err() {
793
+ if fs::write(&tmp, durationsText(durations)).is_ok() && fs::rename(&tmp, &path).is_err() {
794
794
  let _ = fs::remove_file(&tmp);
795
795
  }
796
796
  }
797
797
 
798
+ /// The durations file's text: `seconds<TAB>path` lines, sorted, for the files that still exist.
799
+ fn durationsText(durations: &std::collections::HashMap<String, f64>) -> String {
800
+ let mut lines: Vec<String> = durations
801
+ .iter()
802
+ .filter(|(p, _)| std::path::Path::new(p.as_str()).exists())
803
+ .map(|(p, s)| format!("{s:.3}\t{p}"))
804
+ .collect();
805
+ lines.sort();
806
+ lines.join("\n") + "\n"
807
+ }
808
+
798
809
  /// The order a sweep starts its files in: slowest last time first; a file not timed yet
799
810
  /// counts as slow (it may be), larger before smaller.
800
811
  fn sweepOrder(files: &[std::path::PathBuf], durations: &std::collections::HashMap<String, f64>) -> Vec<usize> {
@@ -1087,4 +1098,14 @@ mod runtime_path_tests {
1087
1098
  d.insert(super::durationKey(&files[3]), 3.0);
1088
1099
  assert_eq!(super::sweepOrder(&files, &d), vec![2, 1, 3, 0]);
1089
1100
  }
1101
+
1102
+ /// The durations file is shared by every checkout: a file that is gone (a test's
1103
+ /// scratch folder, a deleted test) is dropped, so it does not grow without end.
1104
+ #[test]
1105
+ fn durationsOfFilesThatAreGoneAreDropped() {
1106
+ let here = env!("CARGO_MANIFEST_DIR").to_string() + "/Cargo.toml";
1107
+ let gone = std::env::temp_dir().join("plum_no_such_dir_ever/x.plum").display().to_string();
1108
+ let d = std::collections::HashMap::from([(here.clone(), 1.5), (gone, 2.0)]);
1109
+ assert_eq!(super::durationsText(&d), format!("1.500\t{here}\n"));
1110
+ }
1090
1111
  }