Skip to content

Commit b7895ad

Browse files
committed
Add tests for source code with invalid utf-8 bytes
``` error: couldn't read `$DIR/not-utf8-bin-file.rs`: stream did not contain valid UTF-8 --> $DIR/not-utf8-2.rs:6:5 | LL | include!("not-utf8-bin-file.rs"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: byte `193` is not valid utf-8 --> $DIR/not-utf8-bin-file.rs:2:14 | LL | let _ = "�|�␂!5�cc␕␂��"; | ^ = note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info) ``` CC rust-lang#76869, rust-lang#135557.
1 parent 57dd42d commit b7895ad

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

tests/ui/macros/not-utf8-2.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//@ error-pattern: did not contain valid UTF-8
2+
//@ reference: input.encoding.utf8
3+
//@ reference: input.encoding.invalid
4+
5+
fn foo() {
6+
include!("not-utf8-bin-file.rs");
7+
}

tests/ui/macros/not-utf8-2.stderr

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: couldn't read `$DIR/not-utf8-bin-file.rs`: stream did not contain valid UTF-8
2+
--> $DIR/not-utf8-2.rs:6:5
3+
|
4+
LL | include!("not-utf8-bin-file.rs");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: byte `193` is not valid utf-8
8+
--> $DIR/not-utf8-bin-file.rs:2:14
9+
|
10+
LL | let _ = "�|�␂!5�cc␕␂��";
11+
| ^
12+
= note: this error originates in the macro `include` (in Nightly builds, run with -Z macro-backtrace for more info)
13+
14+
error: aborting due to 1 previous error
15+

tests/ui/macros/not-utf8-bin-file.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let _ = "Á|Õ!5¢ccŒÓ";
3+
//~^ ERROR stream did not contain valid UTF-8
4+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: couldn't read `$DIR/not-utf8-bin-file.rs`: stream did not contain valid UTF-8
2+
--> $DIR/not-utf8-bin-file.rs:2:14
3+
|
4+
LL | let _ = "�|�␂!5�cc␕␂��";
5+
| ^ byte `193` is not valid utf-8
6+
7+
error: aborting due to 1 previous error
8+

0 commit comments

Comments
 (0)