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

Separate tooltip tests that require Racer fallback #1200

Merged
merged 6 commits into from
Dec 19, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 82 additions & 47 deletions src/actions/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,11 @@ pub mod test {
impl TooltipTestHarness {
/// Creates a new `TooltipTestHarness`. The `project_dir` must contain
/// a valid rust project with a `Cargo.toml`.
pub fn new<O: Output>(project_dir: PathBuf, output: &O) -> TooltipTestHarness {
pub fn new<O: Output>(
project_dir: PathBuf,
output: &O,
racer_fallback_completion: bool,
) -> TooltipTestHarness {
use env_logger;
let _ = env_logger::try_init();

Expand All @@ -1194,6 +1198,11 @@ pub mod test {

let temp_dir = tempfile::tempdir().unwrap().into_path();
config.target_dir = config::Inferrable::Specified(Some(temp_dir.clone()));
config.racer_completion = racer_fallback_completion;
// FIXME(#1195): This led to spurious failures on macOS; possibly
// because regular build and #[cfg(test)] did race or rls-analysis
// didn't lower them properly?
config.all_targets = false;

let config = Arc::new(Mutex::new(config));
let analysis = Arc::new(analysis::AnalysisHost::new(analysis::Target::Debug));
Expand Down Expand Up @@ -2047,10 +2056,53 @@ pub mod test {
assert_eq!(expected, actual);
}

enum RacerFallback {
Yes,
No,
}

impl From<RacerFallback> for bool {
fn from(arg: RacerFallback) -> bool {
match arg {
RacerFallback::Yes => true,
RacerFallback::No => false,
}
}
}

// Common logic used in `test_tooltip_*` tests below
fn run_tooltip_tests(
tests: &[Test],
proj_dir: PathBuf,
racer_completion: RacerFallback,
) -> Result<(), Box<dyn std::error::Error>> {
let out = LineOutput::default();

let save_dir_guard = tempfile::tempdir().unwrap();
let save_dir = save_dir_guard.path().to_owned();
let load_dir = proj_dir.join("save_data");

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

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())
}
}

#[test]
fn test_tooltip() -> Result<(), Box<dyn std::error::Error>> {
let _ = env_logger::try_init();
use self::test::{LineOutput, Test, TooltipTestHarness};

let tests = vec![
Test::new("test_tooltip_01.rs", 13, 11),
Expand Down Expand Up @@ -2082,7 +2134,6 @@ pub mod test {
Test::new("test_tooltip_01.rs", 68, 11),
Test::new("test_tooltip_01.rs", 68, 26),
Test::new("test_tooltip_01.rs", 75, 10),
Test::new("test_tooltip_01.rs", 80, 11),
Test::new("test_tooltip_01.rs", 85, 14),
Test::new("test_tooltip_01.rs", 85, 50),
Test::new("test_tooltip_01.rs", 85, 54),
Expand All @@ -2091,7 +2142,6 @@ pub mod test {
Test::new("test_tooltip_01.rs", 87, 20),
Test::new("test_tooltip_01.rs", 88, 18),
Test::new("test_tooltip_01.rs", 93, 11),
Test::new("test_tooltip_01.rs", 93, 18),
Test::new("test_tooltip_01.rs", 95, 25),
Test::new("test_tooltip_01.rs", 109, 21),
Test::new("test_tooltip_01.rs", 113, 21),
Expand All @@ -2100,32 +2150,24 @@ pub mod test {
Test::new("test_tooltip_mod_use.rs", 12, 14),
Test::new("test_tooltip_mod_use.rs", 12, 25),
Test::new("test_tooltip_mod_use.rs", 13, 28),
Test::new("test_tooltip_mod_use_external.rs", 11, 7),
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 out = LineOutput::default();
let proj_dir = FIXTURES_DIR.join("hover");

let save_dir_guard = tempfile::tempdir().unwrap();
let save_dir = save_dir_guard.path().to_owned();
let load_dir = proj_dir.join("save_data");

let harness = TooltipTestHarness::new(proj_dir, &out);
run_tooltip_tests(&tests, FIXTURES_DIR.join("hover"), RacerFallback::No)
}

out.reset();
#[test]
fn test_tooltip_racer() -> Result<(), Box<dyn std::error::Error>> {
let _ = env_logger::try_init();

let failures = harness.run_tests(&tests, load_dir, save_dir)?;
let tests = vec![
Test::new("test_tooltip_01.rs", 80, 11),
Test::new("test_tooltip_01.rs", 93, 18),
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),
];

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())
}
run_tooltip_tests(&tests, FIXTURES_DIR.join("hover"), RacerFallback::Yes)
}

/// Note: This test is ignored as it doesn't work in the rust-lang/rust repo.
Expand All @@ -2135,13 +2177,8 @@ pub mod test {
#[ignore]
fn test_tooltip_std() -> Result<(), Box<dyn std::error::Error>> {
let _ = env_logger::try_init();
use self::test::{LineOutput, Test, TooltipTestHarness};

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 All @@ -2157,25 +2194,23 @@ pub mod test {
Test::new("test_tooltip_std.rs", 25, 25),
];

let out = LineOutput::default();
let proj_dir = FIXTURES_DIR.join("hover");

let save_dir_guard = tempfile::tempdir().unwrap();
let save_dir = save_dir_guard.path().to_owned();
let load_dir = proj_dir.join("save_data");

let harness = TooltipTestHarness::new(proj_dir, &out);
run_tooltip_tests(&tests, FIXTURES_DIR.join("hover"), RacerFallback::No)
}

out.reset();
/// 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_racer() -> Result<(), Box<dyn std::error::Error>> {
let _ = env_logger::try_init();

let failures = harness.run_tests(&tests, load_dir, save_dir)?;
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),
];

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())
}
run_tooltip_tests(&tests, FIXTURES_DIR.join("hover"), RacerFallback::Yes)
}
}