Skip to content

Commit b62b996

Browse files
committed
ln: add some tests
1 parent b8fd24e commit b62b996

4 files changed

Lines changed: 85 additions & 10 deletions

File tree

Cargo.lock

Lines changed: 17 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ version = "0.8.0"
386386

387387
[workspace.dependencies]
388388
ansi-width = "0.1.0"
389+
assert_matches = "1.5.0"
389390
bigdecimal = "0.4"
390391
binary-heap-plus = "0.5.0"
391392
bstr = "1.9.1"

src/uu/ln/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ uucore = { workspace = true, features = ["backup-control", "fs"] }
2525
thiserror = { workspace = true }
2626
fluent = { workspace = true }
2727

28+
[dev-dependencies]
29+
assert_matches = { workspace = true }
30+
2831
[[bin]]
2932
name = "ln"
3033
path = "src/main.rs"

src/uu/ln/src/ln.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,67 @@ fn symlink<P1: AsRef<Path>, P2: AsRef<Path>>(_src: P1, _dst: P2) -> io::Result<(
536536
"symlinks not supported on this platform",
537537
))
538538
}
539+
540+
#[cfg(test)]
541+
mod tests {
542+
use super::*;
543+
use assert_matches::assert_matches;
544+
use std::ffi::OsString;
545+
546+
#[test]
547+
fn test_exec_missing_operand() {
548+
let settings: Settings = Settings {
549+
overwrite: OverwriteMode::NoClobber,
550+
backup: BackupMode::None,
551+
suffix: OsString::from(""),
552+
symbolic: false,
553+
relative: false,
554+
logical: false,
555+
target_dir: None,
556+
no_target_dir: false,
557+
no_dereference: false,
558+
verbose: false,
559+
};
560+
561+
let result = exec(&[], &settings);
562+
assert_matches!(result, Err(LnError::MissingOperand));
563+
}
564+
565+
#[test]
566+
fn test_exec_missing_destination() {
567+
let settings = Settings {
568+
overwrite: OverwriteMode::NoClobber,
569+
backup: BackupMode::None,
570+
suffix: OsString::from(""),
571+
symbolic: false,
572+
relative: false,
573+
logical: false,
574+
target_dir: None,
575+
no_target_dir: true,
576+
no_dereference: false,
577+
verbose: false,
578+
};
579+
580+
let result = exec(&["a".into()], &settings);
581+
assert_matches!(result, Err(LnError::MissingDestination(path)) if *path == *"a");
582+
}
583+
584+
#[test]
585+
fn test_exec_extra_operand() {
586+
let settings = Settings {
587+
overwrite: OverwriteMode::NoClobber,
588+
backup: BackupMode::None,
589+
suffix: OsString::from(""),
590+
symbolic: false,
591+
relative: false,
592+
logical: false,
593+
target_dir: None,
594+
no_target_dir: true,
595+
no_dereference: false,
596+
verbose: false,
597+
};
598+
599+
let result = exec(&["a".into(), "b".into(), "c".into()], &settings);
600+
assert_matches!(result, Err(LnError::ExtraOperand(operand, _)) if operand == "c");
601+
}
602+
}

0 commit comments

Comments
 (0)