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

Commit

Permalink
Merge pull request #1175 from alexheretic/split-tooltip-std
Browse files Browse the repository at this point in the history
Improve hover test_tooltip tests
  • Loading branch information
Xanewok authored Dec 13, 2018
2 parents 2edbc7b + 22ade3d commit 9ddbb5a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ install: |
script:
- cargo build -v
- cargo test -v
- cargo test test_tooltip_std -- --ignored

env:
global:
- RUSTFLAGS=--cfg=enable_tooltip_tests
- RUST_BACKTRACE=1
- RLS_TEST_WAIT_FOR_AGES=1
- CARGO_INCREMENTAL=0
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ toml = "0.4"
# for more information.
rustc-workspace-hack = "1.0.0"

[dev-dependencies]
difference = "2"

[build-dependencies]
rustc_tools_util = { git = "https://github.com/rust-lang/rust-clippy", rev = "a3c77f6ad1c1c185e561e9cd7fdec7db569169d1" }

Expand Down
69 changes: 65 additions & 4 deletions src/actions/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -987,6 +987,7 @@ pub mod test {
use std::path::PathBuf;
use std::process;
use std::sync::{Arc, Mutex};
use std::fmt;

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
pub struct Test {
Expand Down Expand Up @@ -1102,7 +1103,7 @@ pub mod test {
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(PartialEq, Eq)]
pub struct TestFailure {
/// The test case, indicating file, line, and column
pub test: Test,
Expand All @@ -1119,6 +1120,23 @@ pub mod test {
pub actual_data: Result<Result<Vec<MarkedString>, String>, ()>,
}

impl fmt::Debug for TestFailure {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("TestFailure")
.field("test", &self.test)
.field("expect_file", &self.expect_file)
.field("actual_file", &self.actual_file)
.field("expect_data", &self.expect_data)
.field("actual_data", &self.actual_data)
.finish()?;

let expected = format!("{:#?}", self.expect_data);
let actual = format!("{:#?}", self.actual_data);
write!(fmt, "-diff: {}", difference::Changeset::new(&expected, &actual, ""))
}
}


#[derive(Clone, Default)]
pub struct LineOutput {
req_id: Arc<Mutex<u64>>,
Expand Down Expand Up @@ -1289,6 +1307,10 @@ pub mod test {

impl Drop for TooltipTestHarness {
fn drop(&mut self) {
if let Ok(mut jobs) = self.ctx.jobs.lock() {
jobs.wait_for_all();
}

if fs::metadata(&self.working_dir).is_ok() {
fs::remove_dir_all(&self.working_dir).expect("failed to tidy up");
}
Expand Down Expand Up @@ -2030,9 +2052,8 @@ pub mod test {
}

#[test]
// doesn't work in the rust-lang/rust repo, enable on CI
#[cfg_attr(not(enable_tooltip_tests), ignore)]
fn test_tooltip() -> Result<(), Box<dyn std::error::Error>> {
let _ = env_logger::try_init();
use self::test::{LineOutput, Test, TooltipTestHarness};
use std::env;

Expand Down Expand Up @@ -2088,8 +2109,48 @@ pub mod test {
Test::new("test_tooltip_mod_use_external.rs", 11, 7),
Test::new("test_tooltip_mod_use_external.rs", 12, 7),
Test::new("test_tooltip_mod_use_external.rs", 12, 12),
];

let cwd = env::current_dir()?;
let out = LineOutput::default();
let proj_dir = cwd.join("test_data").join("hover");
let save_dir = cwd
.join("target")
.join("tests")
.join("hover")
.join("save_data");
let load_dir = proj_dir.join("save_data");

let harness = TooltipTestHarness::new(proj_dir, &out);

out.reset();

let failures = harness.run_tests(&tests, load_dir, save_dir)?;

if failures.is_empty() {
Ok(())
} else {
eprintln!("{}\n\n", out.reset().join("\n"));
eprintln!("Failures (\x1b[91mexpected\x1b[92mactual\x1b[0m): {:#?}\n\n", failures);
Err(format!("{} of {} tooltip tests failed", failures.len(), tests.len()).into())
}
}

/// Note: This test is ignored as it doesn't work in the rust-lang/rust repo.
/// It is enabled on CI.
/// Run with `cargo test test_tooltip_std -- --ignored`
#[test]
#[ignore]
fn test_tooltip_std() -> Result<(), Box<dyn std::error::Error>> {
let _ = env_logger::try_init();
use self::test::{LineOutput, Test, TooltipTestHarness};
use std::env;

let tests = vec![
// these test std stuff
Test::new("test_tooltip_mod_use_external.rs", 14, 12),
Test::new("test_tooltip_mod_use_external.rs", 15, 12),

Test::new("test_tooltip_std.rs", 18, 15),
Test::new("test_tooltip_std.rs", 18, 27),
Test::new("test_tooltip_std.rs", 19, 7),
Expand Down Expand Up @@ -2125,7 +2186,7 @@ pub mod test {
Ok(())
} else {
eprintln!("{}\n\n", out.reset().join("\n"));
eprintln!("{:#?}\n\n", failures);
eprintln!("Failures (\x1b[91mexpected\x1b[92mactual\x1b[0m): {:#?}\n\n", failures);
Err(format!("{} of {} tooltip tests failed", failures.len(), tests.len()).into())
}
}
Expand Down

0 comments on commit 9ddbb5a

Please sign in to comment.