@@ -12,15 +12,16 @@ use boml::Toml;
12
12
/// Controls the compile options (e.g., optimization level) used to compile
13
13
/// test code.
14
14
#[ allow( dead_code) ] // Each test crate picks one variant
15
+ #[ derive( Clone , Copy ) ]
15
16
pub enum Profile {
16
17
Debug ,
17
18
Release ,
18
19
}
19
20
20
21
pub fn main_inner ( profile : Profile ) {
21
22
let tempdir = TempDir :: new ( ) . expect ( "temp dir" ) ;
22
- let current_dir = current_dir ( ) . expect ( "current dir" ) ;
23
- let current_dir = current_dir . to_str ( ) . expect ( "current dir" ) . to_string ( ) ;
23
+ let tempdir2 = TempDir :: new ( ) . expect ( "temp dir" ) ;
24
+
24
25
let toml = Toml :: parse ( include_str ! ( "../config.toml" ) )
25
26
. expect ( "Failed to parse `config.toml`" ) ;
26
27
let gcc_path = if let Ok ( gcc_path) = toml. get_string ( "gcc-path" ) {
@@ -71,6 +72,9 @@ pub fn main_inner(profile: Profile) {
71
72
Some ( lines)
72
73
} )
73
74
. test_cmds ( move |path| {
75
+ let current_dir = current_dir ( ) . expect ( "current dir" ) ;
76
+ let current_dir = current_dir. to_str ( ) . expect ( "current dir" ) . to_string ( ) ;
77
+
74
78
// Test command 1: Compile `x.rs` into `tempdir/x`.
75
79
let mut exe = PathBuf :: new ( ) ;
76
80
exe. push ( & tempdir) ;
@@ -79,6 +83,7 @@ pub fn main_inner(profile: Profile) {
79
83
compiler. args ( & [
80
84
& format ! ( "-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so" , current_dir) ,
81
85
"--sysroot" , & format ! ( "{}/build_sysroot/sysroot/" , current_dir) ,
86
+ "--edition" , "2021" ,
82
87
"-Zno-parallel-llvm" ,
83
88
"-C" , "link-arg=-lc" ,
84
89
"-o" , exe. to_str ( ) . expect ( "to_str" ) ,
@@ -145,4 +150,58 @@ pub fn main_inner(profile: Profile) {
145
150
}
146
151
} )
147
152
. run ( ) ;
153
+
154
+ LangTester :: new ( )
155
+ . test_dir ( "tests/lib" )
156
+ . test_file_filter ( filter)
157
+ . test_extract ( |source| {
158
+ let lines =
159
+ source. lines ( )
160
+ . skip_while ( |l| !l. starts_with ( "//" ) )
161
+ . take_while ( |l| l. starts_with ( "//" ) )
162
+ . map ( |l| & l[ 2 ..] )
163
+ . collect :: < Vec < _ > > ( )
164
+ . join ( "\n " ) ;
165
+ Some ( lines)
166
+ } )
167
+ . test_cmds ( move |path| {
168
+ let current_dir = current_dir ( ) . expect ( "current dir" ) ;
169
+ let current_dir = current_dir. to_str ( ) . expect ( "current dir" ) . to_string ( ) ;
170
+
171
+ // Test command 1: Compile `x.rs` into `tempdir2/x`.
172
+ let mut exe = PathBuf :: new ( ) ;
173
+ exe. push ( & tempdir2) ;
174
+ exe. push ( path. file_stem ( ) . expect ( "file_stem" ) ) ;
175
+ let mut compiler = Command :: new ( "rustc" ) ;
176
+ compiler. args ( & [
177
+ & format ! ( "-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so" , current_dir) ,
178
+ "--sysroot" , & format ! ( "{}/build_sysroot/sysroot/" , current_dir) ,
179
+ "--edition" , "2021" ,
180
+ "--crate-type" , "lib" ,
181
+ "-Zno-parallel-llvm" ,
182
+ "-C" , "link-arg=-lc" ,
183
+ "-o" , exe. to_str ( ) . expect ( "to_str" ) ,
184
+ path. to_str ( ) . expect ( "to_str" ) ,
185
+ ] ) ;
186
+
187
+ if let Some ( flags) = option_env ! ( "TEST_FLAGS" ) {
188
+ for flag in flags. split_whitespace ( ) {
189
+ compiler. arg ( & flag) ;
190
+ }
191
+ }
192
+ match profile {
193
+ Profile :: Debug => { }
194
+ Profile :: Release => {
195
+ compiler. args ( & [
196
+ "-C" , "opt-level=3" ,
197
+ "-C" , "lto=no" ,
198
+ ] ) ;
199
+ }
200
+ }
201
+
202
+ vec ! [
203
+ ( "Compiler" , compiler) ,
204
+ ]
205
+ } )
206
+ . run ( ) ;
148
207
}
0 commit comments