Skip to content

Commit ef25cb1

Browse files
authored
test: clean cwd in unit tests (#2211)
1 parent 2a4b986 commit ef25cb1

File tree

12 files changed

+34
-20
lines changed

12 files changed

+34
-20
lines changed

src/cli/env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ mod tests {
7272
use std::env;
7373

7474
use pretty_assertions::assert_str_eq;
75+
use test_log::test;
7576

7677
use crate::cli::tests::grep;
7778
use crate::dirs;

src/cli/plugins/ls_remote.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ Examples:
6767

6868
#[cfg(test)]
6969
mod tests {
70+
use test_log::test;
71+
72+
use crate::test::reset;
73+
7074
#[test]
7175
fn test_plugin_list_remote() {
76+
reset();
7277
let stdout = assert_cli!("plugin", "ls-remote");
7378
assert!(stdout.contains("tiny"));
7479
}

src/file.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ pub fn is_executable(path: &Path) -> bool {
269269
}
270270

271271
#[cfg(unix)]
272-
pub fn make_executable(path: &Path) -> Result<()> {
272+
pub fn make_executable<P: AsRef<Path>>(path: P) -> Result<()> {
273+
let path = path.as_ref();
273274
let mut perms = path.metadata()?.permissions();
274275
perms.set_mode(perms.mode() | 0o111);
275276
fs::set_permissions(path, perms)

src/plugins/core/bun.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl BunPlugin {
8787
.join("bun"),
8888
self.bun_bin(&ctx.tv),
8989
)?;
90-
file::make_executable(&self.bun_bin(&ctx.tv))?;
90+
file::make_executable(self.bun_bin(&ctx.tv))?;
9191
file::make_symlink(Path::new("./bun"), &ctx.tv.install_path().join("bin/bunx"))?;
9292
Ok(())
9393
}

src/plugins/core/deno.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl DenoPlugin {
8787
file::create_dir_all(tv.install_path().join("bin"))?;
8888
file::unzip(tarball_path, &tv.download_path())?;
8989
file::rename(tv.download_path().join("deno"), self.deno_bin(tv))?;
90-
file::make_executable(&self.deno_bin(tv))?;
90+
file::make_executable(self.deno_bin(tv))?;
9191
Ok(())
9292
}
9393

src/plugins/core/erlang.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl ErlangPlugin {
6666
&self.kerl_path(),
6767
None,
6868
)?;
69-
file::make_executable(&self.kerl_path())?;
69+
file::make_executable(self.kerl_path())?;
7070
Ok(())
7171
}
7272

src/plugins/core/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl NodePlugin {
193193
fn install_npm_shim(&self, tv: &ToolVersion) -> Result<()> {
194194
file::remove_file(self.npm_path(tv)).ok();
195195
file::write(self.npm_path(tv), include_str!("assets/node_npm_shim"))?;
196-
file::make_executable(&self.npm_path(tv))?;
196+
file::make_executable(self.npm_path(tv))?;
197197
Ok(())
198198
}
199199

src/test.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,31 @@ pub fn reset() {
7676
Config::reset();
7777
forge::reset();
7878
config_file::reset();
79+
file::remove_all(&*env::HOME.join("cwd")).unwrap();
80+
file::create_dir_all(&*env::HOME.join("cwd")).unwrap();
7981
env::set_current_dir(env::HOME.join("cwd")).unwrap();
8082
env::remove_var("MISE_FAILURE");
8183
file::remove_all(&*dirs::TRUSTED_CONFIGS).unwrap();
8284
file::remove_all(&*dirs::TRACKED_CONFIGS).unwrap();
85+
file::create_dir_all(".mise/tasks").unwrap();
86+
file::write(
87+
".mise/tasks/filetask",
88+
indoc! {r#"#!/usr/bin/env bash
89+
# mise alias=["ft"]
90+
# mise description="This is a test build script"
91+
# mise depends=["lint", "test"]
92+
# mise sources=[".test-tool-versions"]
93+
# mise outputs=["$MISE_PROJECT_ROOT/test/test-build-output.txt"]
94+
# mise env={TEST_BUILDSCRIPT_ENV_VAR = "VALID"}
95+
96+
set -euxo pipefail
97+
cd "$MISE_PROJECT_ROOT" || exit 1
98+
echo "running test-build script"
99+
echo "TEST_BUILDSCRIPT_ENV_VAR: $TEST_BUILDSCRIPT_ENV_VAR" > test-build-output.txt
100+
"#},
101+
)
102+
.unwrap();
103+
file::make_executable(".mise/tasks/filetask").unwrap();
83104
file::write(
84105
env::HOME.join(".test-tool-versions"),
85106
indoc! {r#"

test/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ data/
22
!data/plugins
33
cache/
44
state/
5-
cwd/man/
5+
cwd/
66
test-build-output.txt

test/cwd/.mise/tasks/filetask

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/cwd/.test-tool-versions

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/cwd/tiny-legacy/.mise-tiny-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)