Skip to content

Commit

Permalink
test: simplify acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-biel committed Sep 16, 2023
1 parent f202f47 commit 410d2c6
Show file tree
Hide file tree
Showing 55 changed files with 87 additions and 282 deletions.
4 changes: 4 additions & 0 deletions tests/acceptance_cases/allow_stays_on_fn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
###
# Ensure that `#[allow(...)]` is propagated to the test function.
###

[package]
name = "allow_stays_on_fn"
version = "0.1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
###
# Ensure that tests can be ran in tandem with `#[tokio::test]` and `#[async_std::test]`.
###

[package]
name = "async_tests"
version = "0.1.0"
Expand All @@ -11,9 +15,9 @@ doctest = false

[dev-dependencies]
test-case = { path = "../../../" }
tokio = { version = "=0.2.25", features = [ "rt-threaded", "macros" ] }
async-std = { version = "=1.6.0", features = ["attributes"] }
async-attributes = "=1.1.1"
once_cell = "=1.13.1"
tokio = { version = "=1.32.0", features = [ "macros", "rt" ] }
async-std = { version = "=1.12.0", features = ["attributes"] }
async-attributes = "=1.1.2"
once_cell = "=1.18.0"

[workspace]
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
###
# Ensure that test cases can be declared outsie of #[cfg(test)] modules.
###

[package]
name = "cases_can_be_declared_on_non_test_items"
version = "0.1.0"
Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance_cases/cases_can_be_ignored/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure that `=> ignore` syntax works.
###

[package]
name = "cases_can_be_ignored"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "cases_can_be_ignored"
path = "src/lib.rs"
Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance_cases/cases_can_panic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure that `panics` syntax anh `#[should_panic]` macro works.
###

[package]
name = "cases_can_panic"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
[lib]
name = "cases_can_panic"
Expand Down
2 changes: 1 addition & 1 deletion tests/acceptance_cases/cases_can_panic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn pattern_matching_result_fails(e: SimpleEnum) -> SimpleEnum {

#[test_case(() => panics "It has to panic")]
#[test_case(() => panics "This should fail")]
fn panicing(_: ()) {
fn panicking(_: ()) {
panic!("It has to panic")
}

Expand Down
4 changes: 4 additions & 0 deletions tests/acceptance_cases/cases_can_return_result/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
###
# Ensure that test cases automatically assert return values.
###

[package]
name = "cases_can_return_result"
version = "0.1.0"
Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance_cases/cases_can_use_regex/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure that `with-regex` feature allows to use `is matching_regex` syntax.
###

[package]
name = "cases_can_use_regex"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
test-case = { path = "../../../", features = ["with-regex"]}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
###
# Ensure basic test case functionality.
###

[package]
name = "cases_support_basic_features"
version = "0.1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure `it` syntax works.
###

[package]
name = "cases_support_complex_assertions"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "cases_support_complex_assertions"
path = "src/lib.rs"
Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance_cases/cases_support_generics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure that cases can be ran against test functions with generic parameters.
###

[package]
name = "cases_support_generics"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "cases_support_generics"
path = "src/lib.rs"
Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance_cases/cases_support_keyword_using/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure that `using` syntax works.
###

[package]
name = "cases_support_keyword_using"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "cases_support_keyword_using"
path = "src/lib.rs"
Expand Down
6 changes: 4 additions & 2 deletions tests/acceptance_cases/cases_support_keyword_with/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure that `with` syntax works.
###

[package]
name = "cases_support_keyword_with"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "cases_support_keyword_with"
path = "src/lib.rs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure that all aliases of test case macro are usable.
###

[package]
name = "cases_support_multiple_calling_methods"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "cases_support_multiple_calling_methods"
path = "src/lib.rs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure that `matches` syntax works.
###

[package]
name = "cases_support_pattern_matching"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
name = "cases_support_pattern_matching"
path = "src/lib.rs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
###
# Ensure that when missing a `feature` flag in Cargo.toml file, the error message is human readable.
###

[package]
name = "features_produce_human_readable_errors"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
test-case = { path = "../../../", default-features = false }

Expand Down
7 changes: 5 additions & 2 deletions tests/acceptance_cases/matrices_compilation_errors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
###
# Ensure that matrix syntax produces human readable errors.
###

[package]
name = "matrices_compilation_errors"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[lib]
name = "matrices_compilation_errors"
path = "src/lib.rs"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
###
# Ensure that `matrix` syntax works.
###

[package]
name = "matrices_support_basic_features"
version = "0.1.0"
Expand Down
17 changes: 4 additions & 13 deletions tests/acceptance_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,10 @@ fn sanitize_lines(s: String) -> String {
let mut s = s
.lines()
.filter(|line| {
!line.contains("note")
&& !line.contains("error: build failed") // For mac builds
&& !line.contains("error: process didn't exit successfully") // For windows builds
&& !line.contains("waiting")
&& !line.contains("Finished")
&& !line.contains("Compiling")
&& !line.contains("termination value with a non-zero status code")
&& !line.contains("Running unittests")
&& !line.contains("Running target")
&& !line.contains("Downloaded")
&& !line.contains("Downloading")
&& !line.contains("Updating")
&& !line.is_empty()
line.starts_with("test")
|| line.contains("panicked at")
|| line.starts_with("error:")
|| line.starts_with("error[")
})
.map(|line| line.replace('\\', "/"))
.map(|line| line.replace(".exe", ""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
source: tests/acceptance_tests.rs
expression: output
---
running 1 test
test allow_stays_on_fn::_42_expects ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
source: tests/acceptance_tests.rs
assertion_line: 65
expression: output
---
running 2 tests
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test works_seamlessly_with_async_std::_100i32_expects_100usize ... ok
test works_seamlessly_with_tokio::_100i32_expects_100usize ... ok
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@
source: tests/acceptance_tests.rs
expression: output
---
internal_tested_function1::_3_expects_6
left: `6`,
right: `0`
---- internal_tested_function1::_3_expects_6 stdout ----
assertion failed: `(left == right)`
error: test failed, to rerun pass `--lib`
failures:
failures:
running 6 tests
test internal_tested_function1::_2_expects_4 ... ok
test internal_tested_function1::_3_expects_6 ... FAILED
test internal_tested_function2::_1_expects_0 ... ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
source: tests/acceptance_tests.rs
expression: output
---
running 9 tests
test descriptions::_expects_inconclusive_ ... ignored, reason but no comment
test descriptions::ignore_keyword ... ignored, reason and comment
test descriptions::test_is_not_run ... ignored, reason and comment
Expand Down
19 changes: 6 additions & 13 deletions tests/snapshots/rust-nightly/acceptance__cases_can_panic.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@
source: tests/acceptance_tests.rs
expression: output
---
panic message: `"It has to panic"`,
panicing::_expects_panicking_some_this_should_fail_
expected substring: `"This should fail"`
---- panicing::_expects_panicking_some_this_should_fail_ stdout ----
It has to panic
error: test failed, to rerun pass `--lib`
failures:
failures:
running 5 tests
test panicing::_expects_panicking_some_it_has_to_panic_ - should panic ... ok
test panicing::_expects_panicking_some_this_should_fail_ - should panic ... FAILED
test panicking::_expects_panicking_some_it_has_to_panic_ - should panic ... ok
test panicking::_expects_panicking_some_this_should_fail_ - should panic ... FAILED
test panics_without_value::_expects_panicking_none - should panic ... ok
test pattern_matching_result_fails::simpleenum_var1_expects_matching_simpleenum_var2_ - should panic ... ok
test result: FAILED. 4 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result_which_panics::_2_2_expects_2_3 - should panic ... ok
thread 'panicing::_expects_panicking_some_this_should_fail_' panicked at src/lib.rs:20:5:
test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result_which_panics::_2_2_expects_2_3 - should panic ... FAILED
thread 'panicking::_expects_panicking_some_this_should_fail_' panicked at src/lib.rs:20:5:
thread 'result_which_panics::_2_2_expects_2_3' panicked at src/lib.rs:28:1:
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
---
source: tests/acceptance_tests.rs
assertion_line: 98
expression: output
---
is_even::_13_expects
is_odd_boxed::_12_expects
---- is_even::_13_expects stdout ----
---- is_odd_boxed::_12_expects stdout ----
Error: "is even"
Error: "is odd"
error: test failed, to rerun pass `--lib`
failures:
failures:
running 7 tests
test ignore_supported::_12_expects_inconclusivematching_ok_ ... ignored
test is_even::_12_expects ... ok
test is_even::_13_expects ... FAILED
Expand Down
18 changes: 0 additions & 18 deletions tests/snapshots/rust-nightly/acceptance__cases_can_use_regex.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,8 @@
source: tests/acceptance_tests.rs
expression: output
---
/
^
regex_test::_abcabc201_expects_complex_regex_r_d_4_
regex_test::_kumkwat_expects_complex_regex_r_
regex_test::_kumkwat_expects_complex_regex_r_abc_
)
---- regex_test::_abcabc201_expects_complex_regex_r_d_4_ stdout ----
---- regex_test::_kumkwat_expects_complex_regex_r_ stdout ----
---- regex_test::_kumkwat_expects_complex_regex_r_abc_ stdout ----
Regex::new: Syntax(
assertion failed: {/n let re = ::test_case::Regex::new(r#/"//d{4}/"#).expect(/"Regex::new/");/n re.is_match(_result)/n}
assertion failed: {/n let re = ::test_case::Regex::new(r#/"abc/"#).expect(/"Regex::new/");/n re.is_match(_result)/n}
error: incomplete escape sequence, reached end of pattern prematurely
error: test failed, to rerun pass `--lib`
failures:
failures:
regex parse error:
running 6 tests
test regex_test::_abcabc201_expects_complex_regex_r_d_ ... ok
test regex_test::_abcabc201_expects_complex_regex_r_d_4_ ... FAILED
test regex_test::_abcabc_expects_complex_regex_r_abc_ ... ok
Expand All @@ -30,5 +14,3 @@ test result: FAILED. 3 passed; 3 failed; 0 ignored; 0 measured; 0 filtered out;
thread 'regex_test::_abcabc201_expects_complex_regex_r_d_4_' panicked at src/lib.rs:5:1:
thread 'regex_test::_kumkwat_expects_complex_regex_r_' panicked at src/lib.rs:5:1:
thread 'regex_test::_kumkwat_expects_complex_regex_r_abc_' panicked at src/lib.rs:5:1:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@
source: tests/acceptance_tests.rs
expression: output
---
Running `target/debug/cases_can_be_declared_on_non_test_items`
Can't
thread 'main' panicked at src/lib.rs:33:5:
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
source: tests/acceptance_tests.rs
assertion_line: 95
expression: output
---
running 33 tests
test result: ok. 33 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test test_cases::abs_tests::returns_0_for_0 ... ok
test test_cases::abs_tests::returns_given_number_for_positive_input ... ok
Expand Down
Loading

0 comments on commit 410d2c6

Please sign in to comment.