Skip to content

Commit

Permalink
test: migrate tests from unit to e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 27, 2024
1 parent f246584 commit 0a2612c
Show file tree
Hide file tree
Showing 94 changed files with 48 additions and 1,708 deletions.
2 changes: 1 addition & 1 deletion docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Answer yes to all confirmation prompts
- [`mise sync <SUBCOMMAND>`](/cli/sync.md)
- [`mise sync node [FLAGS]`](/cli/sync/node.md)
- [`mise sync python <--pyenv>`](/cli/sync/python.md)
- [`mise tasks [FLAGS] <SUBCOMMAND>`](/cli/tasks.md)
- [`mise tasks [FLAGS] [TASK] <SUBCOMMAND>`](/cli/tasks.md)
- [`mise tasks deps [--hidden] [--dot] [TASKS]...`](/cli/tasks/deps.md)
- [`mise tasks edit [-p --path] <TASK>`](/cli/tasks/edit.md)
- [`mise tasks info [-J --json] <TASK>`](/cli/tasks/info.md)
Expand Down
8 changes: 7 additions & 1 deletion docs/cli/tasks.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# `mise tasks`

- **Usage**: `mise tasks [FLAGS] <SUBCOMMAND>`
- **Usage**: `mise tasks [FLAGS] [TASK] <SUBCOMMAND>`
- **Aliases**: `t`
- **Source code**: [`src/cli/tasks.rs`](https://github.com/jdx/mise/blob/main/src/cli/tasks.rs)

Manage tasks

## Arguments

### `[TASK]`

Task name to get info of

## Flags

### `--no-header`
Expand Down
3 changes: 3 additions & 0 deletions e2e/cli/test_backends
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

assert_contains "mise backends" "cargo"
13 changes: 13 additions & 0 deletions e2e/tasks/test_task_deps
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,16 @@ depends = ["hello:*"]
EOF
assert_contains "mise run hello:all" "[hello:1] Hello from 1"
assert_contains "mise run hello:all" "[hello:2] Hello from 2"
assert "mise task deps" "hello:1
hello:2
hello:all
├── hello:2
└── hello:1"
assert "mise task hello:all" 'Task: hello:all
Description: Hello from all
Source: ~/workdir/mise.toml
Depends on: hello:*
Usage Spec:
name "hello:all"
bin "hello:all"'
1 change: 1 addition & 0 deletions mise.usage.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,7 @@ cmd "tasks" help="Manage tasks" {
}
flag "-J --json" help="Output in JSON format"
flag "--usage" hide=true
arg "[TASK]" help="Task name to get info of"
cmd "deps" help="Display a tree visualization of a dependency graph" {
after_long_help r#"Examples:

Expand Down
28 changes: 0 additions & 28 deletions src/cli/alias/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,3 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
20.0.0
"#
);

#[cfg(test)]
mod tests {
use insta::assert_snapshot;

use crate::test::reset;

#[test]
fn test_alias_get() {
reset();
let stdout = assert_cli!("alias", "get", "tiny", "my/alias");
assert_snapshot!(stdout, @"3.0");
}

#[test]
fn test_alias_get_plugin_unknown() {
reset();
let err = assert_cli_err!("alias", "get", "unknown", "unknown");
assert_snapshot!(err, @"Unknown plugin: unknown");
}

#[test]
fn test_alias_get_alias_unknown() {
reset();
let err = assert_cli_err!("alias", "get", "tiny", "unknown");
assert_snapshot!(err, @"Unknown alias: unknown");
}
}
28 changes: 0 additions & 28 deletions src/cli/asdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,31 +68,3 @@ fn list_versions(config: &Config, args: &[String]) -> Result<()> {

Ok(())
}

#[cfg(test)]
mod tests {
use insta::assert_snapshot;

use crate::test::reset;

#[test]
fn test_fake_asdf_other() {
reset();
assert_cli!("uninstall", "--all", "tiny");
assert_cli!("install", "tiny@3.1.0");
assert_cli_snapshot!("asdf", "current", "tiny", @"3.1.0");
}

#[test]
fn test_fake_asdf_reshim() {
reset();
assert_cli_snapshot!("asdf", "reshim");
}

#[test]
fn test_fake_asdf_install() {
reset();
// on alpine this shows a warning, use assert_cli! to just get stdout
assert_snapshot!(assert_cli!("asdf", "install", "tiny"));
}
}
9 changes: 0 additions & 9 deletions src/cli/backends/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,3 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
ubi
"#
);

#[cfg(test)]
mod tests {

#[test]
fn test_backends_list() {
assert_cli_snapshot!("backends", "list");
}
}

This file was deleted.

17 changes: 0 additions & 17 deletions src/cli/cache/clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,3 @@ impl CacheClear {
Ok(())
}
}

#[cfg(test)]
mod tests {
use crate::test::reset;

#[test]
fn test_cache_clear() {
reset();
assert_cli_snapshot!("cache", "clear", @"mise cache cleared");
}

#[test]
fn test_cache_clear_plugin() {
reset();
assert_cli_snapshot!("cache", "clear", "tiny", @"mise cache cleared for tiny");
}
}
15 changes: 0 additions & 15 deletions src/cli/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,3 @@ impl Cache {
}
}
}

#[cfg(test)]
mod tests {
use pretty_assertions::assert_str_eq;

use crate::env;
use crate::test::reset;

#[test]
fn test_cache() {
reset();
let stdout = assert_cli!("cache");
assert_str_eq!(stdout.trim(), env::MISE_CACHE_DIR.display().to_string());
}
}
17 changes: 0 additions & 17 deletions src/cli/cache/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,3 @@ fn bytes_str(bytes: u64) -> String {
NumberPrefix::Prefixed(prefix, n) => format!("{:.1} {}B", n, prefix),
}
}

#[cfg(test)]
mod tests {
use crate::test::reset;

#[test]
fn test_cache_prune() {
reset();
assert_cli!("cache", "prune");
}

#[test]
fn test_cache_prune_plugin() {
reset();
assert_cli!("cache", "prune", "tiny");
}
}
13 changes: 0 additions & 13 deletions src/cli/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,3 @@ impl ValueEnum for Shell {
Some(PossibleValue::new(self.to_string()))
}
}

#[cfg(test)]
mod tests {
use crate::test::reset;

#[test]
fn test_completion() {
reset();
assert_cli!("completion", "zsh");
assert_cli!("completion", "bash");
assert_cli!("completion", "fish");
}
}
17 changes: 0 additions & 17 deletions src/cli/config/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,3 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
$ <bold>mise cf generate --output=mise.toml</bold>
"#
);

#[cfg(test)]
mod tests {
use crate::test::reset;

#[test]
fn test_generate() {
reset();
with_settings!({
let out = assert_cli!("config", "generate");
for line in out.lines() {
assert!(line.len() < 80);
}
assert_cli_snapshot!("cfg", "generate");
});
}
}
12 changes: 0 additions & 12 deletions src/cli/config/get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,3 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
3.12
"#
);

#[cfg(test)]
mod tests {
use crate::test::reset;

#[test]
fn test_toml_get() {
reset();
assert_cli_snapshot!("cfg", "get");
assert_cli_snapshot!("cfg", "get", "env.TEST_ENV_VAR", @"test-123");
}
}
27 changes: 0 additions & 27 deletions src/cli/config/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,3 @@ static AFTER_LONG_HELP: &str = color_print::cstr!(
$ <bold>mise config set settings.jobs 4</bold>
"#
);

#[cfg(test)]
mod tests {
use crate::test::reset;

#[test]
fn test_config_set() {
reset();
assert_cli_snapshot!("config", "set", "env.TEST_ENV_VAR", "ABC", @"");
assert_cli_snapshot!("config", "get", "env.TEST_ENV_VAR", @"ABC");

assert_cli_snapshot!("config", "set", "settings.ruby.default_packages_file", "abc", @"");
assert_cli_snapshot!("config", "get", "settings.ruby.default_packages_file", @"abc");

assert_cli_snapshot!("config", "set", "settings.always_keep_download", "--type", "bool", "true", @"");
assert_cli_snapshot!("config", "get", "settings.always_keep_download", @"true");

assert_cli_snapshot!("config", "set", "settings.jobs", "--type", "integer", "4", @"");
assert_cli_snapshot!("config", "get", "settings.jobs", @"4");

assert_cli_snapshot!("config", "set", "settings.jobs", "4", @"");
assert_cli_snapshot!("config", "get", "settings.jobs", @"4");

assert_cli_snapshot!("config", "set", "settings.disable_tools", "--type", "list", "node,rust", @"");
assert_cli_snapshot!("config", "get", "settings.disable_tools", @r#"["node", "rust"]"#);
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0a2612c

Please sign in to comment.