Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to use assert_cmd with rust-cross #139

Closed
ducaale opened this issue Dec 22, 2021 · 5 comments · Fixed by #193
Closed

Document how to use assert_cmd with rust-cross #139

ducaale opened this issue Dec 22, 2021 · 5 comments · Fixed by #193
Labels
enhancement Improve the expected

Comments

@ducaale
Copy link

ducaale commented Dec 22, 2021

It would be nice to mention that when running tests in cross, one needs to prepend their command with the value contained in CARGO_TARGET_*_RUNNER i.e qemu-aarch64 xh

fn find_runner() -> Option<String> {
    for (key, value) in std::env::vars() {
        if key.starts_with("CARGO_TARGET_") && key.ends_with("_RUNNER") && value.contains("qemu") {
            return Some(value);
        }
    }
    None
}

fn get_base_command() -> Command {
    let mut cmd;
    let path = assert_cmd::cargo::cargo_bin("xh");
    if let Some(runner) = find_runner() {
        cmd = Command::new(runner);
        cmd.arg(path);
    } else {
        cmd = Command::new(path);
    }
    cmd
}

Also, see ducaale/xh#190 (comment)

@epage epage added the enhancement Improve the expected label Dec 22, 2021
@epage
Copy link
Contributor

epage commented Dec 22, 2021

Thanks for providing an example on how to do this. This will be good to add to the docs here and for trycmd

@mfreeborn
Copy link

mfreeborn commented Jul 30, 2022

I wonder, has this changed at all? I'm struggling to get my integration tests running with cross v0.2.4 and assert_cmd.

When running under cross for --target armv7-unknown-linux-gnueabihf, CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_RUNNER = /linux-runner armv7 i.e. the value does not contain qemu, which is what is tested for in find_runner().

Experimenting with adding the prefix manually, the following do not work: /linux-runner armv7, qemu-armv7 and qemu-aarch64.

What does work is qemu-arm, but that is nowhere to be found in the environment variables.

Hence I ask, what is the best way to handle this case at present?

@ducaale
Copy link
Author

ducaale commented Jul 30, 2022

@mfreeborn, can you try if the following works for you? I think the values of CARGO_TARGET_*_RUNNER have been updated in cross v0.2.2

fn find_runner() -> Option<String> {
    for (key, value) in std::env::vars() {
        if key.starts_with("CARGO_TARGET_") && key.ends_with("_RUNNER") && !value.is_empty() {
            return Some(value);
        }
    }
    None
}

fn get_base_command() -> Command {
    let mut cmd;
    let path = assert_cmd::cargo::cargo_bin("xh");
    if let Some(runner) = find_runner() {
        let mut runner = runner.split_whitespace();
        cmd = Command::new(runner.next().unwrap());
        for arg in runner {
            cmd.arg(arg);
        }
        cmd.arg(path);
    } else {
        cmd = Command::new(path);
    }
    cmd
}

@mfreeborn
Copy link

I can confirm that is working - thanks very much!

@mizuki0629
Copy link

Thank you for helping me find this method. Please document it for future reference.

glehmann added a commit to glehmann/assert_cmd that referenced this issue Jan 28, 2024
and how to not change anything to run with cross

close: assert-rs#139
glehmann added a commit to glehmann/assert_cmd that referenced this issue Feb 3, 2024
don't run the mod_example test when using cross

it depends on escargot also supporting cross, which it doesn't at this time

document the runner configuration usage

and how to not change anything to run with cross

close: assert-rs#139
glehmann added a commit to glehmann/assert_cmd that referenced this issue Feb 7, 2024
don't run the mod_example test when using cross

it depends on escargot also supporting cross, which it doesn't at this time

document the runner configuration usage

and how to not change anything to run with cross

close: assert-rs#139
glehmann added a commit to glehmann/assert_cmd that referenced this issue Feb 19, 2024
don't run the mod_example test when using cross

it depends on escargot also supporting cross, which it doesn't at this time

document the runner configuration usage

and how to not change anything to run with cross

close: assert-rs#139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve the expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants