summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output')
-rw-r--r--src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt34
-rw-r--r--src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs21
4 files changed, 67 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/Cargo.lock b/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/Cargo.lock
new file mode 100644
index 000000000..a6d35e395
--- /dev/null
+++ b/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "silly-function"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/Cargo.toml b/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/Cargo.toml
new file mode 100644
index 000000000..f751864de
--- /dev/null
+++ b/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "silly-function"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt b/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt
new file mode 100644
index 000000000..8caaeda06
--- /dev/null
+++ b/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/output.txt
@@ -0,0 +1,34 @@
+$ cargo test -- --show-output
+ Compiling silly-function v0.1.0 (file:///projects/silly-function)
+ Finished test [unoptimized + debuginfo] target(s) in 0.60s
+ Running unittests src/lib.rs (target/debug/deps/silly_function-160869f38cff9166)
+
+running 2 tests
+test tests::this_test_will_fail ... FAILED
+test tests::this_test_will_pass ... ok
+
+successes:
+
+---- tests::this_test_will_pass stdout ----
+I got the value 4
+
+
+successes:
+ tests::this_test_will_pass
+
+failures:
+
+---- tests::this_test_will_fail stdout ----
+I got the value 8
+thread 'main' panicked at 'assertion failed: `(left == right)`
+ left: `5`,
+ right: `10`', src/lib.rs:19:9
+note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
+
+
+failures:
+ tests::this_test_will_fail
+
+test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
+
+error: test failed, to rerun pass '--lib'
diff --git a/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs b/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs
new file mode 100644
index 000000000..43c4c92f9
--- /dev/null
+++ b/src/doc/book/listings/ch11-writing-automated-tests/output-only-01-show-output/src/lib.rs
@@ -0,0 +1,21 @@
+pub fn prints_and_returns_10(a: i32) -> i32 {
+ println!("I got the value {}", a);
+ 10
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn this_test_will_pass() {
+ let value = prints_and_returns_10(4);
+ assert_eq!(10, value);
+ }
+
+ #[test]
+ fn this_test_will_fail() {
+ let value = prints_and_returns_10(8);
+ assert_eq!(5, value);
+ }
+}