Skip to content

Commit 43e8962

Browse files
authored
fix(test): do not report "only" notice when a test fails on its own (#35063)
Fixes #28648
1 parent 84a6342 commit 43e8962

6 files changed

Lines changed: 53 additions & 4 deletions

File tree

cli/tools/test/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,17 +1710,20 @@ pub async fn report_tests(
17101710
);
17111711
}
17121712

1713+
// A genuine test failure takes precedence over the `only` notice: if a test
1714+
// failed on its own, reporting that it failed "because the \"only\" option
1715+
// was used" is misleading.
1716+
if failed {
1717+
return (Err(anyhow!("Test failed")), receiver);
1718+
}
1719+
17131720
if used_only {
17141721
return (
17151722
Err(anyhow!("Test failed because the \"only\" option was used",)),
17161723
receiver,
17171724
);
17181725
}
17191726

1720-
if failed {
1721-
return (Err(anyhow!("Test failed")), receiver);
1722-
}
1723-
17241727
(Ok(()), receiver)
17251728
}
17261729

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"tests": {
3+
"only_test_fails_on_its_own": {
4+
"args": "test --no-check main.ts",
5+
"exitCode": 1,
6+
"output": "main.out"
7+
},
8+
"only_test_passes": {
9+
"args": "test --no-check pass.ts",
10+
"exitCode": 1,
11+
"output": "pass.out"
12+
}
13+
}
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
running 1 test from ./main.ts
2+
fails on its own ... FAILED ([WILDCARD])
3+
4+
ERRORS
5+
6+
fails on its own => ./main.ts:3:11
7+
error: Error: boom
8+
throw new Error("boom");
9+
^
10+
at [WILDCARD]main.ts:4:9
11+
12+
FAILURES
13+
14+
fails on its own => ./main.ts:3:11
15+
16+
FAILED | 0 passed | 1 failed ([WILDCARD])
17+
18+
error: Test failed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// When a test marked with `only` fails on its own, the run should report the
2+
// actual failure rather than the misleading "only" notice.
3+
Deno.test.only("fails on its own", () => {
4+
throw new Error("boom");
5+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
running 1 test from ./pass.ts
2+
passes ... ok ([WILDCARD])
3+
4+
ok | 1 passed | 0 failed ([WILDCARD])
5+
6+
error: Test failed because the "only" option was used
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// A `only` test that passes should still report the "only" notice, since the
2+
// run only "failed" because the `only` filter was applied.
3+
Deno.test.only("passes", () => {});

0 commit comments

Comments
 (0)