Skip to content

Commit

Permalink
Added tests for parsing args
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Nov 19, 2024
1 parent 6048d29 commit ded80ee
Showing 1 changed file with 85 additions and 1 deletion.
86 changes: 85 additions & 1 deletion crates/turborepo-lib/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ mod test {
use itertools::Itertools;
use pretty_assertions::assert_eq;

use crate::cli::{ExecutionArgs, RunArgs};
use crate::cli::{ExecutionArgs, LinkTarget, RunArgs};

struct CommandTestCase {
command: &'static str,
Expand Down Expand Up @@ -2313,6 +2313,90 @@ mod test {
.test();
}

#[test]
fn test_parse_link() {
assert_eq!(
Args::try_parse_from(["turbo", "link"]).unwrap(),
Args {
command: Some(Command::Link {
no_gitignore: false,
scope: None,
yes: false,
target: LinkTarget::RemoteCache,
}),
..Args::default()
}
);

CommandTestCase {
command: "link",
command_args: vec![],
global_args: vec![vec!["--cwd", "../examples/with-yarn"]],
expected_output: Args {
command: Some(Command::Link {
no_gitignore: false,
scope: None,
yes: false,
target: LinkTarget::RemoteCache,
}),
cwd: Some(Utf8PathBuf::from("../examples/with-yarn")),
..Args::default()
},
}
.test();

CommandTestCase {
command: "link",
command_args: vec![vec!["--yes"]],
global_args: vec![vec!["--cwd", "../examples/with-yarn"]],
expected_output: Args {
command: Some(Command::Link {
yes: true,
no_gitignore: false,
scope: None,
target: LinkTarget::RemoteCache,
}),
cwd: Some(Utf8PathBuf::from("../examples/with-yarn")),
..Args::default()
},
}
.test();

CommandTestCase {
command: "link",
command_args: vec![vec!["--scope", "foo"]],
global_args: vec![vec!["--cwd", "../examples/with-yarn"]],
expected_output: Args {
command: Some(Command::Link {
yes: false,
no_gitignore: false,
scope: Some("foo".to_string()),
target: LinkTarget::RemoteCache,
}),
cwd: Some(Utf8PathBuf::from("../examples/with-yarn")),
..Args::default()
},
}
.test();

CommandTestCase {
command: "link",
command_args: vec![vec!["--no-gitignore"]],
global_args: vec![vec!["--cwd", "../examples/with-yarn"]],
expected_output: Args {
command: Some(Command::Link {
yes: false,
no_gitignore: true,
scope: None,
target: LinkTarget::RemoteCache,
}),
cwd: Some(Utf8PathBuf::from("../examples/with-yarn")),
..Args::default()
},
}
.test();
}

#[test]
fn test_parse_login() {
assert_eq!(
Expand Down

0 comments on commit ded80ee

Please sign in to comment.