2
2
//!
3
3
//! Tests for message caching can be found in `cache_messages`.
4
4
5
- #![ allow( deprecated) ]
6
-
5
+ use cargo_test_support:: compare:: assert_e2e;
7
6
use cargo_test_support:: prelude:: * ;
8
7
use cargo_test_support:: { process, project, Project } ;
9
8
use cargo_util:: ProcessError ;
@@ -48,6 +47,12 @@ pub fn raw_rustc_output(project: &Project, path: &str, extra: &[&str]) -> String
48
47
result
49
48
}
50
49
50
+ fn redact_rustc_message ( msg : & str ) -> String {
51
+ let assert = assert_e2e ( ) . normalize_paths ( true ) ;
52
+ let redactions = assert. redactions ( ) ;
53
+ redactions. redact ( msg)
54
+ }
55
+
51
56
#[ cargo_test]
52
57
fn deduplicate_messages_basic ( ) {
53
58
let p = project ( )
@@ -61,21 +66,27 @@ fn deduplicate_messages_basic() {
61
66
)
62
67
. build ( ) ;
63
68
let rustc_message = raw_rustc_output ( & p, "src/lib.rs" , & [ ] ) ;
69
+ let rustc_message = redact_rustc_message ( & rustc_message) ;
64
70
let expected_output = format ! (
65
71
"{}\
66
- warning: `foo` (lib) generated 1 warning[..]
67
- warning: `foo` (lib test) generated 1 warning (1 duplicate)
68
- [FINISHED] [..]
69
- [EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[.. ][EXE])
72
+ [WARNING] `foo` (lib) generated 1 warning[..]
73
+ [WARNING] `foo` (lib test) generated 1 warning (1 duplicate)
74
+ [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
75
+ [EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH ][EXE])
70
76
" ,
71
77
rustc_message
72
78
) ;
73
79
p. cargo ( "test --no-run -j1" )
74
- . with_stderr ( & format ! ( "[COMPILING] foo [..]\n {}" , expected_output) )
80
+ . with_stderr_data ( & format ! (
81
+ "\
82
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
83
+ {}" ,
84
+ expected_output
85
+ ) )
75
86
. run ( ) ;
76
87
// Run again, to check for caching behavior.
77
88
p. cargo ( "test --no-run -j1" )
78
- . with_stderr ( expected_output)
89
+ . with_stderr_data ( expected_output)
79
90
. run ( ) ;
80
91
}
81
92
@@ -99,27 +110,34 @@ fn deduplicate_messages_mismatched_warnings() {
99
110
)
100
111
. build ( ) ;
101
112
let lib_output = raw_rustc_output ( & p, "src/lib.rs" , & [ ] ) ;
102
- let mut lib_test_output = raw_rustc_output ( & p, "src/lib.rs" , & [ "--test" ] ) ;
113
+ let lib_output = redact_rustc_message ( & lib_output) ;
114
+ let lib_test_output = raw_rustc_output ( & p, "src/lib.rs" , & [ "--test" ] ) ;
115
+ let mut lib_test_output = redact_rustc_message ( & lib_test_output) ;
103
116
// Remove the duplicate warning.
104
117
let start = lib_test_output. find ( & lib_output) . expect ( "same warning" ) ;
105
118
lib_test_output. replace_range ( start..start + lib_output. len ( ) , "" ) ;
106
119
let expected_output = format ! (
107
120
"\
108
121
{}\
109
- warning: `foo` (lib) generated 1 warning[..]
122
+ [WARNING] `foo` (lib) generated 1 warning[..]
110
123
{}\
111
- warning: `foo` (lib test) generated 2 warnings (1 duplicate)
112
- [FINISHED] [..]
113
- [EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[.. ][EXE])
124
+ [WARNING] `foo` (lib test) generated 2 warnings (1 duplicate)
125
+ [FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
126
+ [EXECUTABLE] unittests src/lib.rs (target/debug/deps/foo-[HASH ][EXE])
114
127
" ,
115
128
lib_output, lib_test_output
116
129
) ;
117
130
p. cargo ( "test --no-run -j1" )
118
- . with_stderr ( & format ! ( "[COMPILING] foo v0.0.1 [..]\n {}" , expected_output) )
131
+ . with_stderr_data ( & format ! (
132
+ "\
133
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
134
+ {}" ,
135
+ expected_output
136
+ ) )
119
137
. run ( ) ;
120
138
// Run again, to check for caching behavior.
121
139
p. cargo ( "test --no-run -j1" )
122
- . with_stderr ( expected_output)
140
+ . with_stderr_data ( expected_output)
123
141
. run ( ) ;
124
142
}
125
143
@@ -134,12 +152,13 @@ fn deduplicate_errors() {
134
152
)
135
153
. build ( ) ;
136
154
let rustc_message = raw_rustc_output ( & p, "src/lib.rs" , & [ ] ) ;
155
+ let rustc_message = redact_rustc_message ( & rustc_message) ;
137
156
p. cargo ( "test -j1" )
138
157
. with_status ( 101 )
139
- . with_stderr ( & format ! (
158
+ . with_stderr_data ( & format ! (
140
159
"\
141
- [COMPILING] foo v0.0.1 [..]
142
- {}error: could not compile `foo` (lib) due to 1 previous error
160
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
161
+ {}[ERROR] could not compile `foo` (lib) due to 1 previous error
143
162
" ,
144
163
rustc_message
145
164
) )
0 commit comments