@@ -987,6 +987,7 @@ pub mod test {
987987 use std:: path:: PathBuf ;
988988 use std:: process;
989989 use std:: sync:: { Arc , Mutex } ;
990+ use std:: fmt;
990991
991992 #[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Clone ) ]
992993 pub struct Test {
@@ -1102,7 +1103,7 @@ pub mod test {
11021103 }
11031104 }
11041105
1105- #[ derive( Debug , Serialize , Deserialize , PartialEq , Eq ) ]
1106+ #[ derive( PartialEq , Eq ) ]
11061107 pub struct TestFailure {
11071108 /// The test case, indicating file, line, and column
11081109 pub test : Test ,
@@ -1119,6 +1120,23 @@ pub mod test {
11191120 pub actual_data : Result < Result < Vec < MarkedString > , String > , ( ) > ,
11201121 }
11211122
1123+ impl fmt:: Debug for TestFailure {
1124+ fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1125+ fmt. debug_struct ( "TestFailure" )
1126+ . field ( "test" , & self . test )
1127+ . field ( "expect_file" , & self . expect_file )
1128+ . field ( "actual_file" , & self . actual_file )
1129+ . field ( "expect_data" , & self . expect_data )
1130+ . field ( "actual_data" , & self . actual_data )
1131+ . finish ( ) ?;
1132+
1133+ let expected = format ! ( "{:#?}" , self . expect_data) ;
1134+ let actual = format ! ( "{:#?}" , self . actual_data) ;
1135+ write ! ( fmt, "-diff: {}" , difference:: Changeset :: new( & expected, & actual, "" ) )
1136+ }
1137+ }
1138+
1139+
11221140 #[ derive( Clone , Default ) ]
11231141 pub struct LineOutput {
11241142 req_id : Arc < Mutex < u64 > > ,
@@ -1289,6 +1307,10 @@ pub mod test {
12891307
12901308 impl Drop for TooltipTestHarness {
12911309 fn drop ( & mut self ) {
1310+ if let Ok ( mut jobs) = self . ctx . jobs . lock ( ) {
1311+ jobs. wait_for_all ( ) ;
1312+ }
1313+
12921314 if fs:: metadata ( & self . working_dir ) . is_ok ( ) {
12931315 fs:: remove_dir_all ( & self . working_dir ) . expect ( "failed to tidy up" ) ;
12941316 }
@@ -2030,9 +2052,8 @@ pub mod test {
20302052 }
20312053
20322054 #[ test]
2033- // doesn't work in the rust-lang/rust repo, enable on CI
2034- #[ cfg_attr( not( enable_tooltip_tests) , ignore) ]
20352055 fn test_tooltip ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2056+ let _ = env_logger:: try_init ( ) ;
20362057 use self :: test:: { LineOutput , Test , TooltipTestHarness } ;
20372058 use std:: env;
20382059
@@ -2088,8 +2109,48 @@ pub mod test {
20882109 Test :: new( "test_tooltip_mod_use_external.rs" , 11 , 7 ) ,
20892110 Test :: new( "test_tooltip_mod_use_external.rs" , 12 , 7 ) ,
20902111 Test :: new( "test_tooltip_mod_use_external.rs" , 12 , 12 ) ,
2112+ ] ;
2113+
2114+ let cwd = env:: current_dir ( ) ?;
2115+ let out = LineOutput :: default ( ) ;
2116+ let proj_dir = cwd. join ( "test_data" ) . join ( "hover" ) ;
2117+ let save_dir = cwd
2118+ . join ( "target" )
2119+ . join ( "tests" )
2120+ . join ( "hover" )
2121+ . join ( "save_data" ) ;
2122+ let load_dir = proj_dir. join ( "save_data" ) ;
2123+
2124+ let harness = TooltipTestHarness :: new ( proj_dir, & out) ;
2125+
2126+ out. reset ( ) ;
2127+
2128+ let failures = harness. run_tests ( & tests, load_dir, save_dir) ?;
2129+
2130+ if failures. is_empty ( ) {
2131+ Ok ( ( ) )
2132+ } else {
2133+ eprintln ! ( "{}\n \n " , out. reset( ) . join( "\n " ) ) ;
2134+ eprintln ! ( "Failures (\x1b [91mexpected\x1b [92mactual\x1b [0m): {:#?}\n \n " , failures) ;
2135+ Err ( format ! ( "{} of {} tooltip tests failed" , failures. len( ) , tests. len( ) ) . into ( ) )
2136+ }
2137+ }
2138+
2139+ /// Note: This test is ignored as it doesn't work in the rust-lang/rust repo.
2140+ /// It is enabled on CI.
2141+ /// Run with `cargo test test_tooltip_std -- --ignored`
2142+ #[ test]
2143+ #[ ignore]
2144+ fn test_tooltip_std ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2145+ let _ = env_logger:: try_init ( ) ;
2146+ use self :: test:: { LineOutput , Test , TooltipTestHarness } ;
2147+ use std:: env;
2148+
2149+ let tests = vec ! [
2150+ // these test std stuff
20912151 Test :: new( "test_tooltip_mod_use_external.rs" , 14 , 12 ) ,
20922152 Test :: new( "test_tooltip_mod_use_external.rs" , 15 , 12 ) ,
2153+
20932154 Test :: new( "test_tooltip_std.rs" , 18 , 15 ) ,
20942155 Test :: new( "test_tooltip_std.rs" , 18 , 27 ) ,
20952156 Test :: new( "test_tooltip_std.rs" , 19 , 7 ) ,
@@ -2125,7 +2186,7 @@ pub mod test {
21252186 Ok ( ( ) )
21262187 } else {
21272188 eprintln ! ( "{}\n \n " , out. reset( ) . join( "\n " ) ) ;
2128- eprintln ! ( "{:#?}\n \n " , failures) ;
2189+ eprintln ! ( "Failures ( \x1b [91mexpected \x1b [92mactual \x1b [0m): {:#?}\n \n " , failures) ;
21292190 Err ( format ! ( "{} of {} tooltip tests failed" , failures. len( ) , tests. len( ) ) . into ( ) )
21302191 }
21312192 }
0 commit comments