Skip to content

Commit

Permalink
Fix running tests with RUST_BACKTRACE=1 (#1761)
Browse files Browse the repository at this point in the history
The previous version of test output used the `:?` formatter for
`anyhow::Error` which would include the native backtrace when
`RUST_BACKTRACE=1` is set. This commit updates formatters to use `:#`
which is a bit less readable but doesn't include the backtrace when this
env var is set. Additionally a test is added to CI to ensure this
doesn't regress in the future.

This is adapted from #1578.

Closes #1578
  • Loading branch information
alexcrichton authored Sep 9, 2024
1 parent d4a6dc2 commit c4a77ae
Show file tree
Hide file tree
Showing 58 changed files with 192 additions and 376 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ jobs:
# want this to break.
- os: ubuntu-latest
rust: nightly-2024-02-12
# test that if `RUST_BACKTRACE=1` is set in the environment that all
# tests with blessed error messages still pass.
- os: ubuntu-latest
rust: default
env:
RUST_BACKTRACE: 1
env: ${{ matrix.env || fromJSON('{}') }}
steps:
- uses: actions/checkout@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion crates/wit-component/tests/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ fn run_test(path: &Path) -> Result<()> {
if !test_case.starts_with("error-") {
return Err(err);
}
assert_output(&format!("{err:?}"), &error_path)?;
assert_output(&format!("{err:#}"), &error_path)?;
return Ok(());
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: type mismatch for function `a`: expected `[I32, I32] -> [I32]` but found `[] -> []`
failed to decode world from module: module was not valid: type mismatch for function `a`: expected `[I32, I32] -> [I32]` but found `[] -> []`
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: no top-level imported function `foo` specified
failed to decode world from module: module was not valid: no top-level imported function `foo` specified
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: failed to validate exported interface `foo`
2: type mismatch for function `a`: expected `[I32, I32] -> [I32]` but found `[] -> []`
failed to decode world from module: module was not valid: failed to validate exported interface `foo`: type mismatch for function `a`: expected `[I32, I32] -> [I32]` but found `[] -> []`
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: no top-level imported function `[resource-rep]a` specified
failed to decode world from module: module was not valid: no top-level imported function `[resource-rep]a` specified
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: type mismatch for function `[resource-drop]a`: expected `[I32] -> []` but found `[I32] -> [I32]`
failed to decode world from module: module was not valid: type mismatch for function `[resource-drop]a`: expected `[I32] -> []` but found `[I32] -> [I32]`
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: failed to validate import interface `foo`
2: type mismatch for function `bar`: expected `[I32, I32] -> []` but found `[] -> []`
failed to decode world from module: module was not valid: failed to validate import interface `foo`: type mismatch for function `bar`: expected `[I32, I32] -> []` but found `[] -> []`
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: module is only allowed to import functions
failed to decode world from module: module was not valid: module is only allowed to import functions
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: module does not export required function `a`
failed to decode world from module: module was not valid: module does not export required function `a`
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: failed to validate exported interface `foo`
2: module does not export required function `foo#a`
failed to decode world from module: module was not valid: failed to validate exported interface `foo`: module does not export required function `foo#a`
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: module requires an import interface named `foo`
failed to decode world from module: module was not valid: module requires an import interface named `foo`
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to decode world from module

Caused by:
0: module was not valid
1: module requires an import interface named `foo`
failed to decode world from module: module was not valid: module requires an import interface named `foo`
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
failed to register indirect shims for main module

Caused by:
missing component metadata for import of `new::log`
failed to register indirect shims for main module: missing component metadata for import of `new::log`
2 changes: 1 addition & 1 deletion crates/wit-component/tests/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn merging() -> Result<()> {
}
Err(e) => {
assert!(test_case.starts_with("bad-"), "failed to merge with {e:?}");
assert_output(&path.join("error.txt"), &format!("{e:?}"))?;
assert_output(&path.join("error.txt"), &format!("{e:#}"))?;
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions crates/wit-component/tests/merge/bad-interface1/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to merge package `foo:foo` into existing copy

Caused by:
0: failed to merge interface `a`
1: expected type `a` to be present
failed to merge package `foo:foo` into existing copy: failed to merge interface `a`: expected type `a` to be present
6 changes: 1 addition & 5 deletions crates/wit-component/tests/merge/bad-interface2/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to merge package `foo:foo` into existing copy

Caused by:
0: failed to merge interface `a`
1: expected function `a` to be present
failed to merge package `foo:foo` into existing copy: failed to merge interface `a`: expected function `a` to be present
6 changes: 1 addition & 5 deletions crates/wit-component/tests/merge/bad-world1/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to merge package `foo:foo` into existing copy

Caused by:
0: failed to merge world `foo`
1: import `b` not found in target world
failed to merge package `foo:foo` into existing copy: failed to merge world `foo`: import `b` not found in target world
6 changes: 1 addition & 5 deletions crates/wit-component/tests/merge/bad-world2/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to merge package `foo:foo` into existing copy

Caused by:
0: failed to merge world `foo`
1: world contains different number of imports than expected
failed to merge package `foo:foo` into existing copy: failed to merge world `foo`: world contains different number of imports than expected
6 changes: 1 addition & 5 deletions crates/wit-component/tests/merge/bad-world3/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to merge package `foo:foo` into existing copy

Caused by:
0: failed to merge world `foo`
1: world contains different number of exports than expected
failed to merge package `foo:foo` into existing copy: failed to merge world `foo`: world contains different number of exports than expected
6 changes: 1 addition & 5 deletions crates/wit-component/tests/merge/bad-world4/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to merge package `foo:foo` into existing copy

Caused by:
0: failed to merge world `foo`
1: export `b` not found in target world
failed to merge package `foo:foo` into existing copy: failed to merge world `foo`: export `b` not found in target world
6 changes: 1 addition & 5 deletions crates/wit-component/tests/merge/bad-world5/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
failed to merge package `foo:foo` into existing copy

Caused by:
0: failed to merge world `foo`
1: import `a` not found in target world
failed to merge package `foo:foo` into existing copy: failed to merge world `foo`: import `a` not found in target world
2 changes: 1 addition & 1 deletion crates/wit-component/tests/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn targets() -> Result<()> {
}
Err(e) => {
assert!(test_case.starts_with("error-"), "{e:?}");
assert_output(&path.join("error.txt"), &format!("{e:?}"))?;
assert_output(&path.join("error.txt"), &format!("{e:#}"))?;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
failed to validate encoded bytes

Caused by:
type mismatch for import `foobar`
missing export named `test:foo/bar` (at offset 0x1d5)
failed to validate encoded bytes: type mismatch for import `foobar`
missing export named `test:foo/bar` (at offset 0x1d5)
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
failed to validate encoded bytes

Caused by:
type mismatch for import `foobar`
missing import named `test:foo/foo` (at offset 0x175)
failed to validate encoded bytes: type mismatch for import `foobar`
missing import named `test:foo/foo` (at offset 0x175)
2 changes: 1 addition & 1 deletion crates/wit-parser/tests/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Runner {
"some generic platform-agnostic error message",
);
}
format!("{:?}", e)
format!("{:#}", e)
}
}
} else {
Expand Down
13 changes: 5 additions & 8 deletions crates/wit-parser/tests/ui/parse-fail/bad-gate3.wit.result
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
this type is not gated by a feature but its interface is gated by a feature

Caused by:
found a reference to a interface which is excluded due to its feature not being activated
--> tests/ui/parse-fail/bad-gate3.wit:5:8
|
5 | type a = u32;
| ^
this type is not gated by a feature but its interface is gated by a feature: found a reference to a interface which is excluded due to its feature not being activated
--> tests/ui/parse-fail/bad-gate3.wit:5:8
|
5 | type a = u32;
| ^
13 changes: 5 additions & 8 deletions crates/wit-parser/tests/ui/parse-fail/bad-gate4.wit.result
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
failed to update function `[constructor]a`

Caused by:
found a reference to a type which is excluded due to its feature not being activated
--> tests/ui/parse-fail/bad-gate4.wit:6:5
|
6 | constructor();
| ^----------
failed to update function `[constructor]a`: found a reference to a type which is excluded due to its feature not being activated
--> tests/ui/parse-fail/bad-gate4.wit:6:5
|
6 | constructor();
| ^----------
13 changes: 5 additions & 8 deletions crates/wit-parser/tests/ui/parse-fail/bad-gate5.wit.result
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
failed to update function `[static]a.x`

Caused by:
found a reference to a type which is excluded due to its feature not being activated
--> tests/ui/parse-fail/bad-gate5.wit:9:5
|
9 | x: static func();
| ^
failed to update function `[static]a.x`: found a reference to a type which is excluded due to its feature not being activated
--> tests/ui/parse-fail/bad-gate5.wit:9:5
|
9 | x: static func();
| ^
14 changes: 5 additions & 9 deletions crates/wit-parser/tests/ui/parse-fail/bad-pkg1.wit.result
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg1]

Caused by:
0: failed to parse package: tests/ui/parse-fail/bad-pkg1
1: interface or world `nonexistent` not found in package
--> tests/ui/parse-fail/bad-pkg1/root.wit:4:7
|
4 | use nonexistent.{};
| ^----------
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg1]: failed to parse package: tests/ui/parse-fail/bad-pkg1: interface or world `nonexistent` not found in package
--> tests/ui/parse-fail/bad-pkg1/root.wit:4:7
|
4 | use nonexistent.{};
| ^----------
13 changes: 5 additions & 8 deletions crates/wit-parser/tests/ui/parse-fail/bad-pkg2.wit.result
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg2]

Caused by:
interface not found in package
--> tests/ui/parse-fail/bad-pkg2/root.wit:4:15
|
4 | use foo:bar/nonexistent.{};
| ^----------
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg2]: interface not found in package
--> tests/ui/parse-fail/bad-pkg2/root.wit:4:15
|
4 | use foo:bar/nonexistent.{};
| ^----------
13 changes: 5 additions & 8 deletions crates/wit-parser/tests/ui/parse-fail/bad-pkg3.wit.result
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg3]

Caused by:
interface not found in package
--> tests/ui/parse-fail/bad-pkg3/root.wit:4:15
|
4 | use foo:bar/baz.{};
| ^--
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg3]: interface not found in package
--> tests/ui/parse-fail/bad-pkg3/root.wit:4:15
|
4 | use foo:bar/baz.{};
| ^--
13 changes: 5 additions & 8 deletions crates/wit-parser/tests/ui/parse-fail/bad-pkg4.wit.result
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg4]

Caused by:
type `a-name` not defined in interface
--> tests/ui/parse-fail/bad-pkg4/root.wit:3:20
|
3 | use foo:bar/baz.{a-name};
| ^-----
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg4]: type `a-name` not defined in interface
--> tests/ui/parse-fail/bad-pkg4/root.wit:3:20
|
3 | use foo:bar/baz.{a-name};
| ^-----
13 changes: 5 additions & 8 deletions crates/wit-parser/tests/ui/parse-fail/bad-pkg5.wit.result
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg5]

Caused by:
type `nonexistent` not defined in interface
--> tests/ui/parse-fail/bad-pkg5/root.wit:3:20
|
3 | use foo:bar/baz.{nonexistent};
| ^----------
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg5]: type `nonexistent` not defined in interface
--> tests/ui/parse-fail/bad-pkg5/root.wit:3:20
|
3 | use foo:bar/baz.{nonexistent};
| ^----------
13 changes: 5 additions & 8 deletions crates/wit-parser/tests/ui/parse-fail/bad-pkg6.wit.result
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg6]

Caused by:
package not found
--> tests/ui/parse-fail/bad-pkg6/root.wit:3:7
|
3 | use foo:bar/baz.{};
| ^------
failed to resolve directory while parsing WIT for path [tests/ui/parse-fail/bad-pkg6]: package not found
--> tests/ui/parse-fail/bad-pkg6/root.wit:3:7
|
3 | use foo:bar/baz.{};
| ^------
Loading

0 comments on commit c4a77ae

Please sign in to comment.