From 56d475578ea508631275772127f49a6949fea6b0 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Sun, 15 Mar 2020 18:12:25 +0100 Subject: [PATCH] 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 --- CONTRIBUTING.md | 8 +++ Cargo.lock | 1 + Cargo.toml | 4 ++ src/context.rs | 4 ++ src/modules/crystal.rs | 9 ++-- src/modules/elixir.rs | 4 +- src/modules/elm.rs | 10 ++-- src/modules/golang.rs | 16 +++--- src/modules/haskell.rs | 8 +-- src/modules/nodejs.rs | 8 +-- src/modules/php.rs | 6 +-- src/modules/ruby.rs | 6 +-- tests/testsuite/aws.rs | 4 +- tests/testsuite/common.rs | 7 ++- tests/testsuite/directory.rs | 16 +++--- tests/testsuite/dotnet.rs | 27 ++++++---- tests/testsuite/git_branch.rs | 5 +- tests/testsuite/git_commit.rs | 17 ++++--- tests/testsuite/git_status.rs | 95 +++++++++++++++++------------------ tests/testsuite/hg_branch.rs | 18 ++++--- tests/testsuite/python.rs | 16 +++--- tests/testsuite/terraform.rs | 9 ++-- 22 files changed, 169 insertions(+), 129 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4fa8af11..69b74320 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. diff --git a/Cargo.lock b/Cargo.lock index 3dde5f51..efeb5d47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", diff --git a/Cargo.toml b/Cargo.toml index 5f49645e..c08e2880 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/context.rs b/src/context.rs index b8cea191..11cc911d 100644 --- a/src/context.rs +++ b/src/context.rs @@ -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(()) } diff --git a/src/modules/crystal.rs b/src/modules/crystal.rs index a215369c..2243514c 100644 --- a/src/modules/crystal.rs +++ b/src/modules/crystal.rs @@ -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() } } diff --git a/src/modules/elixir.rs b/src/modules/elixir.rs index d68d11d6..3ef1c984 100644 --- a/src/modules/elixir.rs +++ b/src/modules/elixir.rs @@ -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() } } diff --git a/src/modules/elm.rs b/src/modules/elm.rs index 2acc87ac..8cfadfaa 100644 --- a/src/modules/elm.rs +++ b/src/modules/elm.rs @@ -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() } } diff --git a/src/modules/golang.rs b/src/modules/golang.rs index 2f3cb27d..4bfc17c6 100644 --- a/src/modules/golang.rs +++ b/src/modules/golang.rs @@ -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] diff --git a/src/modules/haskell.rs b/src/modules/haskell.rs index 7324cc9c..7b28d56a 100644 --- a/src/modules/haskell.rs +++ b/src/modules/haskell.rs @@ -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() } } diff --git a/src/modules/nodejs.rs b/src/modules/nodejs.rs index 7fec383f..d78ea523 100644 --- a/src/modules/nodejs.rs +++ b/src/modules/nodejs.rs @@ -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() } } diff --git a/src/modules/php.rs b/src/modules/php.rs index 61e464e4..878cdb2a 100644 --- a/src/modules/php.rs +++ b/src/modules/php.rs @@ -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() } } diff --git a/src/modules/ruby.rs b/src/modules/ruby.rs index de367098..f50e8025 100644 --- a/src/modules/ruby.rs +++ b/src/modules/ruby.rs @@ -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] diff --git a/tests/testsuite/aws.rs b/tests/testsuite/aws.rs index d4d57335..01f518f8 100644 --- a/tests/testsuite/aws.rs +++ b/tests/testsuite/aws.rs @@ -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] diff --git a/tests/testsuite/common.rs b/tests/testsuite/common.rs index c7b6c680..379edd23 100644 --- a/tests/testsuite/common.rs +++ b/tests/testsuite/common.rs @@ -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 { - 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 { .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"]) diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index 2ead974e..e30e3d53 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -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() } diff --git a/tests/testsuite/dotnet.rs b/tests/testsuite/dotnet.rs index fa53d257..fe6991ad 100644 --- a/tests/testsuite/dotnet.rs +++ b/tests/testsuite/dotnet.rs @@ -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 { diff --git a/tests/testsuite/git_branch.rs b/tests/testsuite/git_branch.rs index 76cd08ba..7fa5aaae 100644 --- a/tests/testsuite/git_branch.rs +++ b/tests/testsuite/git_branch.rs @@ -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) } diff --git a/tests/testsuite/git_commit.rs b/tests/testsuite/git_commit.rs index fdae075a..d7ae8e77 100644 --- a/tests/testsuite/git_commit.rs +++ b/tests/testsuite/git_commit.rs @@ -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) } diff --git a/tests/testsuite/git_status.rs b/tests/testsuite/git_status.rs index d1ecf085..58bba46e 100644 --- a/tests/testsuite/git_status.rs +++ b/tests/testsuite/git_status.rs @@ -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<()> { diff --git a/tests/testsuite/hg_branch.rs b/tests/testsuite/hg_branch.rs index dc54b620..df600b69 100644 --- a/tests/testsuite/hg_branch.rs +++ b/tests/testsuite/hg_branch.rs @@ -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( diff --git a/tests/testsuite/python.rs b/tests/testsuite/python.rs index 38e54a69..bc106700 100644 --- a/tests/testsuite/python.rs +++ b/tests/testsuite/python.rs @@ -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() } diff --git a/tests/testsuite/terraform.rs b/tests/testsuite/terraform.rs index ef6d16b5..2d35ab79 100644 --- a/tests/testsuite/terraform.rs +++ b/tests/testsuite/terraform.rs @@ -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]