diff --git a/Cargo.lock b/Cargo.lock index af7c96e5..6b9e321b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -264,15 +264,23 @@ name = "diffutils" version = "0.5.0" dependencies = [ "assert_cmd", - "chrono", "codspeed-divan-compat", - "diff", - "itoa", + "diffutils_core", "predicates", - "pretty_assertions", "rand", "regex", - "same-file", + "tempfile", + "uu_cmp", + "uu_diff", +] + +[[package]] +name = "diffutils_core" +version = "0.5.0" +dependencies = [ + "chrono", + "pretty_assertions", + "regex", "tempfile", "unicode-width", ] @@ -824,6 +832,27 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" +[[package]] +name = "uu_cmp" +version = "0.5.0" +dependencies = [ + "diffutils_core", + "itoa", + "same-file", +] + +[[package]] +name = "uu_diff" +version = "0.5.0" +dependencies = [ + "diff", + "diffutils_core", + "pretty_assertions", + "regex", + "same-file", + "unicode-width", +] + [[package]] name = "wait-timeout" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index ded812c8..0f19aace 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,47 @@ [package] name = "diffutils" -version = "0.5.0" -edition = "2021" description = "A CLI app for generating diff files" -license = "MIT OR Apache-2.0" +repository.workspace = true +edition.workspace = true +rust-version.workspace = true +version.workspace = true +license.workspace = true +homepage.workspace = true +keywords.workspace = true +categories.workspace = true + +[workspace] +members = [ + "src/uu/*", + "src/diffutils_core/", +] + +default-members = [ + ".", + "src/uu/*", + "src/diffutils_core/", +] + +[workspace.dependencies] +diffutils_core = { path = "src/diffutils_core" } +chrono = "0.4.38" +diff = "0.1.13" +itoa = "1.0.11" +regex = "1.10.4" +same-file = "1.0.6" +unicode-width = "0.2.0" +pretty_assertions = "1.4.0" +tempfile = "3.26.0" + +[workspace.package] +categories = ["command-line-utilities"] +edition = "2021" +rust-version = "1.87.0" +homepage = "https://github.com/uutils/diffutils" repository = "https://github.com/uutils/diffutils" +keywords = ["diffutils", "uutils", "cross-platform", "cli", "utility"] +license = "MIT OR Apache-2.0" +version = "0.5.0" [lib] name = "diffutilslib" @@ -15,20 +52,17 @@ name = "diffutils" path = "src/main.rs" [dependencies] -chrono = "0.4.38" -diff = "0.1.13" -itoa = "1.0.11" -regex = "1.10.4" -same-file = "1.0.6" -unicode-width = "0.2.0" +uu_cmp = { path = "src/uu/cmp" } +uu_diff = { path = "src/uu/diff" } +diffutils_core = { workspace = true } [dev-dependencies] assert_cmd = "2.0.14" divan = { version = "5.0.0", package = "codspeed-divan-compat" } -pretty_assertions = "1.4.0" predicates = "3.1.0" rand = "0.10.0" -tempfile = "3.26.0" +regex = { workspace = true } +tempfile = { workspace = true } [profile.release] lto = "thin" diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 47a03af4..5f3196d6 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -32,6 +32,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +[[package]] +name = "bitflags" +version = "2.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b588b76d00fde79687d7646a9b5bdf3cc0f655e0bbd080335a95d7e96f3587da" + [[package]] name = "bumpalo" version = "3.20.2" @@ -85,14 +91,41 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" name = "diffutils" version = "0.5.0" dependencies = [ - "chrono", "diff", - "itoa", + "diffutils_core", "regex", "same-file", + "tempfile", "unicode-width", + "uu_cmp", + "uu_diff", ] +[[package]] +name = "diffutils_core" +version = "0.5.0" +dependencies = [ + "chrono", + "regex", + "unicode-width", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + [[package]] name = "find-msvc-tools" version = "0.1.9" @@ -177,6 +210,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + [[package]] name = "log" version = "0.4.29" @@ -257,6 +296,19 @@ version = "0.8.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc897dd8d9e8bd1ed8cdad82b5966c3e0ecae09fb1907d58efaa013543185d0a" +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustversion" version = "1.0.22" @@ -289,6 +341,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom", + "once_cell", + "rustix", + "windows-sys", +] + [[package]] name = "unicode-ident" version = "1.0.24" @@ -309,6 +374,25 @@ dependencies = [ "libfuzzer-sys", ] +[[package]] +name = "uu_cmp" +version = "0.5.0" +dependencies = [ + "diffutils_core", + "itoa", + "same-file", +] + +[[package]] +name = "uu_diff" +version = "0.5.0" +dependencies = [ + "diff", + "diffutils_core", + "same-file", + "unicode-width", +] + [[package]] name = "wasip2" version = "1.0.2+wasi-0.2.9" diff --git a/src/diffutils_core/Cargo.toml b/src/diffutils_core/Cargo.toml new file mode 100644 index 00000000..9b7b693c --- /dev/null +++ b/src/diffutils_core/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "diffutils_core" +description = "diffutils ~ code shared by the diffutils utilities" +categories.workspace = true +edition.workspace = true +rust-version.workspace = true +homepage.workspace = true +repository.workspace = true +keywords.workspace = true +license.workspace = true +version.workspace = true + +[dependencies] +chrono = { workspace = true } +regex = { workspace = true } +unicode-width = { workspace = true } + +[dev-dependencies] +pretty_assertions = { workspace = true } +tempfile = { workspace = true } + +[features] +test-utils = [] diff --git a/src/diffutils_core/LICENSE-APACHE b/src/diffutils_core/LICENSE-APACHE new file mode 120000 index 00000000..1cd601d0 --- /dev/null +++ b/src/diffutils_core/LICENSE-APACHE @@ -0,0 +1 @@ +../../LICENSE-APACHE \ No newline at end of file diff --git a/src/diffutils_core/LICENSE-MIT b/src/diffutils_core/LICENSE-MIT new file mode 120000 index 00000000..b2cfbdc7 --- /dev/null +++ b/src/diffutils_core/LICENSE-MIT @@ -0,0 +1 @@ +../../LICENSE-MIT \ No newline at end of file diff --git a/src/diffutils_core/src/lib.rs b/src/diffutils_core/src/lib.rs new file mode 100644 index 00000000..6652316c --- /dev/null +++ b/src/diffutils_core/src/lib.rs @@ -0,0 +1,6 @@ +pub mod macros; +pub mod params; +pub mod utils; + +pub use params::*; +pub use utils::*; diff --git a/src/macros.rs b/src/diffutils_core/src/macros.rs similarity index 100% rename from src/macros.rs rename to src/diffutils_core/src/macros.rs diff --git a/src/params.rs b/src/diffutils_core/src/params.rs similarity index 100% rename from src/params.rs rename to src/diffutils_core/src/params.rs diff --git a/src/utils.rs b/src/diffutils_core/src/utils.rs similarity index 99% rename from src/utils.rs rename to src/diffutils_core/src/utils.rs index d9415afd..218cef50 100644 --- a/src/utils.rs +++ b/src/diffutils_core/src/utils.rs @@ -98,7 +98,7 @@ pub fn report_failure_to_read_input_file( ); } -#[cfg(test)] +#[cfg(feature = "test-utils")] pub mod testcmds { // Command construction wrapper that provides some validation and non-obscure, "fail fast" // feedback and error messages. diff --git a/src/lib.rs b/src/lib.rs index 342b01ca..5596f9be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,16 +1,7 @@ -pub mod cmp; -pub mod context_diff; -pub mod ed_diff; -pub mod macros; -pub mod normal_diff; -pub mod params; -pub mod side_diff; -pub mod unified_diff; -pub mod utils; - // Re-export the public functions/types you need -pub use context_diff::diff as context_diff; -pub use ed_diff::diff as ed_diff; -pub use normal_diff::diff as normal_diff; -pub use side_diff::diff as side_by_side_diff; -pub use unified_diff::diff as unified_diff; +pub use diffutils_core::*; +pub use uu_cmp as cmp; +pub use uu_diff::ed_diff; +pub use uu_diff::normal_diff; +pub use uu_diff::side_diff; +pub use uu_diff::unified_diff; diff --git a/src/main.rs b/src/main.rs index d0adb692..f3bbc040 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,17 +11,6 @@ use std::{ process::ExitCode, }; -mod cmp; -mod context_diff; -mod diff; -mod ed_diff; -mod macros; -mod normal_diff; -mod params; -mod side_diff; -mod unified_diff; -mod utils; - /// # Panics /// Panics if the binary path cannot be determined fn binary_path(args: &mut Peekable) -> PathBuf { @@ -70,8 +59,8 @@ fn main() -> ExitCode { }; match util_name.as_encoded_bytes() { - name if name.ends_with(b"diff") => diff::main(args), - name if name.ends_with(b"cmp") => cmp::main(args), + name if name.ends_with(b"diff") => uu_diff::main(args), + name if name.ends_with(b"cmp") => uu_cmp::main(args), name => { use std::io::{stderr, Write as _}; let _ = writeln!( diff --git a/src/uu/cmp/Cargo.toml b/src/uu/cmp/Cargo.toml new file mode 100644 index 00000000..76b20b3b --- /dev/null +++ b/src/uu/cmp/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "uu_cmp" +description = "diffutils ~ implementation of the cmp utility" +categories.workspace = true +edition.workspace = true +rust-version.workspace = true +homepage.workspace = true +repository.workspace = true +keywords.workspace = true +license.workspace = true +version.workspace = true + +[dependencies] +diffutils_core = { workspace = true } +itoa = { workspace = true } +same-file = { workspace = true } + +[lib] +path = "./src/cmp.rs" diff --git a/src/uu/cmp/LICENSE-APACHE b/src/uu/cmp/LICENSE-APACHE new file mode 120000 index 00000000..6e2b1da8 --- /dev/null +++ b/src/uu/cmp/LICENSE-APACHE @@ -0,0 +1 @@ +../../../LICENSE-APACHE \ No newline at end of file diff --git a/src/uu/cmp/LICENSE-MIT b/src/uu/cmp/LICENSE-MIT new file mode 120000 index 00000000..98cefa6a --- /dev/null +++ b/src/uu/cmp/LICENSE-MIT @@ -0,0 +1 @@ +../../../LICENSE-MIT \ No newline at end of file diff --git a/src/cmp.rs b/src/uu/cmp/src/cmp.rs similarity index 99% rename from src/cmp.rs rename to src/uu/cmp/src/cmp.rs index 0f7250c0..e5c2c895 100644 --- a/src/cmp.rs +++ b/src/uu/cmp/src/cmp.rs @@ -3,7 +3,7 @@ // For the full copyright and license information, please view the LICENSE-* // files that was distributed with this source code. -use crate::utils::format_failure_to_read_input_file; +use diffutils_core::utils::format_failure_to_read_input_file; use std::env::{self, ArgsOs}; use std::ffi::OsString; use std::io::{BufRead, BufReader, BufWriter, Read, Write}; diff --git a/src/uu/diff/Cargo.toml b/src/uu/diff/Cargo.toml new file mode 100644 index 00000000..990ebba7 --- /dev/null +++ b/src/uu/diff/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "uu_diff" +description = "diffutils ~ implementation of the diff utility" +categories.workspace = true +edition.workspace = true +rust-version.workspace = true +homepage.workspace = true +repository.workspace = true +keywords.workspace = true +license.workspace = true +version.workspace = true + +[dependencies] +diffutils_core = { workspace = true } +same-file = { workspace = true } +diff = { workspace = true } +unicode-width = { workspace = true } + +[dev-dependencies] +pretty_assertions = { workspace = true } +regex = { workspace = true } +diffutils_core = { workspace = true, features = ["test-utils"] } + +[lib] +path = "./src/diff.rs" diff --git a/src/uu/diff/LICENSE-APACHE b/src/uu/diff/LICENSE-APACHE new file mode 120000 index 00000000..6e2b1da8 --- /dev/null +++ b/src/uu/diff/LICENSE-APACHE @@ -0,0 +1 @@ +../../../LICENSE-APACHE \ No newline at end of file diff --git a/src/uu/diff/LICENSE-MIT b/src/uu/diff/LICENSE-MIT new file mode 120000 index 00000000..98cefa6a --- /dev/null +++ b/src/uu/diff/LICENSE-MIT @@ -0,0 +1 @@ +../../../LICENSE-MIT \ No newline at end of file diff --git a/src/context_diff.rs b/src/uu/diff/src/context_diff.rs similarity index 97% rename from src/context_diff.rs rename to src/uu/diff/src/context_diff.rs index 7ddffea6..d2c136c9 100644 --- a/src/context_diff.rs +++ b/src/uu/diff/src/context_diff.rs @@ -6,9 +6,8 @@ use std::collections::VecDeque; use std::io::Write; -use crate::params::Params; -use crate::utils::do_write_line; -use crate::utils::get_modification_time; +use diffutils_core::params::Params; +use diffutils_core::utils::{do_write_line, get_modification_time}; #[derive(Debug, PartialEq)] pub enum DiffLine { @@ -382,12 +381,12 @@ mod tests { use super::*; use pretty_assertions::assert_eq; - use crate::utils::testcmds::PATCH_CMD; + use diffutils_core::utils::testcmds::PATCH_CMD; #[test] fn test_permutations() { // test all possible six-line files. - let target = "target/context-diff/"; + let target = "../../../target/context-diff/"; let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { for &b in &[0, 1, 2] { @@ -454,7 +453,8 @@ mod tests { let _ = fb; let output = PATCH_CMD .new() - .arg("-p0") + .arg("-d") + .arg(&format!("{target}")) .arg("--context") .stdin(File::open(format!("{target}/ab.diff")).unwrap()) .output() @@ -474,7 +474,7 @@ mod tests { #[test] fn test_permutations_empty_lines() { - let target = "target/context-diff/"; + let target = "../../../target/context-diff/"; // test all possible six-line files with missing newlines. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -536,7 +536,8 @@ mod tests { let _ = fb; let output = PATCH_CMD .new() - .arg("-p0") + .arg("-d") + .arg(&format!("{target}")) .arg("--context") .stdin(File::open(format!("{target}/ab_.diff")).unwrap()) .output() @@ -556,7 +557,7 @@ mod tests { #[test] fn test_permutations_missing_lines() { - let target = "target/context-diff/"; + let target = "../../../target/context-diff/"; // test all possible six-line files. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -621,7 +622,8 @@ mod tests { let _ = fb; let output = PATCH_CMD .new() - .arg("-p0") + .arg("-d") + .arg(&format!("{target}")) .arg("--context") .stdin(File::open(format!("{target}/abx.diff")).unwrap()) .output() @@ -641,7 +643,7 @@ mod tests { #[test] fn test_permutations_reverse() { - let target = "target/context-diff/"; + let target = "../../../target/context-diff/"; // test all possible six-line files. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -709,7 +711,8 @@ mod tests { let _ = fb; let output = PATCH_CMD .new() - .arg("-p0") + .arg("-d") + .arg(&format!("{target}")) .arg("--context") .stdin(File::open(format!("{target}/abr.diff")).unwrap()) .output() @@ -729,7 +732,7 @@ mod tests { #[test] fn test_stop_early() { - use crate::assert_diff_eq; + use diffutils_core::assert_diff_eq; let from_filename = "foo"; let from = ["a", "b", "c", ""].join("\n"); diff --git a/src/diff.rs b/src/uu/diff/src/diff.rs similarity index 93% rename from src/diff.rs rename to src/uu/diff/src/diff.rs index f4c0614c..01a50120 100644 --- a/src/diff.rs +++ b/src/uu/diff/src/diff.rs @@ -3,9 +3,14 @@ // For the full copyright and license information, please view the LICENSE-* // files that was distributed with this source code. -use crate::params::{parse_params, Format}; -use crate::utils::report_failure_to_read_input_file; -use crate::{context_diff, ed_diff, normal_diff, side_diff, unified_diff}; +pub mod context_diff; +pub mod ed_diff; +pub mod normal_diff; +pub mod side_diff; +pub mod unified_diff; + +use diffutils_core::params::{parse_params, Format}; +use diffutils_core::utils::report_failure_to_read_input_file; use std::env::ArgsOs; use std::ffi::OsString; use std::fs; diff --git a/src/ed_diff.rs b/src/uu/diff/src/ed_diff.rs similarity index 98% rename from src/ed_diff.rs rename to src/uu/diff/src/ed_diff.rs index 81ddfb46..3c21883d 100644 --- a/src/ed_diff.rs +++ b/src/uu/diff/src/ed_diff.rs @@ -5,8 +5,8 @@ use std::io::Write; -use crate::params::Params; -use crate::utils::do_write_line; +use diffutils_core::params::Params; +use diffutils_core::utils::do_write_line; #[derive(Debug, PartialEq)] struct Mismatch { @@ -163,7 +163,7 @@ mod tests { use super::*; use pretty_assertions::assert_eq; - use crate::utils::testcmds::ED_CMD; + use diffutils_core::utils::testcmds::ED_CMD; pub fn diff_w(expected: &[u8], actual: &[u8], filename: &str) -> Result, DiffError> { let mut output = diff(expected, actual, &Params::default())?; @@ -182,7 +182,7 @@ mod tests { #[test] fn test_permutations() { - let target = "target/ed-diff/"; + let target = "../../../target/ed-diff/"; // test all possible six-line files. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -262,7 +262,7 @@ mod tests { #[test] fn test_permutations_empty_lines() { - let target = "target/ed-diff/"; + let target = "../../../target/ed-diff/"; // test all possible six-line files with missing newlines. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -336,7 +336,7 @@ mod tests { #[test] fn test_permutations_reverse() { - let target = "target/ed-diff/"; + let target = "../../../target/ed-diff/"; // test all possible six-line files. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { diff --git a/src/normal_diff.rs b/src/uu/diff/src/normal_diff.rs similarity index 98% rename from src/normal_diff.rs rename to src/uu/diff/src/normal_diff.rs index 652dc84e..71aabe0f 100644 --- a/src/normal_diff.rs +++ b/src/uu/diff/src/normal_diff.rs @@ -5,8 +5,8 @@ use std::io::Write; -use crate::params::Params; -use crate::utils::do_write_line; +use diffutils_core::params::Params; +use diffutils_core::utils::do_write_line; #[derive(Debug, PartialEq)] struct Mismatch { @@ -215,7 +215,7 @@ mod tests { use super::*; use pretty_assertions::assert_eq; - use crate::utils::testcmds::PATCH_CMD; + use diffutils_core::utils::testcmds::PATCH_CMD; #[test] fn test_basic() { @@ -230,7 +230,7 @@ mod tests { #[test] fn test_permutations() { - let target = "target/normal-diff/"; + let target = "../../../target/normal-diff/"; // test all possible six-line files. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -308,7 +308,7 @@ mod tests { #[test] fn test_permutations_missing_line_ending() { - let target = "target/normal-diff/"; + let target = "../../../target/normal-diff/"; // test all possible six-line files with missing newlines. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -402,7 +402,7 @@ mod tests { #[test] fn test_permutations_empty_lines() { - let target = "target/normal-diff/"; + let target = "../../../target/normal-diff/"; // test all possible six-line files with missing newlines. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -474,7 +474,7 @@ mod tests { #[test] fn test_permutations_reverse() { - let target = "target/normal-diff/"; + let target = "../../../target/normal-diff/"; // test all possible six-line files. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { diff --git a/src/side_diff.rs b/src/uu/diff/src/side_diff.rs similarity index 99% rename from src/side_diff.rs rename to src/uu/diff/src/side_diff.rs index 56953d25..eed03cd5 100644 --- a/src/side_diff.rs +++ b/src/uu/diff/src/side_diff.rs @@ -8,7 +8,7 @@ use diff::Result; use std::{io::Write, vec}; use unicode_width::UnicodeWidthStr; -use crate::params::Params; +use diffutils_core::params::Params; const GUTTER_WIDTH_MIN: usize = 3; diff --git a/src/unified_diff.rs b/src/uu/diff/src/unified_diff.rs similarity index 97% rename from src/unified_diff.rs rename to src/uu/diff/src/unified_diff.rs index 27773b10..0dbc94d8 100644 --- a/src/unified_diff.rs +++ b/src/uu/diff/src/unified_diff.rs @@ -6,9 +6,8 @@ use std::collections::VecDeque; use std::io::Write; -use crate::params::Params; -use crate::utils::do_write_line; -use crate::utils::get_modification_time; +use diffutils_core::params::Params; +use diffutils_core::utils::{do_write_line, get_modification_time}; #[derive(Debug, PartialEq)] pub enum DiffLine { @@ -408,11 +407,11 @@ mod tests { use super::*; use pretty_assertions::assert_eq; - use crate::utils::testcmds::PATCH_CMD; + use diffutils_core::utils::testcmds::PATCH_CMD; #[test] fn test_permutations() { - let target = "target/unified-diff/"; + let target = "../../../target/unified-diff/"; // test all possible six-line files. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -494,11 +493,12 @@ mod tests { .unwrap_or_else(|_| String::from("[Invalid UTF-8]")) ); - use crate::utils::testcmds::PATCH_CMD; + use diffutils_core::utils::testcmds::PATCH_CMD; let output = PATCH_CMD .new() - .arg("-p0") + .arg("-d") + .arg(&format!("{target}")) .stdin(File::open(format!("{target}/ab.diff")).unwrap()) .output() .unwrap(); @@ -517,7 +517,7 @@ mod tests { #[test] fn test_permutations_missing_line_ending() { - let target = "target/unified-diff/"; + let target = "../../../target/unified-diff/"; // test all possible six-line files with missing newlines. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -599,7 +599,8 @@ mod tests { let _ = fb; let output = PATCH_CMD .new() - .arg("-p0") + .arg("-d") + .arg(&format!("{target}")) .stdin(File::open(format!("{target}/abn.diff")).unwrap()) .output() .unwrap(); @@ -619,7 +620,7 @@ mod tests { #[test] fn test_permutations_empty_lines() { - let target = "target/unified-diff/"; + let target = "../../../target/unified-diff/"; // test all possible six-line files with missing newlines. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -696,7 +697,8 @@ mod tests { let _ = fb; let output = PATCH_CMD .new() - .arg("-p0") + .arg("-d") + .arg(&format!("{target}")) .stdin(File::open(format!("{target}/ab_.diff")).unwrap()) .output() .unwrap(); @@ -716,7 +718,7 @@ mod tests { #[test] fn test_permutations_missing_lines() { - let target = "target/unified-diff/"; + let target = "../../../target/unified-diff/"; // test all possible six-line files. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -778,7 +780,8 @@ mod tests { let _ = fb; let output = PATCH_CMD .new() - .arg("-p0") + .arg("-d") + .arg(&format!("{target}")) .stdin(File::open(format!("{target}/abx.diff")).unwrap()) .output() .unwrap(); @@ -797,7 +800,7 @@ mod tests { #[test] fn test_permutations_reverse() { - let target = "target/unified-diff/"; + let target = "../../../target/unified-diff/"; // test all possible six-line files. let _ = std::fs::create_dir(target); for &a in &[0, 1, 2] { @@ -865,7 +868,8 @@ mod tests { let _ = fb; let output = PATCH_CMD .new() - .arg("-p0") + .arg("-d") + .arg(&format!("{target}")) .stdin(File::open(format!("{target}/abr.diff")).unwrap()) .output() .unwrap(); @@ -884,7 +888,7 @@ mod tests { #[test] fn test_stop_early() { - use crate::assert_diff_eq; + use diffutils_core::assert_diff_eq; let from_filename = "foo"; let from = ["a", "b", "c", ""].join("\n");