1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! The one place that decides whether a `not_error` assertion may render an explicit
//! "the call succeeded" presence check (`assertNotNull`, `Assert.NotNull`,
//! `expect(x).toBeDefined()`, and equivalents).
//!
//! ~keep `not_error` is a filler assertion: an uncaught exception/panic already fails the test,
//! so `not_error`'s own presence check exists only to keep a fixture whose sole assertion is
//! `not_error` from being vacuous (`inert_example` exists specifically to catch that shape).
//! Once that reasoning is spelled out, two independent conditions make the presence check unsafe,
//! and either alone is reason enough to suppress it:
//!
//! - `result_is_option`: the call's own return type says a legitimate absent value (`None`) is
//! possible on success (e.g. detecting a language from empty content returning `None`), so
//! presence is not guaranteed regardless of what else the fixture asserts.
//! - a sibling assertion already exists beside `not_error`: it already gives the test real,
//! non-vacuous coverage, so the filler is unneeded — and on an `Option<T>` result it would
//! actively contradict a sibling `is_empty`/`not_empty` check on the same bare value (wasm-
//! bindgen maps `None` -> `undefined`, which fails an unconditional `toBeDefined()`; NAPI's
//! `None` -> `null` only dodged this by accident, since `null !== undefined`).
//!
//! This rule was discovered and independently re-fixed, under a different flag name each time,
//! in swift (`bare_result_is_option`), kotlin (`bare_result_is_option`, twice — once correctly,
//! once via a doc comment that falsely claimed the fix already existed), r
//! (`bare_result_is_option`), typescript (`has_other_assertions`), csharp (`has_other_assertions`),
//! elixir (`has_other_assertions`), and java (`result_is_option && bare_field`) — seven backends
//! independently discovering the same rule (alef #165 and its follow-ups) is the defect this
//! module exists to end: a backend calls [`may_assert_presence`] once and gets the correct
//! answer, instead of re-deriving it.
//!
//! Backends keep control of *how* to render the presence check (or its absence — a comment, a
//! no-op, a different fallback assertion); this module decides only *whether*.
use crateFixture;
/// Whether a `not_error` assertion belonging to `fixture` may render an explicit "the call
/// succeeded" presence check.
///
/// `result_is_option` is the call's already-resolved (backend override applied) fact that the
/// wrapped Rust function returns `Option<T>`. `not_error` itself never carries a field — every
/// backend's own `not_error` handling documents this — so no field argument is needed here: a
/// `not_error` assertion is always a bare check on the whole result.