Skip to content

Commit 0fb9274

Browse files
committed
Add integration tests
1 parent 60f27c2 commit 0fb9274

14 files changed

+103
-79
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[alias]
2-
xtask = "run --release --target-dir target/xtask/release --package xtask --bin xtask --"
2+
xtask = "run --target-dir target/xtask --package xtask --bin xtask --"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
2+
xtask/target
23

34
.DS_Store
45
.vscode

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

_typos.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[files]
2+
extend-exclude = [
3+
"target",
4+
]

xtask/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ edition = "2021"
66
[dependencies]
77
strum = { workspace = true }
88
log = { workspace = true }
9-
tracel-xtask = { path = "../crates/tracel-xtask" }
9+
tracel-xtask = { path = "../crates/tracel-xtask" }
10+
rstest.workspace = true
11+
12+
[dev-dependencies]
13+
rstest = { workspace = true }

xtask/src/commands/build.rs

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

xtask/src/commands/extended_build_args.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ pub struct ExtendedBuildArgsCmdArgs {
99

1010
pub fn handle_command(args: ExtendedBuildArgsCmdArgs) -> anyhow::Result<()> {
1111
if args.debug {
12-
println!("Debug is enabled");
12+
println!("debug enabled");
13+
} else {
14+
println!("debug disabled");
1315
}
1416
base_commands::build::handle_command(args.try_into().unwrap())
1517
}

xtask/src/commands/extended_check_sub_commands.rs

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,41 @@ use strum::IntoEnumIterator;
44
use tracel_xtask::prelude::*;
55

66
#[macros::extend_command_args(CheckCmdArgs, Target, ExtendedCheckSubcommand)]
7-
pub struct ExtendedCheckedArgsCmdArgs {}
7+
pub struct ExtendedCheckArgsCmdArgs {}
88

99
#[macros::extend_subcommands(CheckSubCommand)]
1010
pub enum ExtendedCheckSubcommand {
1111
/// An additional subcommand for our extended Fix command.
12-
MySubcommand,
12+
MySubCommand,
1313
}
1414

15-
pub fn handle_command(args: ExtendedCheckedArgsCmdArgs) -> anyhow::Result<()> {
15+
pub fn handle_command(args: ExtendedCheckArgsCmdArgs) -> anyhow::Result<()> {
1616
match args.get_command() {
17-
ExtendedCheckSubcommand::MySubcommand => run_my_subcommand(args.clone()),
18-
ExtendedCheckSubcommand::All => ExtendedCheckSubcommand::iter()
19-
.filter(|c| *c != ExtendedCheckSubcommand::All)
20-
.try_for_each(|c| {
21-
handle_command(ExtendedCheckedArgsCmdArgs {
22-
command: Some(c),
23-
target: args.target.clone(),
24-
exclude: args.exclude.clone(),
25-
only: args.only.clone(),
17+
ExtendedCheckSubcommand::MySubCommand => run_my_subcommand(args.clone()),
18+
ExtendedCheckSubcommand::All => {
19+
println!("Executing all");
20+
ExtendedCheckSubcommand::iter()
21+
.filter(|c| *c != ExtendedCheckSubcommand::All)
22+
.try_for_each(|c| {
23+
handle_command(ExtendedCheckArgsCmdArgs {
24+
command: Some(c),
25+
target: args.target.clone(),
26+
exclude: args.exclude.clone(),
27+
only: args.only.clone(),
28+
})
2629
})
27-
}),
28-
_ => base_commands::check::handle_command(args.try_into().unwrap()),
30+
}
31+
command => {
32+
println!("Executing {command}");
33+
// this should be uncommented but we skip the actual execution here because we use
34+
// this command in the integration test as well.
35+
// base_commands::check::handle_command(args.try_into().unwrap())
36+
Ok(())
37+
}
2938
}
3039
}
3140

32-
fn run_my_subcommand(_args: ExtendedCheckedArgsCmdArgs) -> Result<(), anyhow::Error> {
41+
fn run_my_subcommand(_args: ExtendedCheckArgsCmdArgs) -> Result<(), anyhow::Error> {
3342
println!("Executing new subcommand");
3443
Ok(())
3544
}

xtask/src/commands/fix.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct ExtendedFixCmdArgs {}
1818
#[macros::extend_subcommands(FixSubCommand)]
1919
pub enum ExtendedFixSubCommand {
2020
/// An additional subcommand for our extended Fix command.
21-
NewSubcommand(NewSubcommandArgs),
21+
NewSubCommand(NewSubcommandArgs),
2222
}
2323

2424
// We can add custom arguments for our 'new-subcommand' subcommand as well
@@ -30,10 +30,13 @@ pub struct NewSubcommandArgs {
3030
}
3131

3232
// Handle function processing the extended command arguments struct with extended subcommands
33-
pub fn handle_command(args: ExtendedFixCmdArgs, answer: Option<bool>) -> anyhow::Result<()> {
33+
#[allow(unused_assignments)]
34+
pub fn handle_command(args: ExtendedFixCmdArgs, mut answer: Option<bool>) -> anyhow::Result<()> {
35+
// force the ansert to yes for the integration tests
36+
answer = Some(true);
3437
// we need to handle both the new subcommand 'new-subcommand' and the 'all' subcommand
3538
match args.get_command() {
36-
ExtendedFixSubCommand::NewSubcommand(ref subcmd_args) => {
39+
ExtendedFixSubCommand::NewSubCommand(ref subcmd_args) => {
3740
run_new_subcommand_fix(args.clone(), subcmd_args, answer)
3841
}
3942
ExtendedFixSubCommand::All => {
@@ -52,7 +55,12 @@ pub fn handle_command(args: ExtendedFixCmdArgs, answer: Option<bool>) -> anyhow:
5255
)
5356
})
5457
}
55-
_ => base_commands::fix::handle_command(args.try_into().unwrap(), answer),
58+
_ => {
59+
// this should be uncommented but we skip the actual execution here because we use
60+
// this command in the integration test as well.
61+
// base_commands::fix::handle_command(args.try_into().unwrap(), answer),
62+
Ok(())
63+
}
5664
}
5765
}
5866

xtask/src/commands/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
pub(crate) mod build;
21
pub(crate) mod extended_build_args;
32
pub(crate) mod extended_build_new_sub_commands;
43
pub(crate) mod extended_check_sub_commands;

0 commit comments

Comments
 (0)