summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory <chmln@users.noreply.github.com>2021-03-27 17:55:00 -0400
committerGitHub <noreply@github.com>2021-03-27 17:55:00 -0400
commit479f0403db6024d331f872ca3a1039db061a8d3b (patch)
tree71420046d0971e355d2ccda9a8d82cdf89879282
parentab6827df4e5006d017d1a08524e3183a3708bd6e (diff)
parent71cb0d834af634bc842371c3960db56473d37bee (diff)
Merge pull request #118 from SimplyDanny/fix-master
Fix master
-rw-r--r--.github/workflows/test.yml14
-rw-r--r--tests/cli.rs98
2 files changed, 61 insertions, 51 deletions
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index c6df21d..acd6608 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -29,10 +29,6 @@ jobs:
target: x86_64-apple-darwin
use-cross: false
- - os: macos-latest
- target: aarch64-apple-darwin
- use-cross: false
-
steps:
- name: Checkout repository
uses: actions/checkout@v2
@@ -47,6 +43,16 @@ jobs:
override: true
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
uses: actions-rs/cargo@v1
with:
diff --git a/tests/cli.rs b/tests/cli.rs
index 7d95411..5f767d6 100644
--- a/tests/cli.rs
+++ b/tests/cli.rs
@@ -1,66 +1,70 @@
-use anyhow::Result;
-use assert_cmd::Command;
-use std::io::prelude::*;
+#[cfg(test)]
+#[cfg(not(sd_cross_compile))] // Cross-compilation does not allow to spawn threads but `command.assert()` would do.
+mod cli {
+ use anyhow::Result;
+ use assert_cmd::Command;
+ use std::io::prelude::*;
-fn sd() -> Command {
- Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Error invoking sd")
-}
+ fn sd() -> Command {
+ Command::cargo_bin(env!("CARGO_PKG_NAME")).expect("Error invoking sd")
+ }
-fn assert_file(path: &std::path::Path, content: &str) {
- assert_eq!(content, std::fs::read_to_string(path).unwrap());
-}
+ fn assert_file(path: &std::path::Path, content: &str) {
+ assert_eq!(content, std::fs::read_to_string(path).unwrap());
+ }
-#[test]
-fn in_place() -> Result<()> {
- let mut file = tempfile::NamedTempFile::new()?;
- file.write(b"abc123def")?;
- let path = file.into_temp_path();
+ #[test]
+ fn in_place() -> Result<()> {
+ let mut file = tempfile::NamedTempFile::new()?;
+ file.write(b"abc123def")?;
+ let path = file.into_temp_path();
- sd().args(&["abc\\d+", "", path.to_str().unwrap()])
- .assert()
- .success();
- assert_file(&path.to_path_buf(), "def");
+ sd().args(&["abc\\d+", "", path.to_str().unwrap()])
+ .assert()
+ .success();
+ assert_file(&path.to_path_buf(), "def");
- Ok(())
-}
+ Ok(())
+ }
-#[test]
-fn in_place_with_empty_result_file() -> Result<()> {
- let mut file = tempfile::NamedTempFile::new()?;
- file.write(b"a7c")?;
- let path = file.into_temp_path();
+ #[test]
+ fn in_place_with_empty_result_file() -> Result<()> {
+ let mut file = tempfile::NamedTempFile::new()?;
+ file.write(b"a7c")?;
+ let path = file.into_temp_path();
- sd().args(&["a\\dc", "", path.to_str().unwrap()])
- .assert()
- .success();
- assert_file(&path.to_path_buf(), "");
+ sd().args(&["a\\dc", "", path.to_str().unwrap()])
+ .assert()
+ .success();
+ assert_file(&path.to_path_buf(), "");
- Ok(())
-}
+ Ok(())
+ }
-#[test]
-fn replace_into_stdout() -> Result<()> {
- let mut file = tempfile::NamedTempFile::new()?;
- file.write(b"abc123def")?;
+ #[test]
+ fn replace_into_stdout() -> Result<()> {
+ let mut file = tempfile::NamedTempFile::new()?;
+ file.write(b"abc123def")?;
- #[rustfmt::skip]
+ #[rustfmt::skip]
sd().args(&["-p", "abc\\d+", "", file.path().to_str().unwrap()])
.assert()
.success()
.stdout("def");
- assert_file(file.path(), "abc123def");
+ assert_file(file.path(), "abc123def");
- Ok(())
-}
+ Ok(())
+ }
-#[test]
-fn stdin() -> Result<()> {
- sd().args(&["abc\\d+", ""])
- .write_stdin("abc123def")
- .assert()
- .success()
- .stdout("def");
+ #[test]
+ fn stdin() -> Result<()> {
+ sd().args(&["abc\\d+", ""])
+ .write_stdin("abc123def")
+ .assert()
+ .success()
+ .stdout("def");
- Ok(())
+ Ok(())
+ }
}