Skip to content

Commit

Permalink
Add tests for source code with invalid utf-8 bytes
Browse files Browse the repository at this point in the history
```
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.
  • Loading branch information
estebank committed Jan 22, 2025
1 parent 57dd42d commit b7895ad
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/ui/macros/not-utf8-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@ error-pattern: did not contain valid UTF-8
//@ reference: input.encoding.utf8
//@ reference: input.encoding.invalid

fn foo() {
include!("not-utf8-bin-file.rs");
}
15 changes: 15 additions & 0 deletions tests/ui/macros/not-utf8-2.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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)

error: aborting due to 1 previous error

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

error: aborting due to 1 previous error

0 comments on commit b7895ad

Please sign in to comment.