Skip to content

Commit 2cd53c5

Browse files
authored
chore(ci): fix windows test (#14546)
CI on main seems to be failing since snapshot based tests were introduced. This PR includes two fixes: - handling of backslashed paths when generating test code - normalization of crlf which, were counted as two line breaks by snapshot comparison Looks like windows test job doen't run on pull requests or feature branches, it only runs on main. You can review its status on my fork's main workflow run: https://github.com/lilnasy/oxc/actions/runs/18458898920.
1 parent 496dd62 commit 2cd53c5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

crates/oxc_formatter/build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
env,
44
fs::{self, File},
55
io::Write,
6-
path::{Path, PathBuf},
6+
path::{MAIN_SEPARATOR, Path, PathBuf},
77
};
88

99
use oxc_span::SourceType;
@@ -108,6 +108,7 @@ fn is_test_file(path: &Path) -> bool {
108108
}
109109
}
110110

111+
#[expect(clippy::disallowed_methods)]
111112
fn generate_test_function(
112113
f: &mut File,
113114
relative_path: &Path,
@@ -123,7 +124,7 @@ fn generate_test_function(
123124
f,
124125
"{} let path = std::path::Path::new(\"tests/fixtures/{}\");",
125126
indent,
126-
relative_path.display()
127+
relative_path.display().to_string().replace(MAIN_SEPARATOR, "/")
127128
)?;
128129
writeln!(f, "{indent} test_file(path);")?;
129130
writeln!(f, "{indent}}}")?;

crates/oxc_formatter/tests/fixtures/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn generate_snapshot(path: &Path, source_text: &str) -> String {
187187
}
188188

189189
let options = parse_format_options(&option_json);
190-
let formatted = format_source(source_text, source_type, options);
190+
let formatted = normalize_newlines(format_source(source_text, source_type, options));
191191
snapshot.push_str(&formatted);
192192
snapshot.push('\n');
193193
}
@@ -199,7 +199,7 @@ fn generate_snapshot(path: &Path, source_text: &str) -> String {
199199

200200
/// Helper function to run a test for a single file
201201
fn test_file(path: &Path) {
202-
let source_text = fs::read_to_string(path).unwrap();
202+
let source_text = normalize_newlines(fs::read_to_string(path).unwrap());
203203
let snapshot = generate_snapshot(path, &source_text);
204204
let snapshot_path = current_dir().unwrap().join(path.parent().unwrap());
205205
let snapshot_name = path.file_name().unwrap().to_str().unwrap();
@@ -215,5 +215,14 @@ fn test_file(path: &Path) {
215215
});
216216
}
217217

218+
#[expect(clippy::disallowed_methods)]
219+
fn normalize_newlines(text: String) -> String {
220+
if !text.contains('\r') {
221+
return text;
222+
}
223+
224+
text.replace("\r\n", "\n")
225+
}
226+
218227
// Include auto-generated test functions from build.rs
219228
include!(concat!(env!("OUT_DIR"), "/generated_tests.rs"));

0 commit comments

Comments
 (0)