@@ -65,14 +65,61 @@ pub struct Config {
65
65
pub test_root_dir : PathBuf ,
66
66
}
67
67
68
+ /// Helper type to simplify assertions of a command's output.
69
+ ///
70
+ /// Typically, an [`Assert`] instance is created by calling the
71
+ /// [`Config::expect()`] method (or its variations) which will run the given
72
+ /// command in the test environment and wrap its output in the instance.
73
+ /// Then, that output can be compared against the expected one.
74
+ ///
75
+ /// # Snapshot-Based Testing
76
+ ///
77
+ /// Currently, rustup utilizes [`snapbox`] (a snapshot-based testing library)
78
+ /// for most comparisons, where the corresponding [`Assert`] method would
79
+ /// accept an `expected` argument conforming [`IntoData`], which is also
80
+ /// called a "snapshot".
81
+ ///
82
+ /// Most of our tests use [inline][`snapbox::data::Inline`] snapshots created
83
+ /// with [`snapbox::str`], but it is also possible to use snapshots from
84
+ /// another file with [`snapbox::file`].
85
+ ///
86
+ /// # Creating or Updating a Snapshot
87
+ ///
88
+ /// There is no need to write out a snapshot by hand. Instead, create an empty
89
+ /// snapshot (e.g. `snapbox::str![[""]]`), and run the test in question with the
90
+ /// environment variable `SNAPSHOTS=overwrite` set. Normally, the snapshot will
91
+ /// then be populated automatically with the right value (modulo redaction,
92
+ /// which will be discussed in a later section).
93
+ ///
94
+ /// The same environment variable is also used to update a snapshot with no extra
95
+ /// steps required.
96
+ ///
97
+ /// # Redacting Snapshots
98
+ ///
99
+ /// To defend against leaking of environment-specific information that might
100
+ /// break the tests on a different machine, a set of redaction rules (also known
101
+ /// as "filters") is used to sanitize the output before sending to comparison.
102
+ ///
103
+ /// Rustup extends the list of `snapbox`'s default filters (see
104
+ /// [`assert_data_eq`]'s documentation for more info) with a list of
105
+ /// rustup-specific values, including:
106
+ /// - `[CURRENT_VERSION]`: The current rustup version.
107
+ /// - `[HOST_TRIPLE]`: The return value of [`this_host_triple()`].
108
+ /// - `[CROSS_ARCH_I]`: The value of [`CROSS_ARCH1`].
109
+ /// - `[CROSS_ARCH_II]`: The value of [`CROSS_ARCH2`].
110
+ /// - `[MULTI_ARCH_I]`: The value of [`MULTI_ARCH1`].
111
+ ///
112
+ /// When updating snapshots, the filters are automatically applied.
113
+ /// To redact some remaining part of the snapshot, you can use the
114
+ /// [`Assert::extend_redactions`] method to introduce new filters.
68
115
#[ derive( Clone ) ]
69
116
pub struct Assert {
70
117
output : SanitizedOutput ,
71
118
redactions : Redactions ,
72
119
}
73
120
74
121
impl Assert {
75
- /// Creates a new [`Assert`] object with the given command [`SanitizedOutput`].
122
+ /// Creates a new [`Assert`] object with the given [`SanitizedOutput`].
76
123
pub fn new ( output : SanitizedOutput ) -> Self {
77
124
let mut redactions = Redactions :: new ( ) ;
78
125
redactions
0 commit comments