Skip to content

Commit 580b27c

Browse files
committed
Rewrite .gitattributes CRLF ui tests into run-make tests
1 parent 42245d3 commit 580b27c

File tree

13 files changed

+147
-134
lines changed

13 files changed

+147
-134
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//@ reference: input.byte-order-mark
2+
//@ reference: input.crlf
3+
4+
use run_make_support::{rfs, rustc, tmp_dir};
5+
6+
fn main() {
7+
let aux_content = "\u{FEFF}\
8+
pub fn test() {\r\n\
9+
\r\n\
10+
let s : String = 1; // Error in the middle of line.\r\n\
11+
\r\n\
12+
let s : String = 1\r\n\
13+
; // Error before the newline.\r\n\
14+
\r\n\
15+
let s : String =\r\n\
16+
1; // Error after the newline.\r\n\
17+
\r\n\
18+
let s : String = (\r\n\
19+
); // Error spanning the newline.\r\n\
20+
}\r\n";
21+
22+
rfs::write(tmp_dir().join("json-bom-plus-crlf-multifile-aux.rs"), aux_content).unwrap();
23+
24+
let aux_bytes = rfs::read(tmp_dir().join("json-bom-plus-crlf-multifile-aux.rs")).unwrap();
25+
assert!(aux_bytes.starts_with(b"\xEF\xBB\xBF"), "File must start with UTF-8 BOM");
26+
assert!(aux_bytes.windows(2).any(|w| w == b"\r\n"), "File must contain CRLF line endings");
27+
28+
let main_content = "\u{FEFF}\
29+
#[path = \"json-bom-plus-crlf-multifile-aux.rs\"]\r\n\
30+
mod json_bom_plus_crlf_multifile_aux;\r\n\
31+
\r\n\
32+
fn main() {\r\n\
33+
json_bom_plus_crlf_multifile_aux::test();\r\n\
34+
}\r\n";
35+
36+
rfs::write(tmp_dir().join("json-bom-plus-crlf-multifile.rs"), main_content).unwrap();
37+
38+
let output = rustc()
39+
.input(tmp_dir().join("json-bom-plus-crlf-multifile.rs"))
40+
.json("diagnostic-short")
41+
.error_format("json")
42+
.run_fail()
43+
.stderr_utf8();
44+
45+
diff()
46+
.expected_file("json-bom-plus-crlf-multifile.stderr")
47+
.actual_text("stderr", &output)
48+
.run();
49+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//@ reference: input.byte-order-mark
2+
//@ reference: input.crlf
3+
4+
use run_make_support::{diff, rfs, rustc, tmp_dir};
5+
6+
fn main() {
7+
let main_content = "\u{FEFF}\
8+
fn main() {\r\n\
9+
\r\n\
10+
let s : String = 1; // Error in the middle of line.\r\n\
11+
\r\n\
12+
let s : String = 1\r\n\
13+
; // Error before the newline.\r\n\
14+
\r\n\
15+
let s : String =\r\n\
16+
1; // Error after the newline.\r\n\
17+
\r\n\
18+
let s : String = (\r\n\
19+
); // Error spanning the newline.\r\n\
20+
}\r\n";
21+
22+
let main_path = tmp_dir().join("json-bom-plus-crlf.rs");
23+
rfs::write(&main_path, main_content).unwrap();
24+
25+
let main_bytes = rfs::read(&main_path).unwrap();
26+
assert!(main_bytes.starts_with(b"\xEF\xBB\xBF"), "File must start with UTF-8 BOM");
27+
assert!(main_bytes.windows(2).any(|w| w == b"\r\n"), "File must contain CRLF line endings");
28+
29+
let output = rustc()
30+
.input(&main_path)
31+
.json("diagnostic-short")
32+
.error_format("json")
33+
.run_fail()
34+
.stderr_utf8();
35+
36+
diff().expected_file("json-bom-plus-crlf.stderr").actual_text("stderr", &output).run();
37+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ reference: input.crlf
2+
3+
use run_make_support::{rfs, run, rustc, tmp_dir};
4+
5+
fn main() {
6+
let test_content = "/// Doc comment that ends in CRLF\r\n\
7+
pub fn foo() {}\r\n\
8+
\r\n\
9+
/** Block doc comment that\r\n\
10+
* contains CRLF characters\r\n\
11+
*/\r\n\
12+
pub fn bar() {}\r\n\
13+
\r\n\
14+
fn main() {\r\n\
15+
let s = \"string\r\nliteral\";\r\n\
16+
assert_eq!(s, \"string\\nliteral\");\r\n\
17+
\r\n\
18+
let s = \"literal with \\\r\n\
19+
escaped newline\";\r\n\
20+
assert_eq!(s, \"literal with escaped newline\");\r\n\
21+
\r\n\
22+
let s = r\"string\r\nliteral\";\r\n\
23+
assert_eq!(s, \"string\\nliteral\");\r\n\
24+
let s = br\"byte string\r\nliteral\";\r\n\
25+
assert_eq!(s, \"byte string\\nliteral\".as_bytes());\r\n\
26+
\r\n\
27+
// validate that our source file has CRLF endings\r\n\
28+
let source = include_str!(file!());\r\n\
29+
assert!(source.contains(\"string\\r\\nliteral\"));\r\n\
30+
}\r\n";
31+
32+
let test_path = tmp_dir().join("lexer-crlf-line-endings-string-literal-doc-comment.rs");
33+
rfs::write(&test_path, test_content).unwrap();
34+
35+
let test_bytes = rfs::read(&test_path).unwrap();
36+
assert!(test_bytes.windows(2).any(|w| w == b"\r\n"), "File must contain CRLF line endings");
37+
38+
rustc().input(&test_path).run();
39+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use run_make_support::{diff, rfs, rustc, tmp_dir};
2+
3+
fn main() {
4+
let test_content = "fn main() {\n\
5+
// \\r\\n\n\
6+
let ok = \"This is \\\r\n\
7+
a test\";\n\
8+
// \\r only\n\
9+
let bad = \"This is \\\r\
10+
a test\";\n\
11+
}\n";
12+
13+
let test_path = tmp_dir().join("trailing-carriage-return-in-string.rs");
14+
rfs::write(&test_path, test_content).unwrap();
15+
16+
let output = rustc().input(&test_path).run_fail().stderr_utf8();
17+
18+
diff()
19+
.expected_file("trailing-carriage-return-in-string.stderr")
20+
.actual_text("stderr", &output)
21+
.run();
22+
}

tests/ui/.gitattributes

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
lexer-crlf-line-endings-string-literal-doc-comment.rs -text
2-
json-bom-plus-crlf.rs -text
3-
json-bom-plus-crlf-multifile.rs -text
4-
json-bom-plus-crlf-multifile-aux.rs -text
5-
trailing-carriage-return-in-string.rs -text
61
*.bin -text

tests/ui/json/json-bom-plus-crlf-multifile-aux.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/ui/json/json-bom-plus-crlf-multifile.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/ui/json/json-bom-plus-crlf.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/ui/lexer/lexer-crlf-line-endings-string-literal-doc-comment.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/ui/parser/trailing-carriage-return-in-string.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)