Skip to content

Commit 39bd990

Browse files
committed
Make but tests work in non-legacy mode and the capability to CI
This allows us to validate the non-legacy mode as well.
1 parent b5bf904 commit 39bd990

File tree

9 files changed

+136
-19
lines changed

9 files changed

+136
-19
lines changed

.github/workflows/push.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ jobs:
184184
env:
185185
GITBUTLER_TESTS_NO_CLEANUP: '1'
186186
name: cargo test
187+
# It's intentional to use 'name equals run-script' so it's easy to re-run locally on failure.
188+
- run: cargo test -p but --no-default-features
187189

188190
rust-test-tauri:
189191
needs: changes

Cargo.lock

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

crates/but-clap/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,3 @@ doctest = false
1919
but.workspace = true
2020
clap.workspace = true
2121
anyhow.workspace = true
22-
23-
[dev-dependencies]
24-
snapbox.workspace = true

crates/but/src/args/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ fn clap() {
77
}
88

99
mod push {
10+
#[cfg(feature = "legacy")]
1011
mod get_gerrit_flags {
1112
use crate::args::push::Command as Args;
1213
use crate::command::legacy::push::get_gerrit_flags;
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use snapbox::str;
2-
31
use crate::utils::Sandbox;
42

53
#[test]
@@ -13,26 +11,31 @@ fn json_flag_can_be_placed_before_or_after_subcommand() -> anyhow::Result<()> {
1311

1412
env.but("completions --help --json").assert().success();
1513

16-
// Test with actual commands that need a repo (they'll fail but should accept the flag)
17-
// Before subcommand
18-
env.but("--json status")
19-
.env_remove("BUT_OUTPUT_FORMAT")
20-
.assert()
21-
.failure()
22-
.stderr_eq(str![[r#"
14+
// Without legacy
15+
#[cfg(feature = "legacy")]
16+
{
17+
use snapbox::str;
18+
// Test with actual commands that need a repo (they'll fail but should accept the flag)
19+
// Before subcommand
20+
env.but("--json status")
21+
.env_remove("BUT_OUTPUT_FORMAT")
22+
.assert()
23+
.failure()
24+
.stderr_eq(str![[r#"
2325
Error: Could not find a git repository in '.' or in any of its parents[..]
2426
2527
"#]]);
2628

27-
// After subcommand
28-
env.but("status --json")
29-
.env_remove("BUT_OUTPUT_FORMAT")
30-
.assert()
31-
.failure()
32-
.stderr_eq(str![[r#"
29+
// After subcommand
30+
env.but("status --json")
31+
.env_remove("BUT_OUTPUT_FORMAT")
32+
.assert()
33+
.failure()
34+
.stderr_eq(str![[r#"
3335
Error: Could not find a git repository in '.' or in any of its parents[..]
3436
3537
"#]]);
38+
}
3639

3740
Ok(())
3841
}

crates/but/tests/but/command/help.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
use crate::utils::Sandbox;
22

3+
#[cfg(not(feature = "legacy"))]
4+
#[test]
5+
fn looks_good_and_can_be_invoked_in_various_ways_non_legacy() -> anyhow::Result<()> {
6+
let env = Sandbox::empty()?;
7+
env.but(None).assert().success().stdout_eq(snapbox::file![
8+
"snapshots/help/no-arg-no-legacy.stdout.term.svg"
9+
]);
10+
Ok(())
11+
}
12+
13+
#[cfg(feature = "legacy")]
314
#[test]
415
fn looks_good_and_can_be_invoked_in_various_ways() -> anyhow::Result<()> {
516
let env = Sandbox::empty()?;
@@ -21,6 +32,7 @@ fn looks_good_and_can_be_invoked_in_various_ways() -> anyhow::Result<()> {
2132
Ok(())
2233
}
2334

35+
#[cfg(feature = "legacy")]
2436
#[test]
2537
fn rub_looks_good() -> anyhow::Result<()> {
2638
let env = Sandbox::empty()?;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
//! Put command-specific tests here. They should be focused on what's important for each command.
22
//! Ideally they *show* the initial state, and the *post* state, to validate the commands actually do what they claim.
3+
#[cfg(feature = "legacy")]
34
mod branch;
5+
#[cfg(feature = "legacy")]
46
mod commit;
57
mod format;
68
mod help;
9+
#[cfg(feature = "legacy")]
710
mod rub;
11+
#[cfg(feature = "legacy")]
812
mod status;
Lines changed: 96 additions & 0 deletions
Loading

crates/but/tests/but/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
mod command;
2+
// TODO: Id tests can be on integration level, but shouldn't involve the CLI
3+
#[cfg(feature = "legacy")]
24
mod id;
5+
#[cfg(feature = "legacy")]
36
mod journey;
47
pub mod utils;

0 commit comments

Comments
 (0)