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