11
11
use common:: Config ;
12
12
use common:: { CompileFail , ParseFail , Pretty , RunFail , RunPass , RunPassValgrind } ;
13
13
use common:: { Codegen , DebugInfoLldb , DebugInfoGdb , Rustdoc , CodegenUnits } ;
14
- use common:: { Incremental , RunMake } ;
14
+ use common:: { Incremental , RunMake , Ui } ;
15
15
use errors:: { self , ErrorKind , Error } ;
16
16
use json;
17
17
use header:: TestProps ;
@@ -29,6 +29,7 @@ use std::io::prelude::*;
29
29
use std:: net:: TcpStream ;
30
30
use std:: path:: { Path , PathBuf } ;
31
31
use std:: process:: { Command , Output , ExitStatus } ;
32
+ use std:: str;
32
33
33
34
pub fn run ( config : Config , testpaths : & TestPaths ) {
34
35
match & * config. target {
@@ -118,6 +119,7 @@ impl<'test> TestCx<'test> {
118
119
CodegenUnits => self . run_codegen_units_test ( ) ,
119
120
Incremental => self . run_incremental_test ( ) ,
120
121
RunMake => self . run_rmake_test ( ) ,
122
+ Ui => self . run_ui_test ( ) ,
121
123
}
122
124
}
123
125
@@ -1314,6 +1316,7 @@ actual:\n\
1314
1316
Codegen |
1315
1317
Rustdoc |
1316
1318
RunMake |
1319
+ Ui |
1317
1320
CodegenUnits => {
1318
1321
// do not use JSON output
1319
1322
}
@@ -2096,6 +2099,89 @@ actual:\n\
2096
2099
}
2097
2100
fs:: remove_dir ( path)
2098
2101
}
2102
+
2103
+ fn run_ui_test ( & self ) {
2104
+ println ! ( "ui: {}" , self . testpaths. file. display( ) ) ;
2105
+
2106
+ let proc_res = self . compile_test ( ) ;
2107
+
2108
+ let expected_stderr_path = self . expected_output_path ( "stderr" ) ;
2109
+ let expected_stderr = self . load_expected_output ( & expected_stderr_path) ;
2110
+
2111
+ let expected_stdout_path = self . expected_output_path ( "stdout" ) ;
2112
+ let expected_stdout = self . load_expected_output ( & expected_stdout_path) ;
2113
+
2114
+ let normalized_stdout = self . normalize_output ( & proc_res. stdout ) ;
2115
+ let normalized_stderr = self . normalize_output ( & proc_res. stderr ) ;
2116
+
2117
+ let mut errors = 0 ;
2118
+ errors += self . compare_output ( "stdout" , normalized_stdout. as_bytes ( ) , & expected_stdout) ;
2119
+ errors += self . compare_output ( "stderr" , normalized_stderr. as_bytes ( ) , & expected_stderr) ;
2120
+
2121
+ if errors > 0 {
2122
+ println ! ( "To update references, run this command from build directory:" ) ;
2123
+ let relative_path_to_file =
2124
+ self . testpaths . relative_dir
2125
+ . join ( self . testpaths . file . file_name ( ) . unwrap ( ) ) ;
2126
+ println ! ( "{}/update-references.sh '{}' '{}'" ,
2127
+ self . config. src_base. display( ) ,
2128
+ self . config. build_base. display( ) ,
2129
+ relative_path_to_file. display( ) ) ;
2130
+ self . fatal ( & format ! ( "{} errors occurred comparing output." , errors) ) ;
2131
+ }
2132
+ }
2133
+
2134
+ fn normalize_output ( & self , output : & str ) -> String {
2135
+ let parent_dir = self . testpaths . file . parent ( ) . unwrap ( ) ;
2136
+ let parent_dir_str = parent_dir. display ( ) . to_string ( ) ;
2137
+ output. replace ( & parent_dir_str, "$DIR" )
2138
+ . replace ( "\\ " , "/" ) // windows, you know.
2139
+ }
2140
+
2141
+ fn expected_output_path ( & self , kind : & str ) -> PathBuf {
2142
+ let extension = match self . revision {
2143
+ Some ( r) => format ! ( "{}.{}" , r, kind) ,
2144
+ None => kind. to_string ( ) ,
2145
+ } ;
2146
+ self . testpaths . file . with_extension ( extension)
2147
+ }
2148
+
2149
+ fn load_expected_output ( & self , path : & Path ) -> Vec < u8 > {
2150
+ if !path. exists ( ) {
2151
+ return vec ! [ ] ;
2152
+ }
2153
+
2154
+ let mut result = Vec :: new ( ) ;
2155
+ match File :: open ( path) . and_then ( |mut f| f. read_to_end ( & mut result) ) {
2156
+ Ok ( _) => result,
2157
+ Err ( e) => {
2158
+ self . fatal ( & format ! ( "failed to load expected output from `{}`: {}" , path. display( ) , e) )
2159
+ }
2160
+ }
2161
+ }
2162
+
2163
+ fn compare_output ( & self , kind : & str , actual : & [ u8 ] , expected : & [ u8 ] ) -> usize {
2164
+ if self . config . verbose {
2165
+ println ! ( "normalized {}:\n {}\n " , kind, str :: from_utf8( actual) . unwrap_or( "not utf8" ) ) ;
2166
+ println ! ( "expected {}:\n {}\n " , kind, str :: from_utf8( expected) . unwrap_or( "not utf8" ) ) ;
2167
+ }
2168
+ if actual == expected {
2169
+ return 0 ;
2170
+ }
2171
+
2172
+ let output_file = self . output_base_name ( ) . with_extension ( kind) ;
2173
+ match File :: create ( & output_file) . and_then ( |mut f| f. write_all ( actual) ) {
2174
+ Ok ( ( ) ) => { }
2175
+ Err ( e) => {
2176
+ self . fatal ( & format ! ( "failed to write {} to `{}`: {}" ,
2177
+ kind, output_file. display( ) , e) )
2178
+ }
2179
+ }
2180
+
2181
+ println ! ( "\n The actual {0} differed from the expected {0}." , kind) ;
2182
+ println ! ( "Actual {} saved to {}" , kind, output_file. display( ) ) ;
2183
+ 1
2184
+ }
2099
2185
}
2100
2186
2101
2187
struct ProcArgs {
0 commit comments