Skip to content

Commit f811086

Browse files
committed
fix: tests obscured by workspace changes
1 parent 22bb891 commit f811086

9 files changed

Lines changed: 69 additions & 39 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ members = [
1616
"src/uucore/",
1717
]
1818

19+
default-members = [
20+
"src/uu/*",
21+
"src/uucore/",
22+
]
23+
1924
[workspace.dependencies]
2025
uucore = { path = "src/uucore" }
2126
chrono = "0.4.38"
@@ -24,6 +29,8 @@ itoa = "1.0.11"
2429
regex = "1.10.4"
2530
same-file = "1.0.6"
2631
unicode-width = "0.2.0"
32+
pretty_assertions = "1.4.0"
33+
tempfile = "3.26.0"
2734

2835
[workspace.package]
2936
categories = ["command-line-utilities"]
@@ -47,17 +54,16 @@ diff = { workspace = true }
4754
same-file = { workspace = true }
4855
regex = { workspace = true }
4956
unicode-width = { workspace = true }
57+
tempfile = { workspace = true }
5058
uu_cmp = { path = "src/uu/cmp" }
5159
uu_diff = { path = "src/uu/diff" }
5260
uucore = { path = "src/uucore" }
5361

5462
[dev-dependencies]
5563
assert_cmd = "2.0.14"
5664
divan = { version = "5.0.0", package = "codspeed-divan-compat" }
57-
pretty_assertions = "1.4.0"
5865
predicates = "3.1.0"
5966
rand = "0.10.0"
60-
tempfile = "3.26.0"
6167

6268
[profile.release]
6369
lto = "thin"

src/uu/diff/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@ same-file = { workspace = true }
1414
diff = { workspace = true }
1515
unicode-width = { workspace = true }
1616

17+
[dev-dependencies]
18+
pretty_assertions = { workspace = true }
19+
regex = { workspace = true }
20+
uucore = { workspace = true, features = ["test-utils"] }
21+
1722
[lib]
1823
path = "./src/diff.rs"

src/uu/diff/src/context_diff.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ mod tests {
381381
use super::*;
382382
use pretty_assertions::assert_eq;
383383

384-
use crate::utils::testcmds::PATCH_CMD;
384+
use uucore::utils::testcmds::PATCH_CMD;
385385

386386
#[test]
387387
fn test_permutations() {
388388
// test all possible six-line files.
389-
let target = "target/context-diff/";
389+
let target = "../../../target/context-diff/";
390390
let _ = std::fs::create_dir(target);
391391
for &a in &[0, 1, 2] {
392392
for &b in &[0, 1, 2] {
@@ -453,7 +453,8 @@ mod tests {
453453
let _ = fb;
454454
let output = PATCH_CMD
455455
.new()
456-
.arg("-p0")
456+
.arg("-d")
457+
.arg(&format!("{target}"))
457458
.arg("--context")
458459
.stdin(File::open(format!("{target}/ab.diff")).unwrap())
459460
.output()
@@ -473,7 +474,7 @@ mod tests {
473474

474475
#[test]
475476
fn test_permutations_empty_lines() {
476-
let target = "target/context-diff/";
477+
let target = "../../../target/context-diff/";
477478
// test all possible six-line files with missing newlines.
478479
let _ = std::fs::create_dir(target);
479480
for &a in &[0, 1, 2] {
@@ -535,7 +536,8 @@ mod tests {
535536
let _ = fb;
536537
let output = PATCH_CMD
537538
.new()
538-
.arg("-p0")
539+
.arg("-d")
540+
.arg(&format!("{target}"))
539541
.arg("--context")
540542
.stdin(File::open(format!("{target}/ab_.diff")).unwrap())
541543
.output()
@@ -555,7 +557,7 @@ mod tests {
555557

556558
#[test]
557559
fn test_permutations_missing_lines() {
558-
let target = "target/context-diff/";
560+
let target = "../../../target/context-diff/";
559561
// test all possible six-line files.
560562
let _ = std::fs::create_dir(target);
561563
for &a in &[0, 1, 2] {
@@ -620,7 +622,8 @@ mod tests {
620622
let _ = fb;
621623
let output = PATCH_CMD
622624
.new()
623-
.arg("-p0")
625+
.arg("-d")
626+
.arg(&format!("{target}"))
624627
.arg("--context")
625628
.stdin(File::open(format!("{target}/abx.diff")).unwrap())
626629
.output()
@@ -640,7 +643,7 @@ mod tests {
640643

641644
#[test]
642645
fn test_permutations_reverse() {
643-
let target = "target/context-diff/";
646+
let target = "../../../target/context-diff/";
644647
// test all possible six-line files.
645648
let _ = std::fs::create_dir(target);
646649
for &a in &[0, 1, 2] {
@@ -708,7 +711,8 @@ mod tests {
708711
let _ = fb;
709712
let output = PATCH_CMD
710713
.new()
711-
.arg("-p0")
714+
.arg("-d")
715+
.arg(&format!("{target}"))
712716
.arg("--context")
713717
.stdin(File::open(format!("{target}/abr.diff")).unwrap())
714718
.output()
@@ -728,7 +732,7 @@ mod tests {
728732

729733
#[test]
730734
fn test_stop_early() {
731-
use crate::assert_diff_eq;
735+
use uucore::assert_diff_eq;
732736

733737
let from_filename = "foo";
734738
let from = ["a", "b", "c", ""].join("\n");

src/uu/diff/src/ed_diff.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ mod tests {
163163
use super::*;
164164
use pretty_assertions::assert_eq;
165165

166-
use crate::utils::testcmds::ED_CMD;
166+
use uucore::utils::testcmds::ED_CMD;
167167

168168
pub fn diff_w(expected: &[u8], actual: &[u8], filename: &str) -> Result<Vec<u8>, DiffError> {
169169
let mut output = diff(expected, actual, &Params::default())?;
@@ -182,7 +182,7 @@ mod tests {
182182

183183
#[test]
184184
fn test_permutations() {
185-
let target = "target/ed-diff/";
185+
let target = "../../../target/ed-diff/";
186186
// test all possible six-line files.
187187
let _ = std::fs::create_dir(target);
188188
for &a in &[0, 1, 2] {
@@ -262,7 +262,7 @@ mod tests {
262262

263263
#[test]
264264
fn test_permutations_empty_lines() {
265-
let target = "target/ed-diff/";
265+
let target = "../../../target/ed-diff/";
266266
// test all possible six-line files with missing newlines.
267267
let _ = std::fs::create_dir(target);
268268
for &a in &[0, 1, 2] {
@@ -336,7 +336,7 @@ mod tests {
336336

337337
#[test]
338338
fn test_permutations_reverse() {
339-
let target = "target/ed-diff/";
339+
let target = "../../../target/ed-diff/";
340340
// test all possible six-line files.
341341
let _ = std::fs::create_dir(target);
342342
for &a in &[0, 1, 2] {

src/uu/diff/src/normal_diff.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ mod tests {
215215
use super::*;
216216
use pretty_assertions::assert_eq;
217217

218-
use crate::utils::testcmds::PATCH_CMD;
218+
use uucore::utils::testcmds::PATCH_CMD;
219219

220220
#[test]
221221
fn test_basic() {
@@ -230,7 +230,7 @@ mod tests {
230230

231231
#[test]
232232
fn test_permutations() {
233-
let target = "target/normal-diff/";
233+
let target = "../../../target/normal-diff/";
234234
// test all possible six-line files.
235235
let _ = std::fs::create_dir(target);
236236
for &a in &[0, 1, 2] {
@@ -308,7 +308,7 @@ mod tests {
308308

309309
#[test]
310310
fn test_permutations_missing_line_ending() {
311-
let target = "target/normal-diff/";
311+
let target = "../../../target/normal-diff/";
312312
// test all possible six-line files with missing newlines.
313313
let _ = std::fs::create_dir(target);
314314
for &a in &[0, 1, 2] {
@@ -402,7 +402,7 @@ mod tests {
402402

403403
#[test]
404404
fn test_permutations_empty_lines() {
405-
let target = "target/normal-diff/";
405+
let target = "../../../target/normal-diff/";
406406
// test all possible six-line files with missing newlines.
407407
let _ = std::fs::create_dir(target);
408408
for &a in &[0, 1, 2] {
@@ -474,7 +474,7 @@ mod tests {
474474

475475
#[test]
476476
fn test_permutations_reverse() {
477-
let target = "target/normal-diff/";
477+
let target = "../../../target/normal-diff/";
478478
// test all possible six-line files.
479479
let _ = std::fs::create_dir(target);
480480
for &a in &[0, 1, 2] {

src/uu/diff/src/unified_diff.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,11 @@ mod tests {
407407
use super::*;
408408
use pretty_assertions::assert_eq;
409409

410-
use crate::utils::testcmds::PATCH_CMD;
410+
use uucore::utils::testcmds::PATCH_CMD;
411411

412412
#[test]
413413
fn test_permutations() {
414-
let target = "target/unified-diff/";
414+
let target = "../../../target/unified-diff/";
415415
// test all possible six-line files.
416416
let _ = std::fs::create_dir(target);
417417
for &a in &[0, 1, 2] {
@@ -493,11 +493,12 @@ mod tests {
493493
.unwrap_or_else(|_| String::from("[Invalid UTF-8]"))
494494
);
495495

496-
use crate::utils::testcmds::PATCH_CMD;
496+
use uucore::utils::testcmds::PATCH_CMD;
497497

498498
let output = PATCH_CMD
499499
.new()
500-
.arg("-p0")
500+
.arg("-d")
501+
.arg(&format!("{target}"))
501502
.stdin(File::open(format!("{target}/ab.diff")).unwrap())
502503
.output()
503504
.unwrap();
@@ -516,7 +517,7 @@ mod tests {
516517

517518
#[test]
518519
fn test_permutations_missing_line_ending() {
519-
let target = "target/unified-diff/";
520+
let target = "../../../target/unified-diff/";
520521
// test all possible six-line files with missing newlines.
521522
let _ = std::fs::create_dir(target);
522523
for &a in &[0, 1, 2] {
@@ -598,7 +599,8 @@ mod tests {
598599
let _ = fb;
599600
let output = PATCH_CMD
600601
.new()
601-
.arg("-p0")
602+
.arg("-d")
603+
.arg(&format!("{target}"))
602604
.stdin(File::open(format!("{target}/abn.diff")).unwrap())
603605
.output()
604606
.unwrap();
@@ -618,7 +620,7 @@ mod tests {
618620

619621
#[test]
620622
fn test_permutations_empty_lines() {
621-
let target = "target/unified-diff/";
623+
let target = "../../../target/unified-diff/";
622624
// test all possible six-line files with missing newlines.
623625
let _ = std::fs::create_dir(target);
624626
for &a in &[0, 1, 2] {
@@ -695,7 +697,8 @@ mod tests {
695697
let _ = fb;
696698
let output = PATCH_CMD
697699
.new()
698-
.arg("-p0")
700+
.arg("-d")
701+
.arg(&format!("{target}"))
699702
.stdin(File::open(format!("{target}/ab_.diff")).unwrap())
700703
.output()
701704
.unwrap();
@@ -715,7 +718,7 @@ mod tests {
715718

716719
#[test]
717720
fn test_permutations_missing_lines() {
718-
let target = "target/unified-diff/";
721+
let target = "../../../target/unified-diff/";
719722
// test all possible six-line files.
720723
let _ = std::fs::create_dir(target);
721724
for &a in &[0, 1, 2] {
@@ -777,7 +780,8 @@ mod tests {
777780
let _ = fb;
778781
let output = PATCH_CMD
779782
.new()
780-
.arg("-p0")
783+
.arg("-d")
784+
.arg(&format!("{target}"))
781785
.stdin(File::open(format!("{target}/abx.diff")).unwrap())
782786
.output()
783787
.unwrap();
@@ -796,7 +800,7 @@ mod tests {
796800

797801
#[test]
798802
fn test_permutations_reverse() {
799-
let target = "target/unified-diff/";
803+
let target = "../../../target/unified-diff/";
800804
// test all possible six-line files.
801805
let _ = std::fs::create_dir(target);
802806
for &a in &[0, 1, 2] {
@@ -864,7 +868,8 @@ mod tests {
864868
let _ = fb;
865869
let output = PATCH_CMD
866870
.new()
867-
.arg("-p0")
871+
.arg("-d")
872+
.arg(&format!("{target}"))
868873
.stdin(File::open(format!("{target}/abr.diff")).unwrap())
869874
.output()
870875
.unwrap();
@@ -883,7 +888,7 @@ mod tests {
883888

884889
#[test]
885890
fn test_stop_early() {
886-
use crate::assert_diff_eq;
891+
use uucore::assert_diff_eq;
887892

888893
let from_filename = "foo";
889894
let from = ["a", "b", "c", ""].join("\n");

src/uucore/Cargo.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ license.workspace = true
99
version.workspace = true
1010

1111
[dependencies]
12-
chrono = "0.4.38"
13-
regex = "1.10.4"
14-
unicode-width = "0.2.0"
12+
chrono = { workspace = true }
13+
regex = { workspace = true }
14+
unicode-width = { workspace = true }
15+
16+
[dev-dependencies]
17+
pretty_assertions = { workspace = true }
18+
tempfile = { workspace = true }
19+
20+
[features]
21+
test-utils = []

src/uucore/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn report_failure_to_read_input_file(
9898
);
9999
}
100100

101-
#[cfg(test)]
101+
#[cfg(feature = "test-utils")]
102102
pub mod testcmds {
103103
// Command construction wrapper that provides some validation and non-obscure, "fail fast"
104104
// feedback and error messages.

0 commit comments

Comments
 (0)