1
1
//! Tests for whether or not warnings are displayed for build scripts.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use cargo_test_support:: registry:: Package ;
6
- use cargo_test_support:: { project, Project } ;
7
-
8
- static WARNING1 : & str = "Hello! I'm a warning. :)" ;
9
- static WARNING2 : & str = "And one more!" ;
4
+ use cargo_test_support:: { project, str, Project } ;
10
5
11
6
fn make_lib ( lib_src : & str ) {
7
+ let warning1: & str = "Hello! I'm a warning. :)" ;
8
+ let warning2: & str = "And one more!" ;
12
9
Package :: new ( "bar" , "0.0.1" )
13
10
. file (
14
11
"Cargo.toml" ,
@@ -33,7 +30,7 @@ fn make_lib(lib_src: &str) {
33
30
println!("cargo::warning={{}}", "{}");
34
31
}}
35
32
"# ,
36
- WARNING1 , WARNING2
33
+ warning1 , warning2
37
34
) ,
38
35
)
39
36
. file ( "src/lib.rs" , & format ! ( "fn f() {{ {} }}" , lib_src) )
@@ -65,17 +62,16 @@ fn no_warning_on_success() {
65
62
let upstream = make_upstream ( "" ) ;
66
63
upstream
67
64
. cargo ( "build" )
68
- . with_stderr (
69
- "\
70
- [UPDATING] `[..]` index
65
+ . with_stderr_data ( str![ [ r#"
66
+ [UPDATING] `dummy-registry` index
71
67
[LOCKING] 2 packages to latest compatible versions
72
68
[DOWNLOADING] crates ...
73
- [DOWNLOADED] bar v0.0.1 ([..] )
69
+ [DOWNLOADED] bar v0.0.1 (registry `dummy-registry` )
74
70
[COMPILING] bar v0.0.1
75
- [COMPILING] foo v0.0.1 ([..] )
76
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
77
- " ,
78
- )
71
+ [COMPILING] foo v0.0.1 ([ROOT]/foo )
72
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
73
+
74
+ "# ] ] )
79
75
. run ( ) ;
80
76
}
81
77
@@ -86,31 +82,55 @@ fn no_warning_on_bin_failure() {
86
82
upstream
87
83
. cargo ( "build" )
88
84
. with_status ( 101 )
89
- . with_stdout_does_not_contain ( "hidden stdout" )
90
- . with_stderr_does_not_contain ( "hidden stderr" )
91
- . with_stderr_does_not_contain ( & format ! ( "[WARNING] {}" , WARNING1 ) )
92
- . with_stderr_does_not_contain ( & format ! ( "[WARNING] {}" , WARNING2 ) )
93
- . with_stderr_contains ( "[UPDATING] `[..]` index" )
94
- . with_stderr_contains ( "[DOWNLOADED] bar v0.0.1 ([..])" )
95
- . with_stderr_contains ( "[COMPILING] bar v0.0.1" )
96
- . with_stderr_contains ( "[COMPILING] foo v0.0.1 ([..])" )
85
+ . with_stdout_data ( "" )
86
+ . with_stderr_data ( str![ [ r#"
87
+ [UPDATING] `dummy-registry` index
88
+ [LOCKING] 2 packages to latest compatible versions
89
+ [DOWNLOADING] crates ...
90
+ [DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
91
+ [COMPILING] bar v0.0.1
92
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
93
+ error[E0425]: cannot find function `hi` in this scope
94
+ --> src/main.rs:1:13
95
+ |
96
+ 1 | fn main() { hi() }
97
+ | ^^ not found in this scope
98
+
99
+ For more information about this error, try `rustc --explain E0425`.
100
+ [ERROR] could not compile `foo` (bin "foo") due to 1 previous error
101
+
102
+ "# ] ] )
97
103
. run ( ) ;
98
104
}
99
105
100
106
#[ cargo_test]
101
107
fn warning_on_lib_failure ( ) {
102
- make_lib ( "err ()" ) ;
108
+ make_lib ( "hi ()" ) ;
103
109
let upstream = make_upstream ( "" ) ;
104
110
upstream
105
111
. cargo ( "build" )
106
112
. with_status ( 101 )
107
- . with_stdout_does_not_contain ( "hidden stdout" )
108
- . with_stderr_does_not_contain ( "hidden stderr" )
109
- . with_stderr_does_not_contain ( "[COMPILING] foo v0.0.1 ([..])" )
110
- . with_stderr_contains ( "[UPDATING] `[..]` index" )
111
- . with_stderr_contains ( "[DOWNLOADED] bar v0.0.1 ([..])" )
112
- . with_stderr_contains ( "[COMPILING] bar v0.0.1" )
113
- . with_stderr_contains ( & format ! ( "[WARNING] [email protected] : {}" , WARNING1 ) )
114
- . with_stderr_contains ( & format ! ( "[WARNING] [email protected] : {}" , WARNING2 ) )
113
+ . with_stdout_data ( "" )
114
+ . with_stderr_data ( str![ [ r#"
115
+ [UPDATING] `dummy-registry` index
116
+ [LOCKING] 2 packages to latest compatible versions
117
+ [DOWNLOADING] crates ...
118
+ [DOWNLOADED] bar v0.0.1 (registry `dummy-registry`)
119
+ [COMPILING] bar v0.0.1
120
+ error[E0425]: cannot find function `hi` in this scope
121
+ --> [ROOT]/home/.cargo/registry/src/-[HASH]/bar-0.0.1/src/lib.rs:1:10
122
+ |
123
+ 1 | fn f() { hi() }
124
+ | ^^ not found in this scope
125
+
126
+ For more information about this error, try `rustc --explain E0425`.
127
+ The following warnings were emitted during compilation:
128
+
129
+ [WARNING] [email protected] : Hello! I'm a warning. :)
130
+ [WARNING] [email protected] : And one more!
131
+
132
+ [ERROR] could not compile `bar` (lib) due to 1 previous error
133
+
134
+ "# ] ] )
115
135
. run ( ) ;
116
136
}
0 commit comments