diff --git a/src/input/walk.rs b/src/input/walk.rs index 1889f01..07f61d1 100644 --- a/src/input/walk.rs +++ b/src/input/walk.rs @@ -27,6 +27,7 @@ impl WalkDocuments { entries: WalkDir::new(root) .follow_links(false) .max_depth(limits.max_walk_depth) + .sort_by_file_name() .into_iter(), limits: limits.clone(), } diff --git a/tests/cli.rs b/tests/cli.rs index b07cc26..81e86e8 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -224,6 +224,25 @@ fn multiple_files_and_findings_keep_requested_and_span_order() { ); } +#[test] +fn directory_output_is_sorted_by_path() { + let directory = tempdir().unwrap(); + let later = directory.path().join("z-later.txt"); + let earlier = directory.path().join("a-earlier.txt"); + fs::write(&later, "later").unwrap(); + fs::write(&earlier, "earlier").unwrap(); + + let output = detector() + .args(["--output", "json"]) + .arg(directory.path()) + .output() + .unwrap(); + let records = json_records(&output); + + assert_eq!(records[0]["source"], earlier.display().to_string()); + assert_eq!(records[1]["source"], later.display().to_string()); +} + #[test] fn missing_path_does_not_hide_a_later_document() { let directory = tempdir().unwrap();