Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 9ddbb5a

Browse files
authored
Merge pull request #1175 from alexheretic/split-tooltip-std
Improve hover test_tooltip tests
2 parents 2edbc7b + 22ade3d commit 9ddbb5a

File tree

4 files changed

+77
-5
lines changed

4 files changed

+77
-5
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ install: |
2020
script:
2121
- cargo build -v
2222
- cargo test -v
23+
- cargo test test_tooltip_std -- --ignored
24+
2325
env:
2426
global:
25-
- RUSTFLAGS=--cfg=enable_tooltip_tests
2627
- RUST_BACKTRACE=1
2728
- RLS_TEST_WAIT_FOR_AGES=1
2829
- CARGO_INCREMENTAL=0

Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ toml = "0.4"
4949
# for more information.
5050
rustc-workspace-hack = "1.0.0"
5151

52+
[dev-dependencies]
53+
difference = "2"
54+
5255
[build-dependencies]
5356
rustc_tools_util = { git = "https://github.com/rust-lang/rust-clippy", rev = "a3c77f6ad1c1c185e561e9cd7fdec7db569169d1" }
5457

src/actions/hover.rs

+65-4
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)