mirror of
https://github.com/uutils/diffutils.git
synced 2026-06-10 15:48:59 -07:00
99 lines
2.9 KiB
Rust
99 lines
2.9 KiB
Rust
// This file is part of the uutils diffutils package.
|
|
//
|
|
// For the full copyright and license information, please view the LICENSE-*
|
|
// files that was distributed with this source code.
|
|
|
|
use assert_cmd::prelude::*;
|
|
use predicates::prelude::*;
|
|
use std::io::Write;
|
|
use std::process::Command;
|
|
use tempfile::NamedTempFile;
|
|
|
|
// Integration tests for the diffutils command
|
|
|
|
#[test]
|
|
fn unknown_param() -> Result<(), Box<dyn std::error::Error>> {
|
|
let mut cmd = Command::cargo_bin("diffutils")?;
|
|
cmd.arg("--foobar");
|
|
cmd.assert()
|
|
.code(predicate::eq(2))
|
|
.failure()
|
|
.stderr(predicate::str::starts_with("Usage: "));
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn cannot_read_from_file() -> Result<(), Box<dyn std::error::Error>> {
|
|
let mut cmd = Command::cargo_bin("diffutils")?;
|
|
cmd.arg("foo.txt").arg("bar.txt");
|
|
cmd.assert()
|
|
.code(predicate::eq(2))
|
|
.failure()
|
|
.stderr(predicate::str::starts_with("Failed to read from-file"));
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn cannot_read_to_file() -> Result<(), Box<dyn std::error::Error>> {
|
|
let file = NamedTempFile::new()?;
|
|
let mut cmd = Command::cargo_bin("diffutils")?;
|
|
cmd.arg(file.path()).arg("bar.txt");
|
|
cmd.assert()
|
|
.code(predicate::eq(2))
|
|
.failure()
|
|
.stderr(predicate::str::starts_with("Failed to read to-file"));
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn no_differences() -> Result<(), Box<dyn std::error::Error>> {
|
|
let file = NamedTempFile::new()?;
|
|
for option in ["", "-u", "-c", "-e"] {
|
|
let mut cmd = Command::cargo_bin("diffutils")?;
|
|
if !option.is_empty() {
|
|
cmd.arg(option);
|
|
}
|
|
cmd.arg(file.path()).arg(file.path());
|
|
cmd.assert()
|
|
.code(predicate::eq(0))
|
|
.success()
|
|
.stdout(predicate::str::is_empty());
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn differences() -> Result<(), Box<dyn std::error::Error>> {
|
|
let mut file1 = NamedTempFile::new()?;
|
|
file1.write_all("foo\n".as_bytes())?;
|
|
let mut file2 = NamedTempFile::new()?;
|
|
file2.write_all("bar\n".as_bytes())?;
|
|
for option in ["", "-u", "-c", "-e"] {
|
|
let mut cmd = Command::cargo_bin("diffutils")?;
|
|
if !option.is_empty() {
|
|
cmd.arg(option);
|
|
}
|
|
cmd.arg(file1.path()).arg(file2.path());
|
|
cmd.assert()
|
|
.code(predicate::eq(1))
|
|
.failure()
|
|
.stdout(predicate::str::is_empty().not());
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn missing_newline() -> Result<(), Box<dyn std::error::Error>> {
|
|
let mut file1 = NamedTempFile::new()?;
|
|
file1.write_all("foo".as_bytes())?;
|
|
let mut file2 = NamedTempFile::new()?;
|
|
file2.write_all("bar".as_bytes())?;
|
|
let mut cmd = Command::cargo_bin("diffutils")?;
|
|
cmd.arg("-e").arg(file1.path()).arg(file2.path());
|
|
cmd.assert()
|
|
.code(predicate::eq(2))
|
|
.failure()
|
|
.stderr(predicate::str::starts_with("No newline at end of file"));
|
|
Ok(())
|
|
}
|