88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- #![ feature( rand, core ) ]
11+ #![ feature( rand) ]
1212
1313use std:: fs:: File ;
1414use std:: io:: prelude:: * ;
@@ -18,6 +18,11 @@ use std::process::Command;
1818use std:: __rand:: { thread_rng, Rng } ;
1919use std:: { char, env} ;
2020
21+ pub fn check_old_skool ( ) -> bool {
22+ use std:: env;
23+ env:: var ( "RUST_NEW_ERROR_FORMAT" ) . is_err ( )
24+ }
25+
2126// creates a file with `fn main() { <random ident> }` and checks the
2227// compiler emits a span of the appropriate length (for the
2328// "unresolved name" message); currently just using the number of code
@@ -65,10 +70,17 @@ fn main() {
6570
6671 let err = String :: from_utf8_lossy ( & result. stderr ) ;
6772
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+ }
7284 }
7385
7486 // Test multi-column characters and tabs
@@ -77,9 +89,6 @@ fn main() {
7789 r#"extern "路濫狼á́́" fn foo() {{}} extern "路濫狼á́" fn bar() {{}}"# ) ;
7890 }
7991
80- // Extra characters. Every line is preceded by `filename:lineno <actual code>`
81- let offset = main_file. to_str ( ) . unwrap ( ) . len ( ) + 3 ;
82-
8392 let result = Command :: new ( "sh" )
8493 . arg ( "-c" )
8594 . arg ( format ! ( "{} {}" ,
@@ -91,17 +100,31 @@ fn main() {
91100
92101 // Test both the length of the snake and the leading spaces up to it
93102
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+ }
107130}
0 commit comments