-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Signed-off-by: Wei Zhang <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
extern crate assert_cmd; | ||
extern crate predicates; | ||
|
||
use assert_cmd::prelude::*; | ||
use assert_fs::prelude::*; | ||
use predicates::prelude::*; | ||
Check failure on line 6 in tests/lscompatible.rs GitHub Actions / Style (macos-latest)
Check warning on line 6 in tests/lscompatible.rs GitHub Actions / MinSRV
Check failure on line 6 in tests/lscompatible.rs GitHub Actions / Style (ubuntu-latest)
Check warning on line 6 in tests/lscompatible.rs GitHub Actions / Build (macos-latest, x86_64-apple-darwin)
Check failure on line 6 in tests/lscompatible.rs GitHub Actions / Style (windows-latest)
Check warning on line 6 in tests/lscompatible.rs GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-gnu, use-cross)
Check warning on line 6 in tests/lscompatible.rs GitHub Actions / Build (ubuntu-latest, i686-unknown-linux-gnu, use-cross)
Check warning on line 6 in tests/lscompatible.rs GitHub Actions / Build (windows-latest, i686-pc-windows-gnu)
Check warning on line 6 in tests/lscompatible.rs GitHub Actions / Build (ubuntu-latest, i686-unknown-linux-musl, use-cross)
Check warning on line 6 in tests/lscompatible.rs GitHub Actions / Build (ubuntu-latest, x86_64-unknown-linux-musl, use-cross)
Check warning on line 6 in tests/lscompatible.rs GitHub Actions / Build (windows-latest, i686-pc-windows-msvc)
Check warning on line 6 in tests/lscompatible.rs GitHub Actions / Build (windows-latest, x86_64-pc-windows-msvc)
|
||
use std::process::{Command, Stdio}; | ||
|
||
fn cmd() -> Command { | ||
Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap() | ||
} | ||
|
||
fn tempdir() -> assert_fs::TempDir { | ||
assert_fs::TempDir::new().unwrap() | ||
} | ||
|
||
#[test] | ||
fn test_pipe_should_use_line() { | ||
let dir = tempdir(); | ||
dir.child("one").touch().unwrap(); | ||
dir.child("two").touch().unwrap(); | ||
|
||
let lsd = cmd() | ||
.arg("--ignore-config") | ||
.arg(dir.path()) | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
.expect("Failed to start lsd process"); | ||
let lsd_out = lsd.stdout.expect("Failed to open ls stdout"); | ||
|
||
let cat_lsd = Command::new("cat") | ||
.stdin(Stdio::from(lsd_out)) | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
.expect("Failed to start cat process"); | ||
let output_lsd = cat_lsd | ||
.wait_with_output() | ||
.expect("Failed to wait on cat lsd"); | ||
|
||
let ls = Command::new("ls") | ||
.arg(dir.path()) | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
.expect("Failed to start ls process"); | ||
let ls_out = ls.stdout.expect("Failed to open ls stdout"); | ||
|
||
let cat_ls = Command::new("cat") | ||
.stdin(Stdio::from(ls_out)) | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
.expect("Failed to start cat process"); | ||
|
||
let output_ls = cat_ls.wait_with_output().expect("Failed to wait on cat ls"); | ||
|
||
assert_eq!(output_ls.stdout, output_lsd.stdout); | ||
} |