1
1
// Copyright (c) The datatest-stable Contributors
2
2
// SPDX-License-Identifier: MIT OR Apache-2.0
3
3
4
+ static EXPECTED_LINES : & [ & str ] = & [
5
+ "datatest-stable::example test_artifact::a.txt" ,
6
+ "datatest-stable::example test_artifact::b.txt" ,
7
+ "datatest-stable::example test_artifact_utf8::a.txt" ,
8
+ "datatest-stable::example test_artifact_utf8::c.skip.txt" ,
9
+ "datatest-stable::example test_artifact_utf8::b.txt" ,
10
+ ] ;
11
+
4
12
#[ test]
5
13
fn run_example ( ) {
6
- let output = std:: process:: Command :: new ( "cargo" )
14
+ let output = std:: process:: Command :: new ( cargo_bin ( ) )
7
15
. args ( [ "nextest" , "run" , "--test=example" , "--color=never" ] )
8
16
. env ( "__DATATEST_FULL_SCAN_FORBIDDEN" , "1" )
9
17
. output ( )
10
- . expect ( "Failed to run `cargo nextest`" ) ;
18
+ . expect ( "`cargo nextest` was successful " ) ;
11
19
12
20
// It's a pain to make assertions on byte slices (even a subslice check isn't easy)
13
21
// and it's also difficult to print nice error messages. So we just assume all
@@ -16,27 +24,86 @@ fn run_example() {
16
24
17
25
assert ! (
18
26
output. status. success( ) ,
19
- "Command failed (exit status: {}, stderr: {stderr})" ,
27
+ "nextest exited with 0 (exit status: {}, stderr: {stderr})" ,
20
28
output. status
21
29
) ;
22
30
23
- let lines: & [ & str ] = & [
31
+ for line in EXPECTED_LINES
32
+ . iter ( )
33
+ . copied ( )
34
+ . chain ( std:: iter:: once ( "5 tests run: 5 passed, 0 skipped" ) )
35
+ {
36
+ assert ! (
37
+ stderr. contains( line) ,
38
+ "Expected to find substring\n {line}\n in stderr\n {stderr}" ,
39
+ ) ;
40
+ }
41
+ }
42
+
43
+ #[ cfg( unix) ]
44
+ mod unix {
45
+ use super :: * ;
46
+ use camino_tempfile:: Utf8TempDir ;
47
+
48
+ static EXPECTED_UNIX_LINES : & [ & str ] = & [
24
49
"datatest-stable::example test_artifact::::colon::dir/::.txt" ,
25
50
"datatest-stable::example test_artifact::::colon::dir/a.txt" ,
26
- "datatest-stable::example test_artifact::a.txt" ,
27
51
"datatest-stable::example test_artifact_utf8::::colon::dir/::.txt" ,
28
- "datatest-stable::example test_artifact::b.txt" ,
29
52
"datatest-stable::example test_artifact_utf8::::colon::dir/a.txt" ,
30
- "datatest-stable::example test_artifact_utf8::a.txt" ,
31
- "datatest-stable::example test_artifact_utf8::c.skip.txt" ,
32
- "datatest-stable::example test_artifact_utf8::b.txt" ,
33
- "9 tests run: 9 passed, 0 skipped" ,
34
53
] ;
35
54
36
- for line in lines {
55
+ #[ test]
56
+ fn run_example_with_colons ( ) {
57
+ let temp_dir = Utf8TempDir :: with_prefix ( "datatest-stable" ) . expect ( "created temp dir" ) ;
58
+ std:: fs:: create_dir_all ( temp_dir. path ( ) . join ( "tests" ) ) . expect ( "created dir" ) ;
59
+ let dest = temp_dir. path ( ) . join ( "tests/files" ) ;
60
+
61
+ // Make a copy of tests/files inside the temp dir.
62
+ fs_extra:: dir:: copy (
63
+ "tests/files" ,
64
+ temp_dir. path ( ) . join ( "tests" ) ,
65
+ & fs_extra:: dir:: CopyOptions :: new ( ) ,
66
+ )
67
+ . expect ( "copied files" ) ;
68
+
69
+ // Add some files with colons in their names. (They can't be checked into the repo because
70
+ // it needs to be cloned on Windows.)
71
+ let colon_dir = dest. join ( "::colon::dir" ) ;
72
+ std:: fs:: create_dir_all ( & colon_dir) . expect ( "created dir with colons" ) ;
73
+ std:: fs:: write ( colon_dir. join ( "::.txt" ) , b"floop" ) . expect ( "wrote file with colons" ) ;
74
+ std:: fs:: write ( colon_dir. join ( "a.txt" ) , b"flarp" ) . expect ( "wrote file with colons" ) ;
75
+
76
+ // Now run the tests.
77
+ let output = std:: process:: Command :: new ( cargo_bin ( ) )
78
+ . args ( [ "nextest" , "run" , "--test=example" , "--color=never" ] )
79
+ . env ( "__DATATEST_FULL_SCAN_FORBIDDEN" , "1" )
80
+ . env ( "__DATATEST_CWD" , temp_dir. path ( ) )
81
+ . output ( )
82
+ . expect ( "`cargo nextest` was successful" ) ;
83
+
84
+ let stderr =
85
+ std:: str:: from_utf8 ( & output. stderr ) . expect ( "cargo nextest stderr should be utf-8" ) ;
86
+
37
87
assert ! (
38
- stderr. contains( line) ,
39
- "Expected to find substring\n {line}\n in stderr\n {stderr}" ,
88
+ output. status. success( ) ,
89
+ "nextest exited with 0 (exit status: {}, stderr: {stderr})" ,
90
+ output. status
40
91
) ;
92
+
93
+ for line in EXPECTED_LINES
94
+ . iter ( )
95
+ . chain ( EXPECTED_UNIX_LINES . iter ( ) )
96
+ . copied ( )
97
+ . chain ( std:: iter:: once ( "9 tests run: 9 passed, 0 skipped" ) )
98
+ {
99
+ assert ! (
100
+ stderr. contains( line) ,
101
+ "Expected to find substring\n {line}\n in stderr\n {stderr}" ,
102
+ ) ;
103
+ }
41
104
}
42
105
}
106
+
107
+ fn cargo_bin ( ) -> String {
108
+ std:: env:: var ( "CARGO" ) . unwrap_or_else ( |_| "cargo" . to_string ( ) )
109
+ }
0 commit comments