1- use super :: * ;
1+ use std:: path:: Path ;
2+
3+ use crate :: common:: { Config , Debugger } ;
4+ use crate :: header:: { parse_normalization_string, EarlyProps } ;
25
36#[ test]
47fn test_parse_normalization_string ( ) {
@@ -25,3 +28,154 @@ fn test_parse_normalization_string() {
2528 assert_eq ! ( first, Some ( "something (32 bits)" . to_owned( ) ) ) ;
2629 assert_eq ! ( s, " -> \" something ($WORD bits)." ) ;
2730}
31+
32+ fn config ( ) -> Config {
33+ let args = & [
34+ "compiletest" ,
35+ "--mode=ui" ,
36+ "--compile-lib-path=" ,
37+ "--run-lib-path=" ,
38+ "--rustc-path=" ,
39+ "--lldb-python=" ,
40+ "--docck-python=" ,
41+ "--src-base=" ,
42+ "--build-base=" ,
43+ "--stage-id=stage2" ,
44+ "--cc=c" ,
45+ "--cxx=c++" ,
46+ "--cflags=" ,
47+ "--llvm-components=" ,
48+ "--llvm-cxxflags=" ,
49+ "--android-cross-path=" ,
50+ "--target=x86_64-unknown-linux-gnu" ,
51+ ] ;
52+ let args = args. iter ( ) . map ( ToString :: to_string) . collect ( ) ;
53+ crate :: parse_config ( args)
54+ }
55+
56+ fn parse_rs ( config : & Config , contents : & str ) -> EarlyProps {
57+ let bytes = contents. as_bytes ( ) ;
58+ EarlyProps :: from_reader ( config, Path :: new ( "a.rs" ) , bytes)
59+ }
60+
61+ fn parse_makefile ( config : & Config , contents : & str ) -> EarlyProps {
62+ let bytes = contents. as_bytes ( ) ;
63+ EarlyProps :: from_reader ( config, Path :: new ( "Makefile" ) , bytes)
64+ }
65+
66+ #[ test]
67+ fn should_fail ( ) {
68+ let config = config ( ) ;
69+
70+ assert ! ( !parse_rs( & config, "" ) . should_fail) ;
71+ assert ! ( parse_rs( & config, "// should-fail" ) . should_fail) ;
72+ }
73+
74+ #[ test]
75+ fn revisions ( ) {
76+ let config = config ( ) ;
77+
78+ assert_eq ! ( parse_rs( & config, "// revisions: a b c" ) . revisions, vec![ "a" , "b" , "c" ] , ) ;
79+ assert_eq ! (
80+ parse_makefile( & config, "# revisions: hello there" ) . revisions,
81+ vec![ "hello" , "there" ] ,
82+ ) ;
83+ }
84+
85+ #[ test]
86+ fn aux_build ( ) {
87+ let config = config ( ) ;
88+
89+ assert_eq ! (
90+ parse_rs(
91+ & config,
92+ r"
93+ // aux-build: a.rs
94+ // aux-build: b.rs
95+ "
96+ )
97+ . aux,
98+ vec![ "a.rs" , "b.rs" ] ,
99+ ) ;
100+ }
101+
102+ #[ test]
103+ fn no_system_llvm ( ) {
104+ let mut config = config ( ) ;
105+
106+ config. system_llvm = false ;
107+ assert ! ( !parse_rs( & config, "// no-system-llvm" ) . ignore) ;
108+
109+ config. system_llvm = true ;
110+ assert ! ( parse_rs( & config, "// no-system-llvm" ) . ignore) ;
111+ }
112+
113+ #[ test]
114+ fn ignore_target ( ) {
115+ let mut config = config ( ) ;
116+ config. target = "x86_64-unknown-linux-gnu" . to_owned ( ) ;
117+
118+ assert ! ( parse_rs( & config, "// ignore-x86_64-unknown-linux-gnu" ) . ignore) ;
119+ assert ! ( parse_rs( & config, "// ignore-x86_64" ) . ignore) ;
120+ assert ! ( parse_rs( & config, "// ignore-linux" ) . ignore) ;
121+ assert ! ( parse_rs( & config, "// ignore-gnu" ) . ignore) ;
122+ assert ! ( parse_rs( & config, "// ignore-64bit" ) . ignore) ;
123+
124+ assert ! ( !parse_rs( & config, "// ignore-i686" ) . ignore) ;
125+ assert ! ( !parse_rs( & config, "// ignore-windows" ) . ignore) ;
126+ assert ! ( !parse_rs( & config, "// ignore-msvc" ) . ignore) ;
127+ assert ! ( !parse_rs( & config, "// ignore-32bit" ) . ignore) ;
128+ }
129+
130+ #[ test]
131+ fn only_target ( ) {
132+ let mut config = config ( ) ;
133+ config. target = "x86_64-pc-windows-gnu" . to_owned ( ) ;
134+
135+ assert ! ( parse_rs( & config, "// only-i686" ) . ignore) ;
136+ assert ! ( parse_rs( & config, "// only-linux" ) . ignore) ;
137+ assert ! ( parse_rs( & config, "// only-msvc" ) . ignore) ;
138+ assert ! ( parse_rs( & config, "// only-32bit" ) . ignore) ;
139+
140+ assert ! ( !parse_rs( & config, "// only-x86_64-pc-windows-gnu" ) . ignore) ;
141+ assert ! ( !parse_rs( & config, "// only-x86_64" ) . ignore) ;
142+ assert ! ( !parse_rs( & config, "// only-windows" ) . ignore) ;
143+ assert ! ( !parse_rs( & config, "// only-gnu" ) . ignore) ;
144+ assert ! ( !parse_rs( & config, "// only-64bit" ) . ignore) ;
145+ }
146+
147+ #[ test]
148+ fn stage ( ) {
149+ let mut config = config ( ) ;
150+ config. stage_id = "stage1" . to_owned ( ) ;
151+
152+ assert ! ( parse_rs( & config, "// ignore-stage1" ) . ignore) ;
153+ assert ! ( !parse_rs( & config, "// ignore-stage2" ) . ignore) ;
154+ }
155+
156+ #[ test]
157+ fn cross_compile ( ) {
158+ let mut config = config ( ) ;
159+ config. host = "x86_64-apple-darwin" . to_owned ( ) ;
160+ config. target = "wasm32-unknown-unknown" . to_owned ( ) ;
161+ assert ! ( parse_rs( & config, "// ignore-cross-compile" ) . ignore) ;
162+
163+ config. target = config. host . clone ( ) ;
164+ assert ! ( !parse_rs( & config, "// ignore-cross-compile" ) . ignore) ;
165+ }
166+
167+ #[ test]
168+ fn debugger ( ) {
169+ let mut config = config ( ) ;
170+ config. debugger = None ;
171+ assert ! ( !parse_rs( & config, "// ignore-cdb" ) . ignore) ;
172+
173+ config. debugger = Some ( Debugger :: Cdb ) ;
174+ assert ! ( parse_rs( & config, "// ignore-cdb" ) . ignore) ;
175+
176+ config. debugger = Some ( Debugger :: Gdb ) ;
177+ assert ! ( parse_rs( & config, "// ignore-gdb" ) . ignore) ;
178+
179+ config. debugger = Some ( Debugger :: Lldb ) ;
180+ assert ! ( parse_rs( & config, "// ignore-lldb" ) . ignore) ;
181+ }
0 commit comments