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