@@ -987,6 +987,7 @@ pub mod test {
987
987
use std:: path:: PathBuf ;
988
988
use std:: process;
989
989
use std:: sync:: { Arc , Mutex } ;
990
+ use std:: fmt;
990
991
991
992
#[ derive( Debug , Serialize , Deserialize , PartialEq , Eq , Clone ) ]
992
993
pub struct Test {
@@ -1102,7 +1103,7 @@ pub mod test {
1102
1103
}
1103
1104
}
1104
1105
1105
- #[ derive( Debug , Serialize , Deserialize , PartialEq , Eq ) ]
1106
+ #[ derive( PartialEq , Eq ) ]
1106
1107
pub struct TestFailure {
1107
1108
/// The test case, indicating file, line, and column
1108
1109
pub test : Test ,
@@ -1119,6 +1120,23 @@ pub mod test {
1119
1120
pub actual_data : Result < Result < Vec < MarkedString > , String > , ( ) > ,
1120
1121
}
1121
1122
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
+
1122
1140
#[ derive( Clone , Default ) ]
1123
1141
pub struct LineOutput {
1124
1142
req_id : Arc < Mutex < u64 > > ,
@@ -1289,6 +1307,10 @@ pub mod test {
1289
1307
1290
1308
impl Drop for TooltipTestHarness {
1291
1309
fn drop ( & mut self ) {
1310
+ if let Ok ( mut jobs) = self . ctx . jobs . lock ( ) {
1311
+ jobs. wait_for_all ( ) ;
1312
+ }
1313
+
1292
1314
if fs:: metadata ( & self . working_dir ) . is_ok ( ) {
1293
1315
fs:: remove_dir_all ( & self . working_dir ) . expect ( "failed to tidy up" ) ;
1294
1316
}
@@ -2030,9 +2052,8 @@ pub mod test {
2030
2052
}
2031
2053
2032
2054
#[ test]
2033
- // doesn't work in the rust-lang/rust repo, enable on CI
2034
- #[ cfg_attr( not( enable_tooltip_tests) , ignore) ]
2035
2055
fn test_tooltip ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2056
+ let _ = env_logger:: try_init ( ) ;
2036
2057
use self :: test:: { LineOutput , Test , TooltipTestHarness } ;
2037
2058
use std:: env;
2038
2059
@@ -2088,8 +2109,48 @@ pub mod test {
2088
2109
Test :: new( "test_tooltip_mod_use_external.rs" , 11 , 7 ) ,
2089
2110
Test :: new( "test_tooltip_mod_use_external.rs" , 12 , 7 ) ,
2090
2111
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
2091
2151
Test :: new( "test_tooltip_mod_use_external.rs" , 14 , 12 ) ,
2092
2152
Test :: new( "test_tooltip_mod_use_external.rs" , 15 , 12 ) ,
2153
+
2093
2154
Test :: new( "test_tooltip_std.rs" , 18 , 15 ) ,
2094
2155
Test :: new( "test_tooltip_std.rs" , 18 , 27 ) ,
2095
2156
Test :: new( "test_tooltip_std.rs" , 19 , 7 ) ,
@@ -2125,7 +2186,7 @@ pub mod test {
2125
2186
Ok ( ( ) )
2126
2187
} else {
2127
2188
eprintln ! ( "{}\n \n " , out. reset( ) . join( "\n " ) ) ;
2128
- eprintln ! ( "{:#?}\n \n " , failures) ;
2189
+ eprintln ! ( "Failures ( \x1b [91mexpected \x1b [92mactual \x1b [0m): {:#?}\n \n " , failures) ;
2129
2190
Err ( format ! ( "{} of {} tooltip tests failed" , failures. len( ) , tests. len( ) ) . into ( ) )
2130
2191
}
2131
2192
}
0 commit comments