fix: possible fix for Intermittent Test Failures in GH Actions (#987)

* fix: possible fix for Intermittent Test Failures in GH Actions

* undo some of the chnages to directory.rs

* typo

* add docs
This commit is contained in:
David Knaack 2020-03-15 18:12:25 +01:00 committed by GitHub
parent fef8cc8bbd
commit 56d475578e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 169 additions and 129 deletions

View File

@ -80,6 +80,14 @@ Integration tests should test full modules or the entire prompt. All integration
For tests that depend on having preexisting state, whatever needed state will have to be added to the project's GitHub Actions workflow file([`.github/workflows/workflow.yml`](.github/workflows/workflow.yml)).
### Test Programming Guidelines
Any tests that depend on File I/O should use [`sync_all()`](https://doc.rust-lang.org/std/fs/struct.File.html#method.sync_all) when creating files or after writing to files.
Any tests that use `tempfile::tempdir` should take care to call `dir.close()` after usage to ensure the lifecycle of the directory can be reasoned about.
Any tests that use `create_fixture_repo()` should remove the returned directory after usage with `remove_dir_all::remove_dir_all()`.
## Running the Documentation Website Locally
If you are contributing to the design of Starship's website, the following section will help you get started.

1
Cargo.lock generated
View File

@ -912,6 +912,7 @@ dependencies = [
"pretty_env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)",
"starship_module_config_derive 0.1.1",
"sysinfo 0.11.7 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -64,6 +64,10 @@ native-tls = { version = "0.2", optional = true }
[dev-dependencies]
tempfile = "3.1.0"
# More realiable than std::fs version on Windows
# For removing temporary directories manually when needed
# This is what tempfile uses to delete temporary directories
remove_dir_all = "0.5.2"
[profile.release]
codegen-units = 1

View File

@ -350,6 +350,7 @@ mod tests {
.is_match(),
false
);
empty.close()?;
let rust = testdir(&["README.md", "Cargo.toml", "src/main.rs"])?;
let rust_dc = DirContents::from_path(&PathBuf::from(rust.path()))?;
@ -363,6 +364,7 @@ mod tests {
.is_match(),
false
);
rust.close()?;
let java = testdir(&["README.md", "src/com/test/Main.java", "pom.xml"])?;
let java_dc = DirContents::from_path(&PathBuf::from(java.path()))?;
@ -376,6 +378,7 @@ mod tests {
.is_match(),
false
);
java.close()?;
let node = testdir(&["README.md", "node_modules/lodash/main.js", "package.json"])?;
let node_dc = DirContents::from_path(&PathBuf::from(node.path()))?;
@ -389,6 +392,7 @@ mod tests {
.is_match(),
true
);
node.close()?;
Ok(())
}

View File

@ -59,7 +59,8 @@ mod tests {
let actual = render_module("crystal", dir.path());
let expected = None;
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -70,7 +71,8 @@ mod tests {
let actual = render_module("crystal", dir.path());
let expected = Some(format!("via {} ", Color::Red.bold().paint("🔮 v0.32.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -81,6 +83,7 @@ mod tests {
let actual = render_module("crystal", dir.path());
let expected = Some(format!("via {} ", Color::Red.bold().paint("🔮 v0.32.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
}

View File

@ -88,7 +88,7 @@ Elixir 1.10 (compiled with Erlang/OTP 22)
assert_eq!(output, expected);
Ok(())
dir.close()
}
#[test]
@ -104,6 +104,6 @@ Elixir 1.10 (compiled with Erlang/OTP 22)
assert_eq!(output, expected);
Ok(())
dir.close()
}
}

View File

@ -49,7 +49,7 @@ mod tests {
let actual = render_module("elm", dir.path());
let expected = None;
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -59,7 +59,7 @@ mod tests {
let actual = render_module("elm", dir.path());
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -69,7 +69,7 @@ mod tests {
let actual = render_module("elm", dir.path());
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -80,7 +80,7 @@ mod tests {
let actual = render_module("elm", dir.path());
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -90,6 +90,6 @@ mod tests {
let actual = render_module("elm", dir.path());
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🌳 v0.19.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
}

View File

@ -72,7 +72,7 @@ mod tests {
let expected = None;
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -84,7 +84,7 @@ mod tests {
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🐹 v1.12.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -96,7 +96,7 @@ mod tests {
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🐹 v1.12.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -108,7 +108,7 @@ mod tests {
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🐹 v1.12.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -121,7 +121,7 @@ mod tests {
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🐹 v1.12.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -133,7 +133,7 @@ mod tests {
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🐹 v1.12.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -145,7 +145,7 @@ mod tests {
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🐹 v1.12.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
fn folder_with_gopkg_lock() -> io::Result<()> {
@ -155,7 +155,7 @@ mod tests {
let actual = render_module("golang", dir.path());
let expected = Some(format!("via {} ", Color::Cyan.bold().paint("🐹 v1.12.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]

View File

@ -51,7 +51,7 @@ mod tests {
let actual = render_module("haskell", dir.path());
let expected = None;
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -61,7 +61,7 @@ mod tests {
let actual = render_module("haskell", dir.path());
let expected = Some(format!("via {} ", Color::Red.bold().paint("λ v8.6.5")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
fn folder_with_cabal_file() -> io::Result<()> {
@ -70,7 +70,7 @@ mod tests {
let actual = render_module("haskell", dir.path());
let expected = Some(format!("via {} ", Color::Red.bold().paint("λ v8.6.5")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -80,6 +80,6 @@ mod tests {
let actual = render_module("haskell", dir.path());
let expected = Some(format!("via {} ", Color::Red.bold().paint("λ v8.6.5")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
}

View File

@ -49,7 +49,7 @@ mod tests {
let actual = render_module("nodejs", dir.path());
let expected = None;
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -60,7 +60,7 @@ mod tests {
let actual = render_module("nodejs", dir.path());
let expected = Some(format!("via {} ", Color::Green.bold().paint("⬢ v12.0.0")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -71,7 +71,7 @@ mod tests {
let actual = render_module("nodejs", dir.path());
let expected = Some(format!("via {} ", Color::Green.bold().paint("⬢ v12.0.0")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -83,6 +83,6 @@ mod tests {
let actual = render_module("nodejs", dir.path());
let expected = Some(format!("via {} ", Color::Green.bold().paint("⬢ v12.0.0")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
}

View File

@ -74,7 +74,7 @@ mod tests {
let expected = None;
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -89,7 +89,7 @@ mod tests {
Color::Fixed(147).bold().paint("🐘 v7.3.8")
));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -104,6 +104,6 @@ mod tests {
Color::Fixed(147).bold().paint("🐘 v7.3.8")
));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
}

View File

@ -63,7 +63,7 @@ mod tests {
let expected = None;
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -75,7 +75,7 @@ mod tests {
let expected = Some(format!("via {} ", Color::Red.bold().paint("💎 v2.5.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -87,7 +87,7 @@ mod tests {
let expected = Some(format!("via {} ", Color::Red.bold().paint("💎 v2.5.1")));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]

View File

@ -104,7 +104,7 @@ region = us-east-2
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ us-east-1"));
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -136,7 +136,7 @@ region = us-east-2
);
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]

View File

@ -1,4 +1,5 @@
use once_cell::sync::Lazy;
use remove_dir_all::remove_dir_all;
use std::io::prelude::*;
use std::io::{Error, ErrorKind};
use std::path::{Path, PathBuf};
@ -43,9 +44,10 @@ pub fn render_module(module_name: &str) -> process::Command {
}
/// Create a repo from the fixture to be used in git module tests
/// Please delete the returned directory manually after usage with `remove_dir_all::remove_dir_all`
pub fn create_fixture_repo() -> io::Result<PathBuf> {
let fixture_repo_path = tempfile::tempdir()?.path().join("fixture");
let repo_path = tempfile::tempdir()?.path().join("rocket");
let fixture_repo_path = tempfile::tempdir()?.into_path();
let repo_path = tempfile::tempdir()?.into_path();
let fixture_path = env::current_dir()?.join("tests/fixtures/rocket.bundle");
let fixture_repo_dir = path_str(&fixture_repo_path)?;
@ -57,6 +59,7 @@ pub fn create_fixture_repo() -> io::Result<PathBuf> {
.output()?;
git2::Repository::clone(&fixture_repo_dir, &repo_dir).ok();
remove_dir_all(fixture_repo_path)?;
Command::new("git")
.args(&["config", "--local", "user.email", "starship@example.com"])

View File

@ -268,7 +268,7 @@ fn git_repo_root() -> io::Result<()> {
let expected = format!("in {} ", Color::Cyan.bold().paint("rocket-controls"));
assert_eq!(expected, actual);
Ok(())
tmp_dir.close()
}
#[test]
@ -288,7 +288,7 @@ fn directory_in_git_repo() -> io::Result<()> {
let expected = format!("in {} ", Color::Cyan.bold().paint("rocket-controls/src"));
assert_eq!(expected, actual);
Ok(())
tmp_dir.close()
}
#[test]
@ -308,7 +308,7 @@ fn truncated_directory_in_git_repo() -> io::Result<()> {
let expected = format!("in {} ", Color::Cyan.bold().paint("src/meters/fuel-gauge"));
assert_eq!(expected, actual);
Ok(())
tmp_dir.close()
}
#[test]
@ -339,7 +339,7 @@ fn directory_in_git_repo_truncate_to_repo_false() -> io::Result<()> {
.paint("above-repo/rocket-controls/src/meters/fuel-gauge")
);
assert_eq!(expected, actual);
Ok(())
tmp_dir.close()
}
#[test]
@ -371,7 +371,7 @@ fn fish_path_directory_in_git_repo_truncate_to_repo_false() -> io::Result<()> {
.paint("~/.t/above-repo/rocket-controls/src/meters/fuel-gauge")
);
assert_eq!(expected, actual);
Ok(())
tmp_dir.close()
}
#[test]
@ -403,7 +403,7 @@ fn fish_path_directory_in_git_repo_truncate_to_repo_true() -> io::Result<()> {
.paint("~/.t/a/rocket-controls/src/meters/fuel-gauge")
);
assert_eq!(expected, actual);
Ok(())
tmp_dir.close()
}
#[test]
@ -434,7 +434,7 @@ fn directory_in_git_repo_truncate_to_repo_true() -> io::Result<()> {
.paint("rocket-controls/src/meters/fuel-gauge")
);
assert_eq!(expected, actual);
Ok(())
tmp_dir.close()
}
#[test]
@ -465,5 +465,5 @@ fn git_repo_in_home_directory_truncate_to_repo_true() -> io::Result<()> {
Color::Cyan.bold().paint("~/src/meters/fuel-gauge")
);
assert_eq!(expected, actual);
Ok(())
tmp_dir.close()
}

View File

@ -8,7 +8,8 @@ use tempfile::{self, TempDir};
#[ignore]
fn shows_nothing_in_directory_with_zero_relevant_files() -> io::Result<()> {
let workspace = create_workspace(false)?;
expect_output(&workspace, ".", None)
expect_output(&workspace, ".", None)?;
workspace.close()
}
#[test]
@ -16,7 +17,8 @@ fn shows_nothing_in_directory_with_zero_relevant_files() -> io::Result<()> {
fn shows_latest_in_directory_with_solution() -> io::Result<()> {
let workspace = create_workspace(false)?;
touch_path(&workspace, "solution.sln", None)?;
expect_output(&workspace, ".", Some("•NET v2.2.402"))
expect_output(&workspace, ".", Some("•NET v2.2.402"))?;
workspace.close()
}
#[test]
@ -24,7 +26,8 @@ fn shows_latest_in_directory_with_solution() -> io::Result<()> {
fn shows_latest_in_directory_with_csproj() -> io::Result<()> {
let workspace = create_workspace(false)?;
touch_path(&workspace, "project.csproj", None)?;
expect_output(&workspace, ".", Some("•NET v2.2.402"))
expect_output(&workspace, ".", Some("•NET v2.2.402"))?;
workspace.close()
}
#[test]
@ -32,7 +35,8 @@ fn shows_latest_in_directory_with_csproj() -> io::Result<()> {
fn shows_latest_in_directory_with_fsproj() -> io::Result<()> {
let workspace = create_workspace(false)?;
touch_path(&workspace, "project.fsproj", None)?;
expect_output(&workspace, ".", Some("•NET v2.2.402"))
expect_output(&workspace, ".", Some("•NET v2.2.402"))?;
workspace.close()
}
#[test]
@ -40,7 +44,8 @@ fn shows_latest_in_directory_with_fsproj() -> io::Result<()> {
fn shows_latest_in_directory_with_xproj() -> io::Result<()> {
let workspace = create_workspace(false)?;
touch_path(&workspace, "project.xproj", None)?;
expect_output(&workspace, ".", Some("•NET v2.2.402"))
expect_output(&workspace, ".", Some("•NET v2.2.402"))?;
workspace.close()
}
#[test]
@ -48,7 +53,8 @@ fn shows_latest_in_directory_with_xproj() -> io::Result<()> {
fn shows_latest_in_directory_with_project_json() -> io::Result<()> {
let workspace = create_workspace(false)?;
touch_path(&workspace, "project.json", None)?;
expect_output(&workspace, ".", Some("•NET v2.2.402"))
expect_output(&workspace, ".", Some("•NET v2.2.402"))?;
workspace.close()
}
#[test]
@ -57,7 +63,8 @@ fn shows_pinned_in_directory_with_global_json() -> io::Result<()> {
let workspace = create_workspace(false)?;
let global_json = make_pinned_sdk_json("1.2.3");
touch_path(&workspace, "global.json", Some(&global_json))?;
expect_output(&workspace, ".", Some("•NET v1.2.3"))
expect_output(&workspace, ".", Some("•NET v1.2.3"))?;
workspace.close()
}
#[test]
@ -67,7 +74,8 @@ fn shows_pinned_in_project_below_root_with_global_json() -> io::Result<()> {
let global_json = make_pinned_sdk_json("1.2.3");
touch_path(&workspace, "global.json", Some(&global_json))?;
touch_path(&workspace, "project/project.csproj", None)?;
expect_output(&workspace, "project", Some("•NET v1.2.3"))
expect_output(&workspace, "project", Some("•NET v1.2.3"))?;
workspace.close()
}
#[test]
@ -77,7 +85,8 @@ fn shows_pinned_in_deeply_nested_project_within_repository() -> io::Result<()> {
let global_json = make_pinned_sdk_json("1.2.3");
touch_path(&workspace, "global.json", Some(&global_json))?;
touch_path(&workspace, "deep/path/to/project/project.csproj", None)?;
expect_output(&workspace, "deep/path/to/project", Some("•NET v1.2.3"))
expect_output(&workspace, "deep/path/to/project", Some("•NET v1.2.3"))?;
workspace.close()
}
fn create_workspace(is_repo: bool) -> io::Result<TempDir> {

View File

@ -1,4 +1,5 @@
use ansi_term::Color;
use remove_dir_all::remove_dir_all;
use std::io;
use std::process::Command;
@ -124,7 +125,7 @@ fn test_truncate_length_with_config(
.unwrap(),
)
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
@ -135,5 +136,5 @@ fn test_truncate_length_with_config(
.paint(format!("\u{e0a0} {}{}", expected_name, truncation_symbol)),
);
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}

View File

@ -1,4 +1,5 @@
use ansi_term::Color;
use remove_dir_all::remove_dir_all;
use std::process::Command;
use std::{io, str};
@ -22,7 +23,7 @@ fn test_render_commit_hash() -> io::Result<()> {
only_detached = false
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
@ -32,7 +33,7 @@ fn test_render_commit_hash() -> io::Result<()> {
.to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -54,7 +55,7 @@ fn test_render_commit_hash_len_override() -> io::Result<()> {
commit_hash_length = 14
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
@ -64,7 +65,7 @@ fn test_render_commit_hash_len_override() -> io::Result<()> {
.to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -73,13 +74,13 @@ fn test_render_commit_hash_only_detached_on_branch() -> io::Result<()> {
let output = common::render_module("git_commit")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!("", actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -101,7 +102,7 @@ fn test_render_commit_hash_only_detached_on_detached() -> io::Result<()> {
let output = common::render_module("git_commit")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
@ -112,5 +113,5 @@ fn test_render_commit_hash_only_detached_on_detached() -> io::Result<()> {
.to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}

View File

@ -1,4 +1,5 @@
use ansi_term::{ANSIStrings, Color};
use remove_dir_all::remove_dir_all;
use std::fs::{self, File};
use std::io;
use std::path::PathBuf;
@ -27,14 +28,14 @@ fn shows_behind() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -50,14 +51,14 @@ fn shows_behind_with_count() -> io::Result<()> {
show_sync_count = true
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "⇣1")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -70,14 +71,14 @@ fn shows_ahead() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -94,14 +95,14 @@ fn shows_ahead_with_count() -> io::Result<()> {
show_sync_count = true
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "⇡1")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -113,14 +114,14 @@ fn shows_diverged() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -136,7 +137,7 @@ fn shows_diverged_with_count() -> io::Result<()> {
show_sync_count = true
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red
@ -146,7 +147,7 @@ fn shows_diverged_with_count() -> io::Result<()> {
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -158,14 +159,14 @@ fn shows_conflicted() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "=")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -181,14 +182,14 @@ fn shows_conflicted_with_count() -> io::Result<()> {
conflicted_count.enabled = true
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "=1")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -200,14 +201,14 @@ fn shows_untracked_file() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "?")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -223,14 +224,14 @@ fn shows_untracked_file_with_count() -> io::Result<()> {
untracked_count.enabled = true
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "?1")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -248,14 +249,14 @@ fn doesnt_show_untracked_file_if_disabled() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = "";
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -274,14 +275,14 @@ fn shows_stashed() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "$")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -304,14 +305,13 @@ fn shows_stashed_with_count() -> io::Result<()> {
stashed_count.enabled = true
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "$1")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -323,14 +323,13 @@ fn shows_modified() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "!")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -346,14 +345,14 @@ fn shows_modified_with_count() -> io::Result<()> {
modified_count.enabled = true
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "!1")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -365,14 +364,14 @@ fn shows_staged_file() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "+")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -389,7 +388,7 @@ fn shows_staged_file_with_count() -> io::Result<()> {
staged_count.style = "green"
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = format!(
@ -403,7 +402,7 @@ fn shows_staged_file_with_count() -> io::Result<()> {
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -415,14 +414,14 @@ fn shows_renamed_file() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "»")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -438,14 +437,14 @@ fn shows_renamed_file_with_count() -> io::Result<()> {
renamed_count.enabled = true
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "»1")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -457,14 +456,14 @@ fn shows_deleted_file() -> io::Result<()> {
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -480,14 +479,14 @@ fn shows_deleted_file_with_count() -> io::Result<()> {
deleted_count.enabled = true
})
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = Color::Red.bold().paint(format!("[{}] ", "✘1")).to_string();
assert_eq!(expected, actual);
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -497,7 +496,7 @@ fn prefix() -> io::Result<()> {
File::create(repo_dir.join("prefix"))?.sync_all()?;
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.env_clear()
.use_config(toml::toml! {
[git_status]
@ -508,7 +507,7 @@ fn prefix() -> io::Result<()> {
let actual = String::from_utf8(output.stdout).unwrap();
let expected = "(";
assert!(actual.starts_with(&expected));
Ok(())
remove_dir_all(repo_dir)
}
#[test]
@ -518,7 +517,7 @@ fn suffix() -> io::Result<()> {
File::create(repo_dir.join("suffix"))?.sync_all()?;
let output = common::render_module("git_status")
.arg("--path")
.arg(repo_dir)
.arg(&repo_dir)
.env_clear()
.use_config(toml::toml! {
[git_status]
@ -529,7 +528,7 @@ fn suffix() -> io::Result<()> {
let actual = String::from_utf8(output.stdout).unwrap();
let expected = ")";
assert!(actual.ends_with(&expected));
Ok(())
remove_dir_all(repo_dir)
}
fn ahead(repo_dir: &PathBuf) -> io::Result<()> {

View File

@ -30,14 +30,16 @@ fn test_hg_get_branch_fails() -> io::Result<()> {
tempdir.path(),
"",
&[Expect::BranchName(&"default"), Expect::NoTruncation],
)
)?;
tempdir.close()
}
#[test]
#[ignore]
fn test_hg_get_branch_autodisabled() -> io::Result<()> {
let tempdir = tempfile::tempdir()?;
expect_hg_branch_with_config(tempdir.path(), "", &[Expect::Empty])
expect_hg_branch_with_config(tempdir.path(), "", &[Expect::Empty])?;
tempdir.close()
}
#[test]
@ -50,7 +52,8 @@ fn test_hg_bookmark() -> io::Result<()> {
&repo_dir,
"",
&[Expect::BranchName(&"bookmark-101"), Expect::NoTruncation],
)
)?;
tempdir.close()
}
#[test]
@ -73,7 +76,8 @@ fn test_default_truncation_symbol() -> io::Result<()> {
&repo_dir,
"truncation_length = 14",
&[Expect::BranchName(&"branch-name-10")],
)
)?;
tempdir.close()
}
#[test]
@ -104,7 +108,8 @@ fn test_configured_symbols() -> io::Result<()> {
Expect::Symbol(&"B"),
Expect::TruncationSymbol(&"%"),
],
)
)?;
tempdir.close()
}
#[test]
@ -134,7 +139,8 @@ fn test_configured_style() -> io::Result<()> {
Expect::Style(Color::Blue.underline()),
Expect::TruncationSymbol(&""),
],
)
)?;
tempdir.close()
}
fn expect_hg_branch_with_config(

View File

@ -20,7 +20,7 @@ fn folder_with_python_version() -> io::Result<()> {
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -37,7 +37,7 @@ fn folder_with_requirements_txt() -> io::Result<()> {
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -54,7 +54,7 @@ fn folder_with_pyproject_toml() -> io::Result<()> {
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -71,7 +71,7 @@ fn folder_with_pipfile() -> io::Result<()> {
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -88,7 +88,7 @@ fn folder_with_tox() -> io::Result<()> {
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -105,7 +105,7 @@ fn folder_with_py_file() -> io::Result<()> {
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -122,7 +122,7 @@ fn with_virtual_env() -> io::Result<()> {
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6 (my_venv)"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -139,5 +139,5 @@ fn with_active_venv() -> io::Result<()> {
let expected = format!("via {} ", Color::Yellow.bold().paint("🐍 v3.7.6 (my_venv)"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}

View File

@ -18,7 +18,7 @@ fn folder_without_dotterraform() -> io::Result<()> {
let expected = "";
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -35,7 +35,7 @@ fn folder_with_tf_file() -> io::Result<()> {
let expected = format!("via {} ", Color::Fixed(105).bold().paint("💠 default"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -54,7 +54,7 @@ fn folder_with_workspace_override() -> io::Result<()> {
let expected = format!("via {} ", Color::Fixed(105).bold().paint("💠 development"));
assert_eq!(expected, actual);
Ok(())
dir.close()
}
#[test]
@ -78,7 +78,8 @@ fn folder_with_datadir_override() -> io::Result<()> {
let expected = format!("via {} ", Color::Fixed(105).bold().paint("💠 development"));
assert_eq!(expected, actual);
Ok(())
dir.close()?;
datadir.close()
}
#[test]