mirror of
https://github.com/chmln/sd
synced 2025-02-16 15:58:23 +00:00
Ignore integration tests in cross-compiled targets
As stated [here](https://github.com/rust-embedded/cross#supported-targets) spawning threads in tests will make them fail or they may not terminate at all.
This commit is contained in:
parent
ab6827df4e
commit
7724332232
2 changed files with 64 additions and 50 deletions
12
.github/workflows/test.yml
vendored
12
.github/workflows/test.yml
vendored
|
@ -31,7 +31,7 @@ jobs:
|
||||||
|
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
target: aarch64-apple-darwin
|
target: aarch64-apple-darwin
|
||||||
use-cross: false
|
use-cross: true
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
|
@ -47,6 +47,16 @@ jobs:
|
||||||
override: true
|
override: true
|
||||||
target: ${{ matrix.target }}
|
target: ${{ matrix.target }}
|
||||||
|
|
||||||
|
- name: Create .cargo/config.toml
|
||||||
|
if: ${{ matrix.use-cross == true }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir .cargo
|
||||||
|
cat > .cargo/config.toml <<EOF
|
||||||
|
[target.${{ matrix.target }}]
|
||||||
|
rustflags = ["--cfg", "sd_cross_compile"]
|
||||||
|
EOF
|
||||||
|
|
||||||
- name: Test
|
- name: Test
|
||||||
uses: actions-rs/cargo@v1
|
uses: actions-rs/cargo@v1
|
||||||
with:
|
with:
|
||||||
|
|
40
tests/cli.rs
40
tests/cli.rs
|
@ -1,17 +1,20 @@
|
||||||
use anyhow::Result;
|
#[cfg(test)]
|
||||||
use assert_cmd::Command;
|
#[cfg(not(sd_cross_compile))] // Cross-compilation does not allow to spawn threads but `command.assert()` would do.
|
||||||
use std::io::prelude::*;
|
mod cli {
|
||||||
|
use anyhow::Result;
|
||||||
|
use assert_cmd::Command;
|
||||||
|
use std::io::prelude::*;
|
||||||
|
|
||||||
fn sd() -> Command {
|
fn sd() -> Command {
|
||||||
Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Error invoking sd")
|
Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Error invoking sd")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_file(path: &std::path::Path, content: &str) {
|
fn assert_file(path: &std::path::Path, content: &str) {
|
||||||
assert_eq!(content, std::fs::read_to_string(path).unwrap());
|
assert_eq!(content, std::fs::read_to_string(path).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn in_place() -> Result<()> {
|
fn in_place() -> Result<()> {
|
||||||
let mut file = tempfile::NamedTempFile::new()?;
|
let mut file = tempfile::NamedTempFile::new()?;
|
||||||
file.write(b"abc123def")?;
|
file.write(b"abc123def")?;
|
||||||
let path = file.into_temp_path();
|
let path = file.into_temp_path();
|
||||||
|
@ -22,10 +25,10 @@ fn in_place() -> Result<()> {
|
||||||
assert_file(&path.to_path_buf(), "def");
|
assert_file(&path.to_path_buf(), "def");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn in_place_with_empty_result_file() -> Result<()> {
|
fn in_place_with_empty_result_file() -> Result<()> {
|
||||||
let mut file = tempfile::NamedTempFile::new()?;
|
let mut file = tempfile::NamedTempFile::new()?;
|
||||||
file.write(b"a7c")?;
|
file.write(b"a7c")?;
|
||||||
let path = file.into_temp_path();
|
let path = file.into_temp_path();
|
||||||
|
@ -36,10 +39,10 @@ fn in_place_with_empty_result_file() -> Result<()> {
|
||||||
assert_file(&path.to_path_buf(), "");
|
assert_file(&path.to_path_buf(), "");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn replace_into_stdout() -> Result<()> {
|
fn replace_into_stdout() -> Result<()> {
|
||||||
let mut file = tempfile::NamedTempFile::new()?;
|
let mut file = tempfile::NamedTempFile::new()?;
|
||||||
file.write(b"abc123def")?;
|
file.write(b"abc123def")?;
|
||||||
|
|
||||||
|
@ -52,10 +55,10 @@ fn replace_into_stdout() -> Result<()> {
|
||||||
assert_file(file.path(), "abc123def");
|
assert_file(file.path(), "abc123def");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn stdin() -> Result<()> {
|
fn stdin() -> Result<()> {
|
||||||
sd().args(&["abc\\d+", ""])
|
sd().args(&["abc\\d+", ""])
|
||||||
.write_stdin("abc123def")
|
.write_stdin("abc123def")
|
||||||
.assert()
|
.assert()
|
||||||
|
@ -63,4 +66,5 @@ fn stdin() -> Result<()> {
|
||||||
.stdout("def");
|
.stdout("def");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue