Skip to content

Commit 7b63219

Browse files
authored
normalize new lines in tests (\r\n) (#62)
Normalize the new lines for the snapshots, so when you run ```bash cargo insta test ``` All passes as green ✅ This should also allow us to enable Windows in the CI tests, but we don't need to do it
1 parent 485e250 commit 7b63219

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

src/test.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ use std::path::Path;
88

99
fn evaluate_example(fname: &Path) -> String {
1010
let mut compiler = Compiler::new();
11-
let contents = std::fs::read(fname).expect("We only run tests found by glob");
11+
let contents = std::fs::read_to_string(fname).expect("We only run tests found by glob");
12+
// normalize newlines
13+
let replaced = contents.replace("\r\n", "\n");
14+
let contents = replaced.as_bytes();
1215

1316
let span_offset = compiler.span_offset();
14-
compiler.add_file(&fname.to_string_lossy(), &contents);
17+
compiler.add_file(&fname.to_string_lossy(), contents);
1518

16-
let (tokens, err) = lex(&contents, span_offset);
19+
let (tokens, err) = lex(contents, span_offset);
1720
if let Err(e) = err {
18-
tokens.eprint(&contents);
21+
tokens.eprint(contents);
1922
eprintln!("Lexing error. Error: {:?}", e);
2023
std::process::exit(1);
2124
}
@@ -53,14 +56,13 @@ fn evaluate_example(fname: &Path) -> String {
5356
}
5457

5558
fn evaluate_lexer(fname: &Path) -> String {
56-
let contents = std::fs::read(fname);
59+
let contents = std::fs::read_to_string(fname).expect("We only run tests found by glob");
60+
// normalize newlines
61+
let replaced = contents.replace("\r\n", "\n");
62+
let contents = replaced.as_bytes();
5763

58-
let Ok(contents) = contents else {
59-
panic!("Lexer: can't find file {}", fname.to_string_lossy());
60-
};
61-
62-
let (tokens, err) = lex(&contents, 0);
63-
let mut res = tokens.display(&contents);
64+
let (tokens, err) = lex(contents, 0);
65+
let mut res = tokens.display(contents);
6466

6567
if let Err(e) = err {
6668
res.push_str(&format!("Lexing error. Error: {:?}", e));

0 commit comments

Comments
 (0)