Skip to content

Commit fe0208f

Browse files
committed
Add numerous more UI tests.
1 parent 65b122c commit fe0208f

23 files changed

+111
-10
lines changed

.github/workflows/ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ jobs:
7474
- name: Run unit tests
7575
run: cargo test --locked --all-targets --workspace --all-features
7676
timeout-minutes: 10
77+
78+
- name: Run ignored unit tests
79+
run: cargo test --locked --all-targets --workspace --all-features -- --ignored
80+
timeout-minutes: 10
7781
check:
7882
runs-on: ubuntu-latest
7983
outputs:

src/tests.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ release: {version}
138138

139139
#[test]
140140
fn check_newlines() -> crate::Result<()> {
141-
for file in walk_dir(get_cargo_workspace(), &[".git", "target"], |_| true) {
141+
// tests contains the trycmd tests, which may have placeholders
142+
for file in walk_dir(get_cargo_workspace(), &[".git", "target", "tests"], |_| {
143+
true
144+
}) {
142145
let file = file?;
143146
if !file.file_type().map_or(true, |f| f.is_file()) {
144147
continue;

tests/cli.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
use std::process::{Command, ExitStatus, Output};
22

33
#[test]
4+
#[ignore]
45
fn cli_tests() -> cross::Result<()> {
56
let cargo_version = run_success("cargo", &["--version"])?;
67
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-
8+
// TODO(ahuszagh): We need to add the following:
9+
// Get version info from cross: this needs to use the same
10+
// code as cross itself
11+
//
12+
// `cargo --quiet --verbose` prints the help menu
13+
// this is currently incorrect, it errors
14+
//
15+
// Need `CARGO_TERM_VERBOSE=true cargo build --quiet` to pass
16+
//
17+
// Need many additional unittests
18+
19+
// FIXME: `[CARGOHELP]` does not seem to work: we have the output hard-coded
20+
// This is likely because of how it tries to replace the
21+
// `[+toolchain] [OPTIONS] [SUBCOMMAND]` contents.
1122
trycmd::TestCases::new()
1223
.case("tests/cmd/*.toml")
13-
.fail("tests/cmd/no-color.toml")
24+
.case("tests/cmd/*.md")
1425
.insert_var("[CARGOVERSION]", cargo_version.stdout)?
1526
.insert_var("[CARGOHELP]", cargo_help.stdout)?;
1627

@@ -33,6 +44,7 @@ fn run_with_status(bin: &str, args: &[&str], status: Option<i32>) -> cross::Resu
3344
Ok(output)
3445
}
3546

47+
#[allow(dead_code)]
3648
struct Utf8Output {
3749
status: ExitStatus,
3850
stdout: String,

tests/cmd/build-no-color.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
no-color.stderr

tests/cmd/build-no-color.stdout

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
no-color.stdout

tests/cmd/build-no-color.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bin.name = "cross"
2+
args = ["build", "--color"]
3+
status = "failed"

tests/cmd/help.stdout

+39-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,39 @@
1-
[CARGOHELP]
1+
Rust's package manager
2+
3+
USAGE:
4+
cargo [+toolchain] [OPTIONS] [SUBCOMMAND]
5+
6+
OPTIONS:
7+
-V, --version Print version info and exit
8+
--list List installed commands
9+
--explain <CODE> Run `rustc --explain CODE`
10+
-v, --verbose Use verbose output (-vv very verbose/build.rs output)
11+
-q, --quiet Do not print cargo log messages
12+
--color <WHEN> Coloring: auto, always, never
13+
--frozen Require Cargo.lock and cache are up to date
14+
--locked Require Cargo.lock is up to date
15+
--offline Run without accessing the network
16+
--config <KEY=VALUE> Override a configuration value (unstable)
17+
-Z <FLAG> Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for
18+
details
19+
-h, --help Print help information
20+
21+
Some common cargo commands are (see all commands with --list):
22+
build, b Compile the current package
23+
check, c Analyze the current package and report errors, but don't build object files
24+
clean Remove the target directory
25+
doc, d Build this package's and its dependencies' documentation
26+
new Create a new cargo package
27+
init Create a new cargo package in an existing directory
28+
add Add dependencies to a manifest file
29+
run, r Run a binary or example of the local package
30+
test, t Run the tests
31+
bench Run the benchmarks
32+
update Update dependencies listed in Cargo.lock
33+
search Search registry for crates
34+
publish Package and upload this package to the registry
35+
install Install a Rust binary. Default location is $HOME/.cargo/bin
36+
uninstall Uninstall a Rust binary
37+
38+
See 'cargo help <command>' for more information on a specific command.
39+

tests/cmd/list.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fallback.stderr

tests/cmd/list.stdout

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Cross Commands:
2+
b [..] alias: build
3+
bench [..] Execute all benchmarks of a local package
4+
build [..] Compile a local package and all of its dependencies
5+
c [..] alias: check
6+
check [..] Check a local package and all of its dependencies for errors
7+
clean [..] Remove artifacts that cargo has generated in the past
8+
clippy [..] Checks a package to catch common mistakes and improve your Rust code.
9+
doc [..] Build a package's documentation
10+
metadata [..] Output the resolved dependencies of a package, the concrete used versions including overrides, in machine-readable format
11+
r [..] alias: run
12+
run [..] Run a binary or example of the local package
13+
rustc [..] Compile a package, and pass extra options to the compiler
14+
t [..] alias: test
15+
test [..] Execute all unit and integration tests and build examples of a local package
16+
Host Commands:
17+
...
18+
add Add dependencies to a Cargo.toml manifest file
19+
...

tests/cmd/list.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin.name = "cross"
2+
args = ["--list"]

tests/cmd/no-args.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
help.stderr

tests/cmd/no-args.stdout

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
help.stdout

tests/cmd/no-args.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bin.name = "cross"

tests/cmd/no-color.stdout

Whitespace-only changes.

tests/cmd/no-color.toml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin.name = "cross"
22
args = ["--color"]
3+
status = "failed"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
quiet-verbose.stderr
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
quiet-verbose.stdout
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bin.name = "cross"
2+
args = ["build"]
3+
status = "failed"
4+
5+
[env.add]
6+
CARGO_TERM_VERBOSE = "true"
7+
CARGO_TERM_QUIET = "true"

tests/cmd/quiet-verbose.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[cross] error: cannot set both --verbose and --quiet

tests/cmd/quiet-verbose.stdout

Whitespace-only changes.

tests/cmd/quiet-verbose.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
bin.name = "cross"
2+
args = ["build", "--quiet", "--verbose"]
3+
status = "failed"

tests/cmd/version.stdout

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
cross 0.2.4 (35a1e17 2022-11-01)
1+
cross [..]
22
[CARGOVERSION]

xtask/src/ui.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn cross_ui(
286286
)?;
287287

288288
// check we can run custom binaries
289-
cross_command("run", target, image, &workspace_dir.join("binary"), None)?
289+
cross_command("run", target, image, workspace_dir.join("binary"), None)?
290290
.utf8_output(msg_info)?
291291
.runs("Hello from binary, binary/src/main.rs")?;
292292
check_file_exists(&workspace_dir, &format!("target/{target}/debug/binary"))?;
@@ -357,7 +357,7 @@ fn target_dir() -> PathBuf {
357357
fn cargo_bin(bin: impl AsRef<str>, cwd: impl AsRef<Path>) -> cross::Result<Command> {
358358
let bin = bin.as_ref();
359359
let env_var = format!("CARGO_BIN_EXE_{}", bin);
360-
let path = env::var_os(&env_var)
360+
let path = env::var_os(env_var)
361361
.map(|p| p.into())
362362
.unwrap_or_else(|| target_dir().join(format!("{}{}", bin, env::consts::EXE_SUFFIX)));
363363

0 commit comments

Comments
 (0)