mirror of
https://github.com/uutils/diffutils.git
synced 2026-06-29 15:15:15 -04:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fe605ff853 |
Generated
+1
-1
@@ -122,7 +122,7 @@ checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
||||
|
||||
[[package]]
|
||||
name = "diffutils"
|
||||
version = "0.4.1"
|
||||
version = "0.4.0"
|
||||
dependencies = [
|
||||
"assert_cmd",
|
||||
"chrono",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "diffutils"
|
||||
version = "0.4.1"
|
||||
version = "0.4.0"
|
||||
edition = "2021"
|
||||
description = "A CLI app for generating diff files"
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
Copyright (c) Michael Howell
|
||||
Copyright (c) uutils developers
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
Copyright (c) Michael Howell
|
||||
Copyright (c) uutils developers
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
|
||||
@@ -178,6 +178,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_permutations() {
|
||||
let target = "target/ed-diff/";
|
||||
// test all possible six-line files.
|
||||
@@ -258,6 +259,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_permutations_empty_lines() {
|
||||
let target = "target/ed-diff/";
|
||||
// test all possible six-line files with missing newlines.
|
||||
@@ -332,6 +334,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(windows))]
|
||||
fn test_permutations_reverse() {
|
||||
let target = "target/ed-diff/";
|
||||
// test all possible six-line files.
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
// considering datetime varitations
|
||||
//
|
||||
// It replaces the modification time in the actual diff
|
||||
// with placeholder "TIMESTAMP" and then asserts the equality
|
||||
// with placeholer "TIMESTAMP" and then asserts the equality
|
||||
//
|
||||
// For eg.
|
||||
// let brief = "*** fruits_old.txt\t2024-03-24 23:43:05.189597645 +0530\n
|
||||
|
||||
+69
-314
@@ -1,5 +1,4 @@
|
||||
use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
use std::ffi::{OsStr, OsString};
|
||||
|
||||
use regex::Regex;
|
||||
|
||||
@@ -12,6 +11,17 @@ pub enum Format {
|
||||
Ed,
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
fn osstr_bytes(osstr: &OsStr) -> &[u8] {
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
osstr.as_bytes()
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
fn osstr_bytes(osstr: &OsStr) -> Vec<u8> {
|
||||
osstr.to_string_lossy().bytes().collect()
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub struct Params {
|
||||
pub from: OsString,
|
||||
@@ -40,7 +50,7 @@ impl Default for Params {
|
||||
}
|
||||
|
||||
pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params, String> {
|
||||
let mut opts = opts.into_iter().peekable();
|
||||
let mut opts = opts.into_iter();
|
||||
// parse CLI
|
||||
|
||||
let Some(exe) = opts.next() else {
|
||||
@@ -50,10 +60,8 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
|
||||
let mut from = None;
|
||||
let mut to = None;
|
||||
let mut format = None;
|
||||
let mut context = None;
|
||||
let tabsize_re = Regex::new(r"^--tabsize=(?<num>\d+)$").unwrap();
|
||||
while let Some(param) = opts.next() {
|
||||
let next_param = opts.peek();
|
||||
if param == "--" {
|
||||
break;
|
||||
}
|
||||
@@ -79,20 +87,6 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
|
||||
params.expand_tabs = true;
|
||||
continue;
|
||||
}
|
||||
if param == "--normal" {
|
||||
if format.is_some() && format != Some(Format::Normal) {
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Normal);
|
||||
continue;
|
||||
}
|
||||
if param == "-e" || param == "--ed" {
|
||||
if format.is_some() && format != Some(Format::Ed) {
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Ed);
|
||||
continue;
|
||||
}
|
||||
if tabsize_re.is_match(param.to_string_lossy().as_ref()) {
|
||||
// Because param matches the regular expression,
|
||||
// it is safe to assume it is valid UTF-8.
|
||||
@@ -109,48 +103,60 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
|
||||
};
|
||||
continue;
|
||||
}
|
||||
match match_context_diff_params(¶m, next_param, format) {
|
||||
Ok(DiffStyleMatch {
|
||||
is_match,
|
||||
context_count,
|
||||
next_param_consumed,
|
||||
}) => {
|
||||
if is_match {
|
||||
format = Some(Format::Context);
|
||||
if context_count.is_some() {
|
||||
context = context_count;
|
||||
let p = osstr_bytes(¶m);
|
||||
if p.first() == Some(&b'-') && p.get(1) != Some(&b'-') {
|
||||
let mut bit = p[1..].iter().copied().peekable();
|
||||
// Can't use a for loop because `diff -30u` is supposed to make a diff
|
||||
// with 30 lines of context.
|
||||
while let Some(b) = bit.next() {
|
||||
match b {
|
||||
b'0'..=b'9' => {
|
||||
params.context_count = (b - b'0') as usize;
|
||||
while let Some(b'0'..=b'9') = bit.peek() {
|
||||
params.context_count *= 10;
|
||||
params.context_count += (bit.next().unwrap() - b'0') as usize;
|
||||
}
|
||||
}
|
||||
if next_param_consumed {
|
||||
opts.next();
|
||||
b'c' => {
|
||||
if format.is_some() && format != Some(Format::Context) {
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Context);
|
||||
}
|
||||
continue;
|
||||
b'e' => {
|
||||
if format.is_some() && format != Some(Format::Ed) {
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Ed);
|
||||
}
|
||||
b'u' => {
|
||||
if format.is_some() && format != Some(Format::Unified) {
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Unified);
|
||||
}
|
||||
b'U' => {
|
||||
if format.is_some() && format != Some(Format::Unified) {
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Unified);
|
||||
let context_count_maybe = if bit.peek().is_some() {
|
||||
String::from_utf8(bit.collect::<Vec<u8>>()).ok()
|
||||
} else {
|
||||
opts.next().map(|x| x.to_string_lossy().into_owned())
|
||||
};
|
||||
if let Some(context_count_maybe) =
|
||||
context_count_maybe.and_then(|x| x.parse().ok())
|
||||
{
|
||||
params.context_count = context_count_maybe;
|
||||
break;
|
||||
}
|
||||
return Err("Invalid context count".to_string());
|
||||
}
|
||||
_ => return Err(format!("Unknown option: {}", String::from_utf8_lossy(&[b]))),
|
||||
}
|
||||
}
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
match match_unified_diff_params(¶m, next_param, format) {
|
||||
Ok(DiffStyleMatch {
|
||||
is_match,
|
||||
context_count,
|
||||
next_param_consumed,
|
||||
}) => {
|
||||
if is_match {
|
||||
format = Some(Format::Unified);
|
||||
if context_count.is_some() {
|
||||
context = context_count;
|
||||
}
|
||||
if next_param_consumed {
|
||||
opts.next();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Err(error) => return Err(error),
|
||||
}
|
||||
if param.to_string_lossy().starts_with('-') {
|
||||
return Err(format!("Unknown option: {:?}", param));
|
||||
}
|
||||
if from.is_none() {
|
||||
} else if from.is_none() {
|
||||
from = Some(param);
|
||||
} else if to.is_none() {
|
||||
to = Some(param);
|
||||
@@ -172,125 +178,10 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
|
||||
} else {
|
||||
return Err(format!("Usage: {} <from> <to>", exe.to_string_lossy()));
|
||||
};
|
||||
|
||||
// diff DIRECTORY FILE => diff DIRECTORY/FILE FILE
|
||||
// diff FILE DIRECTORY => diff FILE DIRECTORY/FILE
|
||||
let mut from_path: PathBuf = PathBuf::from(¶ms.from);
|
||||
let mut to_path: PathBuf = PathBuf::from(¶ms.to);
|
||||
|
||||
if from_path.is_dir() && to_path.is_file() {
|
||||
from_path.push(to_path.file_name().unwrap());
|
||||
params.from = from_path.into_os_string();
|
||||
} else if from_path.is_file() && to_path.is_dir() {
|
||||
to_path.push(from_path.file_name().unwrap());
|
||||
params.to = to_path.into_os_string();
|
||||
}
|
||||
|
||||
params.format = format.unwrap_or(Format::default());
|
||||
if let Some(context_count) = context {
|
||||
params.context_count = context_count;
|
||||
}
|
||||
Ok(params)
|
||||
}
|
||||
|
||||
struct DiffStyleMatch {
|
||||
is_match: bool,
|
||||
context_count: Option<usize>,
|
||||
next_param_consumed: bool,
|
||||
}
|
||||
|
||||
fn match_context_diff_params(
|
||||
param: &OsString,
|
||||
next_param: Option<&OsString>,
|
||||
format: Option<Format>,
|
||||
) -> Result<DiffStyleMatch, String> {
|
||||
const CONTEXT_RE: &str = r"^(-[cC](?<num1>\d*)|--context(=(?<num2>\d*))?|-(?<num3>\d+)c)$";
|
||||
let regex = Regex::new(CONTEXT_RE).unwrap();
|
||||
let is_match = regex.is_match(param.to_string_lossy().as_ref());
|
||||
let mut context_count = None;
|
||||
let mut next_param_consumed = false;
|
||||
if is_match {
|
||||
if format.is_some() && format != Some(Format::Context) {
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
let captures = regex.captures(param.to_str().unwrap()).unwrap();
|
||||
let num = captures
|
||||
.name("num1")
|
||||
.or(captures.name("num2"))
|
||||
.or(captures.name("num3"));
|
||||
if let Some(numvalue) = num {
|
||||
if !numvalue.as_str().is_empty() {
|
||||
context_count = Some(numvalue.as_str().parse::<usize>().unwrap());
|
||||
}
|
||||
}
|
||||
if param == "-C" && next_param.is_some() {
|
||||
match next_param.unwrap().to_string_lossy().parse::<usize>() {
|
||||
Ok(context_size) => {
|
||||
context_count = Some(context_size);
|
||||
next_param_consumed = true;
|
||||
}
|
||||
Err(_) => {
|
||||
return Err(format!(
|
||||
"invalid context length '{}'",
|
||||
next_param.unwrap().to_string_lossy()
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(DiffStyleMatch {
|
||||
is_match,
|
||||
context_count,
|
||||
next_param_consumed,
|
||||
})
|
||||
}
|
||||
|
||||
fn match_unified_diff_params(
|
||||
param: &OsString,
|
||||
next_param: Option<&OsString>,
|
||||
format: Option<Format>,
|
||||
) -> Result<DiffStyleMatch, String> {
|
||||
const UNIFIED_RE: &str = r"^(-[uU](?<num1>\d*)|--unified(=(?<num2>\d*))?|-(?<num3>\d+)u)$";
|
||||
let regex = Regex::new(UNIFIED_RE).unwrap();
|
||||
let is_match = regex.is_match(param.to_string_lossy().as_ref());
|
||||
let mut context_count = None;
|
||||
let mut next_param_consumed = false;
|
||||
if is_match {
|
||||
if format.is_some() && format != Some(Format::Unified) {
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
let captures = regex.captures(param.to_str().unwrap()).unwrap();
|
||||
let num = captures
|
||||
.name("num1")
|
||||
.or(captures.name("num2"))
|
||||
.or(captures.name("num3"));
|
||||
if let Some(numvalue) = num {
|
||||
if !numvalue.as_str().is_empty() {
|
||||
context_count = Some(numvalue.as_str().parse::<usize>().unwrap());
|
||||
}
|
||||
}
|
||||
if param == "-U" && next_param.is_some() {
|
||||
match next_param.unwrap().to_string_lossy().parse::<usize>() {
|
||||
Ok(context_size) => {
|
||||
context_count = Some(context_size);
|
||||
next_param_consumed = true;
|
||||
}
|
||||
Err(_) => {
|
||||
return Err(format!(
|
||||
"invalid context length '{}'",
|
||||
next_param.unwrap().to_string_lossy()
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(DiffStyleMatch {
|
||||
is_match,
|
||||
context_count,
|
||||
next_param_consumed,
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -307,148 +198,20 @@ mod tests {
|
||||
}),
|
||||
parse_params([os("diff"), os("foo"), os("bar")].iter().cloned())
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn basics_ed() {
|
||||
assert_eq!(
|
||||
Ok(Params {
|
||||
from: os("foo"),
|
||||
to: os("bar"),
|
||||
format: Format::Ed,
|
||||
..Default::default()
|
||||
}),
|
||||
parse_params(
|
||||
[os("diff"), os("--normal"), os("foo"), os("bar")]
|
||||
.iter()
|
||||
.cloned()
|
||||
)
|
||||
parse_params([os("diff"), os("-e"), os("foo"), os("bar")].iter().cloned())
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn basics_ed() {
|
||||
for arg in ["-e", "--ed"] {
|
||||
assert_eq!(
|
||||
Ok(Params {
|
||||
from: os("foo"),
|
||||
to: os("bar"),
|
||||
format: Format::Ed,
|
||||
..Default::default()
|
||||
}),
|
||||
parse_params([os("diff"), os(arg), os("foo"), os("bar")].iter().cloned())
|
||||
);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn context_valid() {
|
||||
for args in [vec!["-c"], vec!["--context"], vec!["--context="]] {
|
||||
let mut params = vec!["diff"];
|
||||
params.extend(args);
|
||||
params.extend(["foo", "bar"]);
|
||||
assert_eq!(
|
||||
Ok(Params {
|
||||
from: os("foo"),
|
||||
to: os("bar"),
|
||||
format: Format::Context,
|
||||
..Default::default()
|
||||
}),
|
||||
parse_params(params.iter().map(|x| os(x)))
|
||||
);
|
||||
}
|
||||
for args in [
|
||||
vec!["-c42"],
|
||||
vec!["-C42"],
|
||||
vec!["-C", "42"],
|
||||
vec!["--context=42"],
|
||||
vec!["-42c"],
|
||||
] {
|
||||
let mut params = vec!["diff"];
|
||||
params.extend(args);
|
||||
params.extend(["foo", "bar"]);
|
||||
assert_eq!(
|
||||
Ok(Params {
|
||||
from: os("foo"),
|
||||
to: os("bar"),
|
||||
format: Format::Context,
|
||||
context_count: 42,
|
||||
..Default::default()
|
||||
}),
|
||||
parse_params(params.iter().map(|x| os(x)))
|
||||
);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn context_invalid() {
|
||||
for args in [
|
||||
vec!["-c", "42"],
|
||||
vec!["-c=42"],
|
||||
vec!["-c="],
|
||||
vec!["-C"],
|
||||
vec!["-C=42"],
|
||||
vec!["-C="],
|
||||
vec!["--context42"],
|
||||
vec!["--context", "42"],
|
||||
vec!["-42C"],
|
||||
] {
|
||||
let mut params = vec!["diff"];
|
||||
params.extend(args);
|
||||
params.extend(["foo", "bar"]);
|
||||
assert!(parse_params(params.iter().map(|x| os(x))).is_err());
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn unified_valid() {
|
||||
for args in [vec!["-u"], vec!["--unified"], vec!["--unified="]] {
|
||||
let mut params = vec!["diff"];
|
||||
params.extend(args);
|
||||
params.extend(["foo", "bar"]);
|
||||
assert_eq!(
|
||||
Ok(Params {
|
||||
from: os("foo"),
|
||||
to: os("bar"),
|
||||
format: Format::Unified,
|
||||
..Default::default()
|
||||
}),
|
||||
parse_params(params.iter().map(|x| os(x)))
|
||||
);
|
||||
}
|
||||
for args in [
|
||||
vec!["-u42"],
|
||||
vec!["-U42"],
|
||||
vec!["-U", "42"],
|
||||
vec!["--unified=42"],
|
||||
vec!["-42u"],
|
||||
] {
|
||||
let mut params = vec!["diff"];
|
||||
params.extend(args);
|
||||
params.extend(["foo", "bar"]);
|
||||
assert_eq!(
|
||||
Ok(Params {
|
||||
from: os("foo"),
|
||||
to: os("bar"),
|
||||
format: Format::Unified,
|
||||
context_count: 42,
|
||||
..Default::default()
|
||||
}),
|
||||
parse_params(params.iter().map(|x| os(x)))
|
||||
);
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn unified_invalid() {
|
||||
for args in [
|
||||
vec!["-u", "42"],
|
||||
vec!["-u=42"],
|
||||
vec!["-u="],
|
||||
vec!["-U"],
|
||||
vec!["-U=42"],
|
||||
vec!["-U="],
|
||||
vec!["--unified42"],
|
||||
vec!["--unified", "42"],
|
||||
vec!["-42U"],
|
||||
] {
|
||||
let mut params = vec!["diff"];
|
||||
params.extend(args);
|
||||
params.extend(["foo", "bar"]);
|
||||
assert!(parse_params(params.iter().map(|x| os(x))).is_err());
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
fn context_count() {
|
||||
assert_eq!(
|
||||
Ok(Params {
|
||||
@@ -741,15 +504,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn conflicting_output_styles() {
|
||||
for (arg1, arg2) in [
|
||||
("-u", "-c"),
|
||||
("-u", "-e"),
|
||||
("-c", "-u"),
|
||||
("-c", "-U42"),
|
||||
("-u", "--normal"),
|
||||
("--normal", "-e"),
|
||||
("--context", "--normal"),
|
||||
] {
|
||||
for (arg1, arg2) in [("-u", "-c"), ("-u", "-e"), ("-c", "-u"), ("-c", "-U42")] {
|
||||
assert!(parse_params(
|
||||
[os("diff"), os(arg1), os(arg2), os("foo"), os("bar")]
|
||||
.iter()
|
||||
|
||||
+5
-56
@@ -6,9 +6,8 @@
|
||||
use assert_cmd::cmd::Command;
|
||||
use diffutilslib::assert_diff_eq;
|
||||
use predicates::prelude::*;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use tempfile::{tempdir, NamedTempFile};
|
||||
use tempfile::NamedTempFile;
|
||||
|
||||
// Integration tests for the diffutils command
|
||||
|
||||
@@ -19,7 +18,7 @@ fn unknown_param() -> Result<(), Box<dyn std::error::Error>> {
|
||||
cmd.assert()
|
||||
.code(predicate::eq(2))
|
||||
.failure()
|
||||
.stderr(predicate::str::starts_with("Unknown option: \"--foobar\""));
|
||||
.stderr(predicate::str::starts_with("Usage: "));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -27,26 +26,22 @@ fn unknown_param() -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn cannot_read_files() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let file = NamedTempFile::new()?;
|
||||
|
||||
let nofile = NamedTempFile::new()?;
|
||||
let nopath = nofile.into_temp_path();
|
||||
std::fs::remove_file(&nopath)?;
|
||||
|
||||
let mut cmd = Command::cargo_bin("diffutils")?;
|
||||
cmd.arg(&nopath).arg(file.path());
|
||||
cmd.arg("foo.txt").arg(file.path());
|
||||
cmd.assert()
|
||||
.code(predicate::eq(2))
|
||||
.failure()
|
||||
.stderr(predicate::str::starts_with("Failed to read from-file"));
|
||||
|
||||
let mut cmd = Command::cargo_bin("diffutils")?;
|
||||
cmd.arg(file.path()).arg(&nopath);
|
||||
cmd.arg(file.path()).arg("foo.txt");
|
||||
cmd.assert()
|
||||
.code(predicate::eq(2))
|
||||
.failure()
|
||||
.stderr(predicate::str::starts_with("Failed to read to-file"));
|
||||
|
||||
let mut cmd = Command::cargo_bin("diffutils")?;
|
||||
cmd.arg(&nopath).arg(&nopath);
|
||||
cmd.arg("foo.txt").arg("foo.txt");
|
||||
cmd.assert()
|
||||
.code(predicate::eq(2))
|
||||
.failure()
|
||||
@@ -239,49 +234,3 @@ fn read_from_stdin() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compare_file_to_directory() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let tmp_dir = tempdir()?;
|
||||
|
||||
let directory = tmp_dir.path().join("d");
|
||||
let _ = std::fs::create_dir(&directory);
|
||||
|
||||
let a_path = tmp_dir.path().join("a");
|
||||
let mut a = File::create(&a_path).unwrap();
|
||||
a.write_all(b"a\n").unwrap();
|
||||
|
||||
let da_path = directory.join("a");
|
||||
let mut da = File::create(&da_path).unwrap();
|
||||
da.write_all(b"da\n").unwrap();
|
||||
|
||||
let mut cmd = Command::cargo_bin("diffutils")?;
|
||||
cmd.arg("-u").arg(&directory).arg(&a_path);
|
||||
cmd.assert().code(predicate::eq(1)).failure();
|
||||
|
||||
let output = cmd.output().unwrap().stdout;
|
||||
assert_diff_eq!(
|
||||
output,
|
||||
format!(
|
||||
"--- {}\tTIMESTAMP\n+++ {}\tTIMESTAMP\n@@ -1 +1 @@\n-da\n+a\n",
|
||||
da_path.display(),
|
||||
a_path.display()
|
||||
)
|
||||
);
|
||||
|
||||
let mut cmd = Command::cargo_bin("diffutils")?;
|
||||
cmd.arg("-u").arg(&a_path).arg(&directory);
|
||||
cmd.assert().code(predicate::eq(1)).failure();
|
||||
|
||||
let output = cmd.output().unwrap().stdout;
|
||||
assert_diff_eq!(
|
||||
output,
|
||||
format!(
|
||||
"--- {}\tTIMESTAMP\n+++ {}\tTIMESTAMP\n@@ -1 +1 @@\n-a\n+da\n",
|
||||
a_path.display(),
|
||||
da_path.display()
|
||||
)
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
# By default it expects a release build of the diffutils binary, but a
|
||||
# different build profile can be specified as an argument
|
||||
# (e.g. 'dev' or 'test').
|
||||
# Unless overridden by the $TESTS environment variable, all tests in the test
|
||||
# Unless overriden by the $TESTS environment variable, all tests in the test
|
||||
# suite will be run. Tests targeting a command that is not yet implemented
|
||||
# (e.g. cmp, diff3 or sdiff) are skipped.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user