Skip to content

Commit 97be155

Browse files
committed
docs(@test): explain snapshot test
1 parent e518158 commit 97be155

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

test/__snapshot__/test.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello

test/test.mbt

+21-4
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,40 @@ pub fn is_not[T : Show](a : T, b : T, loc~ : SourceLoc = _) -> Unit! {
109109
}
110110
}
111111
112-
///|
112+
///| Expected used in test block, don't catch this error.
113+
///
114+
/// Produces an error message similar to @builtin.fail.
113115
pub fn fail[T](msg : String, loc~ : SourceLoc = _) -> T! {
114116
@builtin.fail!(msg, loc~)
115117
}
116118
117-
///|
119+
///| Write data to snapshot buffer, use `snapshot` to output.
120+
///
121+
/// See also `@test.T::writeln`
118122
pub fn write(self : T, obj : &Show) -> Unit {
119123
self.buffer.write_string(obj.to_string())
120124
}
121125
122-
///|
126+
///| Write data to snapshot buffer and newline, use `snapshot` to output.
127+
///
128+
/// See also `@test.T::write`
123129
pub fn writeln(self : T, obj : &Show) -> Unit {
124130
self.write(obj)
125131
self.buffer.write_char('\n')
126132
}
127133
128-
///|
134+
///| Use snapshot in test block end, only can be used once.
135+
///
136+
/// ```
137+
/// test {
138+
/// let t = new("test.txt")
139+
/// t.writeln("hello")
140+
/// t.snapshot!(filename="test.txt") // actual test block end
141+
/// t.writeln("world") // unreachable code
142+
/// // Cann't found `world` in `test.txt`
143+
/// }
144+
/// ```
145+
///
129146
pub fn snapshot(
130147
self : T,
131148
filename~ : String,

0 commit comments

Comments
 (0)