8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- #![ feature( rand, core ) ]
11
+ #![ feature( rand) ]
12
12
13
13
use std:: fs:: File ;
14
14
use std:: io:: prelude:: * ;
@@ -18,6 +18,11 @@ use std::process::Command;
18
18
use std:: __rand:: { thread_rng, Rng } ;
19
19
use std:: { char, env} ;
20
20
21
+ pub fn check_old_skool ( ) -> bool {
22
+ use std:: env;
23
+ env:: var ( "RUST_NEW_ERROR_FORMAT" ) . is_err ( )
24
+ }
25
+
21
26
// creates a file with `fn main() { <random ident> }` and checks the
22
27
// compiler emits a span of the appropriate length (for the
23
28
// "unresolved name" message); currently just using the number of code
@@ -65,10 +70,17 @@ fn main() {
65
70
66
71
let err = String :: from_utf8_lossy ( & result. stderr ) ;
67
72
68
- // the span should end the line (e.g no extra ~'s)
69
- let expected_span = format ! ( "^{}\n " , repeat( "~" ) . take( n - 1 )
70
- . collect:: <String >( ) ) ;
71
- assert ! ( err. contains( & expected_span) ) ;
73
+ if check_old_skool ( ) {
74
+ // the span should end the line (e.g no extra ~'s)
75
+ let expected_span = format ! ( "^{}\n " , repeat( "~" ) . take( n - 1 )
76
+ . collect:: <String >( ) ) ;
77
+ assert ! ( err. contains( & expected_span) ) ;
78
+ } else {
79
+ // the span should end the line (e.g no extra ~'s)
80
+ let expected_span = format ! ( "^{}\n " , repeat( "^" ) . take( n - 1 )
81
+ . collect:: <String >( ) ) ;
82
+ assert ! ( err. contains( & expected_span) ) ;
83
+ }
72
84
}
73
85
74
86
// Test multi-column characters and tabs
@@ -77,9 +89,6 @@ fn main() {
77
89
r#"extern "路濫狼á́́" fn foo() {{}} extern "路濫狼á́" fn bar() {{}}"# ) ;
78
90
}
79
91
80
- // Extra characters. Every line is preceded by `filename:lineno <actual code>`
81
- let offset = main_file. to_str ( ) . unwrap ( ) . len ( ) + 3 ;
82
-
83
92
let result = Command :: new ( "sh" )
84
93
. arg ( "-c" )
85
94
. arg ( format ! ( "{} {}" ,
@@ -91,17 +100,31 @@ fn main() {
91
100
92
101
// Test both the length of the snake and the leading spaces up to it
93
102
94
- // First snake is 8 ~s long, with 7 preceding spaces (excluding file name/line offset)
95
- let expected_span = format ! ( "\n {}^{}\n " ,
96
- repeat( " " ) . take( offset + 7 ) . collect:: <String >( ) ,
97
- repeat( "~" ) . take( 8 ) . collect:: <String >( ) ) ;
98
- assert ! ( err. contains( & expected_span) ) ;
99
- // Second snake is only 7 ~s long, with 36 preceding spaces,
100
- // because rustc counts chars() now rather than width(). This
101
- // is because width() functions are to be removed from
102
- // librustc_unicode
103
- let expected_span = format ! ( "\n {}^{}\n " ,
104
- repeat( " " ) . take( offset + 36 ) . collect:: <String >( ) ,
105
- repeat( "~" ) . take( 7 ) . collect:: <String >( ) ) ;
106
- assert ! ( err. contains( & expected_span) ) ;
103
+ if check_old_skool ( ) {
104
+ // Extra characters. Every line is preceded by `filename:lineno <actual code>`
105
+ let offset = main_file. to_str ( ) . unwrap ( ) . len ( ) + 3 ;
106
+
107
+ // First snake is 8 ~s long, with 7 preceding spaces (excluding file name/line offset)
108
+ let expected_span = format ! ( "\n {}^{}\n " ,
109
+ repeat( " " ) . take( offset + 7 ) . collect:: <String >( ) ,
110
+ repeat( "~" ) . take( 8 ) . collect:: <String >( ) ) ;
111
+ assert ! ( err. contains( & expected_span) ) ;
112
+ // Second snake is only 7 ~s long, with 36 preceding spaces,
113
+ // because rustc counts chars() now rather than width(). This
114
+ // is because width() functions are to be removed from
115
+ // librustc_unicode
116
+ let expected_span = format ! ( "\n {}^{}\n " ,
117
+ repeat( " " ) . take( offset + 36 ) . collect:: <String >( ) ,
118
+ repeat( "~" ) . take( 7 ) . collect:: <String >( ) ) ;
119
+ assert ! ( err. contains( & expected_span) ) ;
120
+ } else {
121
+ let expected_span = format ! ( "\n |>{}{}\n " ,
122
+ repeat( " " ) . take( 8 ) . collect:: <String >( ) ,
123
+ repeat( "^" ) . take( 9 ) . collect:: <String >( ) ) ;
124
+ assert ! ( err. contains( & expected_span) ) ;
125
+ let expected_span = format ! ( "\n |>{}{}\n " ,
126
+ repeat( " " ) . take( 37 ) . collect:: <String >( ) ,
127
+ repeat( "^" ) . take( 8 ) . collect:: <String >( ) ) ;
128
+ assert ! ( err. contains( & expected_span) ) ;
129
+ }
107
130
}
0 commit comments