Skip to content

Commit dd6228e

Browse files
committed
test(test): Verify escaping behavior
1 parent 0b84a35 commit dd6228e

File tree

1 file changed

+102
-5
lines changed

1 file changed

+102
-5
lines changed

tests/testsuite/test.rs

Lines changed: 102 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,13 +725,98 @@ fn dont_run_examples() {
725725
}
726726

727727
#[cargo_test]
728-
fn pass_through_command_line() {
728+
fn pass_through_escaped() {
729729
let p = project()
730730
.file(
731731
"src/lib.rs",
732732
"
733-
#[test] fn foo() {}
734-
#[test] fn bar() {}
733+
/// ```rust
734+
/// assert!(foo::foo());
735+
/// ```
736+
pub fn foo() -> bool {
737+
true
738+
}
739+
740+
/// ```rust
741+
/// assert!(!foo::bar());
742+
/// ```
743+
pub fn bar() -> bool {
744+
false
745+
}
746+
747+
#[test] fn test_foo() {
748+
assert!(foo());
749+
}
750+
#[test] fn test_bar() {
751+
assert!(!bar());
752+
}
753+
",
754+
)
755+
.build();
756+
757+
p.cargo("test -- bar")
758+
.with_stderr(
759+
"\
760+
[COMPILING] foo v0.0.1 ([CWD])
761+
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
762+
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
763+
",
764+
)
765+
.with_stdout_contains("running 1 test")
766+
.with_stdout_contains("test test_bar ... ok")
767+
.run();
768+
769+
p.cargo("test -- foo")
770+
.with_stderr(
771+
"\
772+
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
773+
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
774+
",
775+
)
776+
.with_stdout_contains("running 1 test")
777+
.with_stdout_contains("test test_foo ... ok")
778+
.run();
779+
780+
p.cargo("test -- foo bar")
781+
.with_stderr(
782+
"\
783+
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
784+
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
785+
",
786+
)
787+
.with_stdout_contains("running 2 tests")
788+
.with_stdout_contains("test test_foo ... ok")
789+
.with_stdout_contains("test test_bar ... ok")
790+
.run();
791+
}
792+
793+
// Unlike `pass_through_escaped`, doctests won't run when using `testname` as an optimization
794+
#[cargo_test]
795+
fn pass_through_testname() {
796+
let p = project()
797+
.file(
798+
"src/lib.rs",
799+
"
800+
/// ```rust
801+
/// assert!(foo::foo());
802+
/// ```
803+
pub fn foo() -> bool {
804+
true
805+
}
806+
807+
/// ```rust
808+
/// assert!(!foo::bar());
809+
/// ```
810+
pub fn bar() -> bool {
811+
false
812+
}
813+
814+
#[test] fn test_foo() {
815+
assert!(foo());
816+
}
817+
#[test] fn test_bar() {
818+
assert!(!bar());
819+
}
735820
",
736821
)
737822
.build();
@@ -745,7 +830,7 @@ fn pass_through_command_line() {
745830
",
746831
)
747832
.with_stdout_contains("running 1 test")
748-
.with_stdout_contains("test bar ... ok")
833+
.with_stdout_contains("test test_bar ... ok")
749834
.run();
750835

751836
p.cargo("test foo")
@@ -756,7 +841,19 @@ fn pass_through_command_line() {
756841
",
757842
)
758843
.with_stdout_contains("running 1 test")
759-
.with_stdout_contains("test foo ... ok")
844+
.with_stdout_contains("test test_foo ... ok")
845+
.run();
846+
847+
p.cargo("test foo -- bar")
848+
.with_stderr(
849+
"\
850+
[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
851+
[RUNNING] [..] (target/debug/deps/foo-[..][EXE])
852+
",
853+
)
854+
.with_stdout_contains("running 2 tests")
855+
.with_stdout_contains("test test_foo ... ok")
856+
.with_stdout_contains("test test_bar ... ok")
760857
.run();
761858
}
762859

0 commit comments

Comments
 (0)