Skip to content

Commit 65b122c

Browse files
committed
Dummy commit.
1 parent d32cf3e commit 65b122c

17 files changed

+66
-18
lines changed

tests/cli.rs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,50 @@
1+
use std::process::{Command, ExitStatus, Output};
12

23
#[test]
3-
fn cli_tests() {
4+
fn cli_tests() -> cross::Result<()> {
5+
let cargo_version = run_success("cargo", &["--version"])?;
6+
let cargo_help = run_success("cargo", &["--help"])?;
7+
// TODO(ahuszagh) Should get some output here
8+
// TODO(ahuszagh) Get version info from Rust
9+
// TODO(ahuszagh) Get version info from cargo
10+
411
trycmd::TestCases::new()
5-
.case("tests/cmd/*.trycmd")
6-
.case("tests/cmd/*.toml");
12+
.case("tests/cmd/*.toml")
13+
.fail("tests/cmd/no-color.toml")
14+
.insert_var("[CARGOVERSION]", cargo_version.stdout)?
15+
.insert_var("[CARGOHELP]", cargo_help.stdout)?;
16+
17+
Ok(())
18+
}
19+
20+
fn run(bin: &str, args: &[&str]) -> cross::Result<Utf8Output> {
21+
Utf8Output::new(Command::new(bin).args(args).output()?)
22+
}
23+
24+
fn run_success(bin: &str, args: &[&str]) -> cross::Result<Utf8Output> {
25+
run_with_status(bin, args, Some(0))
26+
}
27+
28+
fn run_with_status(bin: &str, args: &[&str], status: Option<i32>) -> cross::Result<Utf8Output> {
29+
let output = run(bin, args)?;
30+
if output.status.code() != status {
31+
eyre::bail!("Unexpected exit status of {:?}", output.status);
32+
}
33+
Ok(output)
34+
}
35+
36+
struct Utf8Output {
37+
status: ExitStatus,
38+
stdout: String,
39+
stderr: String,
40+
}
41+
42+
impl Utf8Output {
43+
fn new(output: Output) -> cross::Result<Self> {
44+
Ok(Self {
45+
status: output.status,
46+
stdout: String::from_utf8(output.stdout)?,
47+
stderr: String::from_utf8(output.stderr)?,
48+
})
49+
}
750
}

tests/cmd/fallback.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[cross] note: Falling back to `cargo` on the host.

tests/cmd/help.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fallback.stderr

tests/cmd/help.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[CARGOHELP]

tests/cmd/help.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin.name = "cross"
2+
args = ["--help"]

tests/cmd/help.trycmd

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
**No Color Provided:**
2-
3-
```
4-
$ cross --color
51
[cross] error: The argument '--color <WHEN>' requires a value but none was supplied
62
[possible values: auto, always, never]
73
Usage:
84
cross [+toolchain] [OPTIONS] [SUBCOMMAND]
95

106
For more information try --help
11-
```

tests/cmd/no-color.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin.name = "cross"
2+
args = ["--color"]

tests/cmd/short-help.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fallback.stderr

tests/cmd/short-help.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
help.stdout

0 commit comments

Comments
 (0)