Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,29 +863,7 @@ mod test {

#[test]
fn test_fix() {
use std::fs;
let file = "fixtures/linter/fix.js";
let args = &["--fix", file];
let content_original = fs::read_to_string(file).unwrap();
#[expect(clippy::disallowed_methods)]
let content = content_original.replace("\r\n", "\n");
assert_eq!(&content, "debugger\n");

// Apply fix to the file.
Tester::new().test(args);
#[expect(clippy::disallowed_methods)]
let new_content = fs::read_to_string(file).unwrap().replace("\r\n", "\n");
assert_eq!(new_content, "\n");

// File should not be modified if no fix is applied.
let modified_before: std::time::SystemTime =
fs::metadata(file).unwrap().modified().unwrap();
Tester::new().test(args);
let modified_after = fs::metadata(file).unwrap().modified().unwrap();
assert_eq!(modified_before, modified_after);

// Write the file back.
fs::write(file, content_original).unwrap();
Tester::test_fix("fixtures/linter/fix.js", "debugger\n", "\n");
}

#[test]
Expand Down
24 changes: 24 additions & 0 deletions apps/oxlint/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ impl Tester {
let _ = LintRunner::new(options, None).with_cwd(self.cwd.clone()).run(&mut output);
}

pub fn test_fix(file: &str, before: &str, after: &str) {
use std::fs;
#[expect(clippy::disallowed_methods)]
let content_original = fs::read_to_string(file).unwrap().replace("\r\n", "\n");
assert_eq!(content_original, before);

Tester::new().test(&["--fix", file]);

#[expect(clippy::disallowed_methods)]
let new_content = fs::read_to_string(file).unwrap().replace("\r\n", "\n");
assert_eq!(new_content, after);

Tester::new().test(&["--fix", file]);

// File should not be modified if no fix is applied.
let modified_before: std::time::SystemTime =
fs::metadata(file).unwrap().modified().unwrap();
let modified_after = fs::metadata(file).unwrap().modified().unwrap();
assert_eq!(modified_before, modified_after);

// Write the file back.
fs::write(file, before).unwrap();
}

pub fn test_and_snapshot(&self, args: &[&str]) {
self.test_and_snapshot_multiple(&[args]);
}
Expand Down
Loading