Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Sep 1, 2024
1 parent ab15cdf commit 9717614
Show file tree
Hide file tree
Showing 28 changed files with 87 additions and 83 deletions.
25 changes: 16 additions & 9 deletions src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,13 @@ impl From<syn::Error> for Diagnostic {
use proc_macro2::{Delimiter, TokenTree};

fn gut_error(ts: &mut impl Iterator<Item = TokenTree>) -> Option<(SpanRange, String)> {
let first = match ts.next() {
// compile_error
None => return None,
Some(tt) => tt.span(),
};
ts.next().unwrap(); // !
let start_span = ts.next()?.span();
ts.next().expect(":1");
ts.next().expect("core");
ts.next().expect(":2");
ts.next().expect(":3");
ts.next().expect("compile_error");
ts.next().expect("!");

let lit = match ts.next().unwrap() {
TokenTree::Group(group) => {
Expand All @@ -318,10 +319,10 @@ impl From<syn::Error> for Diagnostic {

match group.stream().into_iter().next().unwrap() {
TokenTree::Literal(lit) => lit,
_ => unreachable!(),
_ => unreachable!(""),
}
}
_ => unreachable!(),
_ => unreachable!(""),
};

let last = lit.span();
Expand All @@ -331,7 +332,13 @@ impl From<syn::Error> for Diagnostic {
msg.pop();
msg.remove(0);

Some((SpanRange { first, last }, msg))
Some((
SpanRange {
first: start_span,
last,
},
msg,
))
}

let mut ts = err.to_compile_error().into_iter();
Expand Down
2 changes: 0 additions & 2 deletions test-crate/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate proc_macro;

use proc_macro2::{Span, TokenStream};
use proc_macro_error::{
abort, abort_call_site, diagnostic, emit_call_site_error, emit_call_site_warning, emit_error,
Expand Down
2 changes: 0 additions & 2 deletions tests/macro-errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate trybuild;

#[cfg_attr(skip_ui_tests, ignore)]
#[test]
fn ui() {
Expand Down
2 changes: 0 additions & 2 deletions tests/ok.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate test_crate;

use test_crate::*;

ok!(it_works);
Expand Down
1 change: 0 additions & 1 deletion tests/ui/abort.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate test_crate;
use test_crate::*;

abort_from!(one, two);
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/abort.stderr
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
error: abort!(span, from) test
--> tests/ui/abort.rs:4:13
--> tests/ui/abort.rs:3:13
|
4 | abort_from!(one, two);
3 | abort_from!(one, two);
| ^^^

error: abort!(span, single_expr) test
--> tests/ui/abort.rs:5:18
--> tests/ui/abort.rs:4:18
|
5 | abort_to_string!(one, two);
4 | abort_to_string!(one, two);
| ^^^

error: abort!(span, expr1, expr2) test
--> tests/ui/abort.rs:6:15
--> tests/ui/abort.rs:5:15
|
6 | abort_format!(one, two);
5 | abort_format!(one, two);
| ^^^

error: Diagnostic::abort() test
--> tests/ui/abort.rs:7:15
--> tests/ui/abort.rs:6:15
|
7 | direct_abort!(one, two);
6 | direct_abort!(one, two);
| ^^^

error: This is an error
Expand All @@ -34,15 +34,15 @@ error: This is an error
= note: spanned format note
= note: Some note

--> tests/ui/abort.rs:8:14
--> tests/ui/abort.rs:7:14
|
8 | abort_notes!(one, two);
7 | abort_notes!(one, two);
| ^^^

error: abort_call_site! test
--> tests/ui/abort.rs:9:1
--> tests/ui/abort.rs:8:1
|
9 | abort_call_site_test!(one, two);
8 | abort_call_site_test!(one, two);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `abort_call_site_test` (in Nightly builds, run with -Z macro-backtrace for more info)
3 changes: 1 addition & 2 deletions tests/ui/append_dummy.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
extern crate test_crate;
use test_crate::*;

enum NeedDefault {
A,
B
B,
}

append_dummy!(need_default);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/append_dummy.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: append_dummy test
--> tests/ui/append_dummy.rs:9:15
--> tests/ui/append_dummy.rs:8:15
|
9 | append_dummy!(need_default);
8 | append_dummy!(need_default);
| ^^^^^^^^^^^^
1 change: 0 additions & 1 deletion tests/ui/children_messages.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate test_crate;
use test_crate::*;

children_messages!(one, two, three, four);
Expand Down
26 changes: 21 additions & 5 deletions tests/ui/children_messages.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
error: proc macro panicked
--> tests/ui/children_messages.rs:4:1
error: main macro message
--> tests/ui/children_messages.rs:3:20
|
4 | children_messages!(one, two, three, four);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | children_messages!(one, two, three, four);
| ^^^

error: child message
--> tests/ui/children_messages.rs:3:25
|
= help: message: internal error: entered unreachable code
3 | children_messages!(one, two, three, four);
| ^^^

error: main syn::Error
--> tests/ui/children_messages.rs:3:30
|
3 | children_messages!(one, two, three, four);
| ^^^^^

error: child syn::Error
--> tests/ui/children_messages.rs:3:37
|
3 | children_messages!(one, two, three, four);
| ^^^^
3 changes: 1 addition & 2 deletions tests/ui/dummy.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
extern crate test_crate;
use test_crate::*;

enum NeedDefault {
A,
B
B,
}

dummy!(need_default);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/dummy.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: set_dummy test
--> tests/ui/dummy.rs:9:8
--> tests/ui/dummy.rs:8:8
|
9 | dummy!(need_default);
8 | dummy!(need_default);
| ^^^^^^^^^^^^
1 change: 0 additions & 1 deletion tests/ui/emit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate test_crate;
use test_crate::*;

emit!(one, two, three, four, five);
Expand Down
24 changes: 12 additions & 12 deletions tests/ui/emit.stderr
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
error: emit!(span, from) test
--> tests/ui/emit.rs:4:7
--> tests/ui/emit.rs:3:7
|
4 | emit!(one, two, three, four, five);
3 | emit!(one, two, three, four, five);
| ^^^

error: emit!(span, expr1, expr2) test
--> tests/ui/emit.rs:4:12
--> tests/ui/emit.rs:3:12
|
4 | emit!(one, two, three, four, five);
3 | emit!(one, two, three, four, five);
| ^^^

error: emit!(span, single_expr) test
--> tests/ui/emit.rs:4:17
--> tests/ui/emit.rs:3:17
|
4 | emit!(one, two, three, four, five);
3 | emit!(one, two, three, four, five);
| ^^^^^

error: Diagnostic::emit() test
--> tests/ui/emit.rs:4:24
--> tests/ui/emit.rs:3:24
|
4 | emit!(one, two, three, four, five);
3 | emit!(one, two, three, four, five);
| ^^^^

error: emit_call_site_error!(expr) test
--> tests/ui/emit.rs:4:1
--> tests/ui/emit.rs:3:1
|
4 | emit!(one, two, three, four, five);
3 | emit!(one, two, three, four, five);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `emit` (in Nightly builds, run with -Z macro-backtrace for more info)
Expand All @@ -42,7 +42,7 @@ error: This is an error
= note: spanned format note
= note: Some note

--> tests/ui/emit.rs:5:13
--> tests/ui/emit.rs:4:13
|
5 | emit_notes!(one, two);
4 | emit_notes!(one, two);
| ^^^
1 change: 0 additions & 1 deletion tests/ui/explicit_span_range.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate test_crate;
use test_crate::*;

explicit_span_range!(one, two, three, four);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/explicit_span_range.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: explicit SpanRange
--> tests/ui/explicit_span_range.rs:4:22
--> tests/ui/explicit_span_range.rs:3:22
|
4 | explicit_span_range!(one, two, three, four);
3 | explicit_span_range!(one, two, three, four);
| ^^^^^^^^^^^^^^^
1 change: 0 additions & 1 deletion tests/ui/misuse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate proc_macro_error;
use proc_macro_error::abort;

struct Foo;
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/misuse.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0599]: the method `FIRST_ARG_MUST_EITHER_BE_Span_OR_IMPLEMENT_ToTokens_OR_BE_SpanRange` exists for reference `&Foo`, but its trait bounds were not satisfied
--> tests/ui/misuse.rs:8:5
--> tests/ui/misuse.rs:7:5
|
4 | struct Foo;
3 | struct Foo;
| ---------- doesn't satisfy `Foo: quote::to_tokens::ToTokens`
...
8 | abort!(Foo, "BOOM");
7 | abort!(Foo, "BOOM");
| ^^^^^^^^^^^^^^^^^^^ method cannot be called on `&Foo` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
Expand Down
4 changes: 1 addition & 3 deletions tests/ui/multiple_tokens.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
extern crate test_crate;

#[test_crate::multiple_tokens]
type T = ();

fn main() {}
fn main() {}
4 changes: 2 additions & 2 deletions tests/ui/multiple_tokens.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: ...
--> tests/ui/multiple_tokens.rs:4:1
--> tests/ui/multiple_tokens.rs:2:1
|
4 | type T = ();
2 | type T = ();
| ^^^^^^^^^^^^
1 change: 0 additions & 1 deletion tests/ui/option_ext.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate test_crate;
use test_crate::*;

option_ext!(one, two);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/option_ext.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: Option::expect_or_abort() test
--> tests/ui/option_ext.rs:4:1
--> tests/ui/option_ext.rs:3:1
|
4 | option_ext!(one, two);
3 | option_ext!(one, two);
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `option_ext` (in Nightly builds, run with -Z macro-backtrace for more info)
1 change: 0 additions & 1 deletion tests/ui/result_ext.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate test_crate;
use test_crate::*;

result_unwrap_or_abort!(one, two);
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/result_ext.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: Result::unwrap_or_abort() test
--> tests/ui/result_ext.rs:4:25
--> tests/ui/result_ext.rs:3:25
|
4 | result_unwrap_or_abort!(one, two);
3 | result_unwrap_or_abort!(one, two);
| ^^^

error: BOOM: Result::expect_or_abort() test
--> tests/ui/result_ext.rs:5:25
--> tests/ui/result_ext.rs:4:25
|
5 | result_expect_or_abort!(one, two);
4 | result_expect_or_abort!(one, two);
| ^^^
1 change: 0 additions & 1 deletion tests/ui/to_tokens_span.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate test_crate;
use test_crate::*;

to_tokens_span!(std::option::Option);
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/to_tokens_span.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: whole type
--> tests/ui/to_tokens_span.rs:4:17
--> tests/ui/to_tokens_span.rs:3:17
|
4 | to_tokens_span!(std::option::Option);
3 | to_tokens_span!(std::option::Option);
| ^^^^^^^^^^^^^^^^^^^

error: explicit .span()
--> tests/ui/to_tokens_span.rs:4:17
--> tests/ui/to_tokens_span.rs:3:17
|
4 | to_tokens_span!(std::option::Option);
3 | to_tokens_span!(std::option::Option);
| ^^^
1 change: 0 additions & 1 deletion tests/ui/unrelated_panic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
extern crate test_crate;
use test_crate::*;

unrelated_panic!();
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/unrelated_panic.stderr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
error: proc macro panicked
--> tests/ui/unrelated_panic.rs:4:1
--> tests/ui/unrelated_panic.rs:3:1
|
4 | unrelated_panic!();
3 | unrelated_panic!();
| ^^^^^^^^^^^^^^^^^^
|
= help: message: unrelated panic test

0 comments on commit 9717614

Please sign in to comment.