@@ -1175,7 +1175,11 @@ pub mod test {
11751175 impl TooltipTestHarness {
11761176 /// Creates a new `TooltipTestHarness`. The `project_dir` must contain
11771177 /// a valid rust project with a `Cargo.toml`.
1178- pub fn new < O : Output > ( project_dir : PathBuf , output : & O ) -> TooltipTestHarness {
1178+ pub fn new < O : Output > (
1179+ project_dir : PathBuf ,
1180+ output : & O ,
1181+ racer_fallback_completion : bool ,
1182+ ) -> TooltipTestHarness {
11791183 use env_logger;
11801184 let _ = env_logger:: try_init ( ) ;
11811185
@@ -1194,6 +1198,11 @@ pub mod test {
11941198
11951199 let temp_dir = tempfile:: tempdir ( ) . unwrap ( ) . into_path ( ) ;
11961200 config. target_dir = config:: Inferrable :: Specified ( Some ( temp_dir. clone ( ) ) ) ;
1201+ config. racer_completion = racer_fallback_completion;
1202+ // FIXME(#1195): This led to spurious failures on macOS; possibly
1203+ // because regular build and #[cfg(test)] did race or rls-analysis
1204+ // didn't lower them properly?
1205+ config. all_targets = false ;
11971206
11981207 let config = Arc :: new ( Mutex :: new ( config) ) ;
11991208 let analysis = Arc :: new ( analysis:: AnalysisHost :: new ( analysis:: Target :: Debug ) ) ;
@@ -2047,10 +2056,53 @@ pub mod test {
20472056 assert_eq ! ( expected, actual) ;
20482057 }
20492058
2059+ enum RacerFallback {
2060+ Yes ,
2061+ No ,
2062+ }
2063+
2064+ impl From < RacerFallback > for bool {
2065+ fn from ( arg : RacerFallback ) -> bool {
2066+ match arg {
2067+ RacerFallback :: Yes => true ,
2068+ RacerFallback :: No => false ,
2069+ }
2070+ }
2071+ }
2072+
2073+ // Common logic used in `test_tooltip_*` tests below
2074+ fn run_tooltip_tests (
2075+ tests : & [ Test ] ,
2076+ proj_dir : PathBuf ,
2077+ racer_completion : RacerFallback ,
2078+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2079+ let out = LineOutput :: default ( ) ;
2080+
2081+ let save_dir_guard = tempfile:: tempdir ( ) . unwrap ( ) ;
2082+ let save_dir = save_dir_guard. path ( ) . to_owned ( ) ;
2083+ let load_dir = proj_dir. join ( "save_data" ) ;
2084+
2085+ let harness = TooltipTestHarness :: new ( proj_dir, & out, racer_completion. into ( ) ) ;
2086+
2087+ out. reset ( ) ;
2088+
2089+ let failures = harness. run_tests ( tests, load_dir, save_dir) ?;
2090+
2091+ if failures. is_empty ( ) {
2092+ Ok ( ( ) )
2093+ } else {
2094+ eprintln ! ( "{}\n \n " , out. reset( ) . join( "\n " ) ) ;
2095+ eprintln ! (
2096+ "Failures (\x1b [91mexpected\x1b [92mactual\x1b [0m): {:#?}\n \n " ,
2097+ failures
2098+ ) ;
2099+ Err ( format ! ( "{} of {} tooltip tests failed" , failures. len( ) , tests. len( ) ) . into ( ) )
2100+ }
2101+ }
2102+
20502103 #[ test]
20512104 fn test_tooltip ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
20522105 let _ = env_logger:: try_init ( ) ;
2053- use self :: test:: { LineOutput , Test , TooltipTestHarness } ;
20542106
20552107 let tests = vec ! [
20562108 Test :: new( "test_tooltip_01.rs" , 13 , 11 ) ,
@@ -2082,7 +2134,6 @@ pub mod test {
20822134 Test :: new( "test_tooltip_01.rs" , 68 , 11 ) ,
20832135 Test :: new( "test_tooltip_01.rs" , 68 , 26 ) ,
20842136 Test :: new( "test_tooltip_01.rs" , 75 , 10 ) ,
2085- Test :: new( "test_tooltip_01.rs" , 80 , 11 ) ,
20862137 Test :: new( "test_tooltip_01.rs" , 85 , 14 ) ,
20872138 Test :: new( "test_tooltip_01.rs" , 85 , 50 ) ,
20882139 Test :: new( "test_tooltip_01.rs" , 85 , 54 ) ,
@@ -2091,7 +2142,6 @@ pub mod test {
20912142 Test :: new( "test_tooltip_01.rs" , 87 , 20 ) ,
20922143 Test :: new( "test_tooltip_01.rs" , 88 , 18 ) ,
20932144 Test :: new( "test_tooltip_01.rs" , 93 , 11 ) ,
2094- Test :: new( "test_tooltip_01.rs" , 93 , 18 ) ,
20952145 Test :: new( "test_tooltip_01.rs" , 95 , 25 ) ,
20962146 Test :: new( "test_tooltip_01.rs" , 109 , 21 ) ,
20972147 Test :: new( "test_tooltip_01.rs" , 113 , 21 ) ,
@@ -2100,32 +2150,24 @@ pub mod test {
21002150 Test :: new( "test_tooltip_mod_use.rs" , 12 , 14 ) ,
21012151 Test :: new( "test_tooltip_mod_use.rs" , 12 , 25 ) ,
21022152 Test :: new( "test_tooltip_mod_use.rs" , 13 , 28 ) ,
2103- Test :: new( "test_tooltip_mod_use_external.rs" , 11 , 7 ) ,
2104- Test :: new( "test_tooltip_mod_use_external.rs" , 11 , 7 ) ,
2105- Test :: new( "test_tooltip_mod_use_external.rs" , 12 , 7 ) ,
2106- Test :: new( "test_tooltip_mod_use_external.rs" , 12 , 12 ) ,
21072153 ] ;
21082154
2109- let out = LineOutput :: default ( ) ;
2110- let proj_dir = FIXTURES_DIR . join ( "hover" ) ;
2111-
2112- let save_dir_guard = tempfile:: tempdir ( ) . unwrap ( ) ;
2113- let save_dir = save_dir_guard. path ( ) . to_owned ( ) ;
2114- let load_dir = proj_dir. join ( "save_data" ) ;
2115-
2116- let harness = TooltipTestHarness :: new ( proj_dir, & out) ;
2155+ run_tooltip_tests ( & tests, FIXTURES_DIR . join ( "hover" ) , RacerFallback :: No )
2156+ }
21172157
2118- out. reset ( ) ;
2158+ #[ test]
2159+ fn test_tooltip_racer ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2160+ let _ = env_logger:: try_init ( ) ;
21192161
2120- let failures = harness. run_tests ( & tests, load_dir, save_dir) ?;
2162+ let tests = vec ! [
2163+ Test :: new( "test_tooltip_01.rs" , 80 , 11 ) ,
2164+ Test :: new( "test_tooltip_01.rs" , 93 , 18 ) ,
2165+ Test :: new( "test_tooltip_mod_use_external.rs" , 11 , 7 ) ,
2166+ Test :: new( "test_tooltip_mod_use_external.rs" , 12 , 7 ) ,
2167+ Test :: new( "test_tooltip_mod_use_external.rs" , 12 , 12 ) ,
2168+ ] ;
21212169
2122- if failures. is_empty ( ) {
2123- Ok ( ( ) )
2124- } else {
2125- eprintln ! ( "{}\n \n " , out. reset( ) . join( "\n " ) ) ;
2126- eprintln ! ( "Failures (\x1b [91mexpected\x1b [92mactual\x1b [0m): {:#?}\n \n " , failures) ;
2127- Err ( format ! ( "{} of {} tooltip tests failed" , failures. len( ) , tests. len( ) ) . into ( ) )
2128- }
2170+ run_tooltip_tests ( & tests, FIXTURES_DIR . join ( "hover" ) , RacerFallback :: Yes )
21292171 }
21302172
21312173 /// Note: This test is ignored as it doesn't work in the rust-lang/rust repo.
@@ -2135,13 +2177,8 @@ pub mod test {
21352177 #[ ignore]
21362178 fn test_tooltip_std ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
21372179 let _ = env_logger:: try_init ( ) ;
2138- use self :: test:: { LineOutput , Test , TooltipTestHarness } ;
21392180
21402181 let tests = vec ! [
2141- // these test std stuff
2142- Test :: new( "test_tooltip_mod_use_external.rs" , 14 , 12 ) ,
2143- Test :: new( "test_tooltip_mod_use_external.rs" , 15 , 12 ) ,
2144-
21452182 Test :: new( "test_tooltip_std.rs" , 18 , 15 ) ,
21462183 Test :: new( "test_tooltip_std.rs" , 18 , 27 ) ,
21472184 Test :: new( "test_tooltip_std.rs" , 19 , 7 ) ,
@@ -2157,25 +2194,23 @@ pub mod test {
21572194 Test :: new( "test_tooltip_std.rs" , 25 , 25 ) ,
21582195 ] ;
21592196
2160- let out = LineOutput :: default ( ) ;
2161- let proj_dir = FIXTURES_DIR . join ( "hover" ) ;
2162-
2163- let save_dir_guard = tempfile:: tempdir ( ) . unwrap ( ) ;
2164- let save_dir = save_dir_guard. path ( ) . to_owned ( ) ;
2165- let load_dir = proj_dir. join ( "save_data" ) ;
2166-
2167- let harness = TooltipTestHarness :: new ( proj_dir, & out) ;
2197+ run_tooltip_tests ( & tests, FIXTURES_DIR . join ( "hover" ) , RacerFallback :: No )
2198+ }
21682199
2169- out. reset ( ) ;
2200+ /// Note: This test is ignored as it doesn't work in the rust-lang/rust repo.
2201+ /// It is enabled on CI.
2202+ /// Run with `cargo test test_tooltip_std -- --ignored`
2203+ #[ test]
2204+ #[ ignore]
2205+ fn test_tooltip_std_racer ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2206+ let _ = env_logger:: try_init ( ) ;
21702207
2171- let failures = harness. run_tests ( & tests, load_dir, save_dir) ?;
2208+ let tests = vec ! [
2209+ // these test std stuff
2210+ Test :: new( "test_tooltip_mod_use_external.rs" , 14 , 12 ) ,
2211+ Test :: new( "test_tooltip_mod_use_external.rs" , 15 , 12 ) ,
2212+ ] ;
21722213
2173- if failures. is_empty ( ) {
2174- Ok ( ( ) )
2175- } else {
2176- eprintln ! ( "{}\n \n " , out. reset( ) . join( "\n " ) ) ;
2177- eprintln ! ( "Failures (\x1b [91mexpected\x1b [92mactual\x1b [0m): {:#?}\n \n " , failures) ;
2178- Err ( format ! ( "{} of {} tooltip tests failed" , failures. len( ) , tests. len( ) ) . into ( ) )
2179- }
2214+ run_tooltip_tests ( & tests, FIXTURES_DIR . join ( "hover" ) , RacerFallback :: Yes )
21802215 }
21812216}
0 commit comments