diff --git a/Cargo.lock b/Cargo.lock index ea9b5f5..8a0af8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,31 +3,59 @@ version = 3 [[package]] -name = "ansi_term" -version = "0.12.1" +name = "anstream" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" dependencies = [ - "winapi", + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "utf8parse", ] [[package]] -name = "anyhow" -version = "1.0.81" +name = "anstyle" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" [[package]] -name = "atty" -version = "0.2.14" +name = "anstyle-parse" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" dependencies = [ - "hermit-abi", - "libc", - "winapi", + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +dependencies = [ + "anstyle", + "windows-sys", ] +[[package]] +name = "anyhow" +version = "1.0.82" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" + [[package]] name = "autocfg" version = "1.2.0" @@ -54,77 +82,76 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "2.34.0" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim", - "textwrap", - "unicode-width", - "vec_map", + "clap_builder", + "clap_derive", ] [[package]] -name = "crossterm" -version = "0.27.0" +name = "clap_builder" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ - "bitflags 2.5.0", - "crossterm_winapi", - "libc", - "mio", - "parking_lot", - "signal-hook", - "signal-hook-mio", - "winapi", + "anstream", + "anstyle", + "clap_lex", + "strsim", ] [[package]] -name = "crossterm_winapi" -version = "0.9.1" +name = "clap_derive" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "winapi", + "heck", + "proc-macro2", + "quote", + "syn", ] [[package]] -name = "heck" -version = "0.3.3" +name = "clap_lex" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] -name = "hermit-abi" -version = "0.1.19" +name = "crossterm" +version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" dependencies = [ + "bitflags 2.5.0", "libc", + "parking_lot", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "homer" version = "0.2.3" dependencies = [ "anyhow", + "clap", "crossterm", - "structopt", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.153" @@ -141,24 +168,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - -[[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "log", - "wasi", - "windows-sys", -] - [[package]] name = "parking_lot" version = "0.12.1" @@ -179,31 +188,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", + "windows-targets 0.48.5", ] [[package]] @@ -217,9 +202,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -239,36 +224,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" -[[package]] -name = "signal-hook" -version = "0.3.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" -dependencies = [ - "libc", - "signal-hook-registry", -] - -[[package]] -name = "signal-hook-mio" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" -dependencies = [ - "libc", - "mio", - "signal-hook", -] - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - [[package]] name = "smallvec" version = "1.13.2" @@ -277,54 +232,21 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "strsim" -version = "0.8.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - -[[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "unicode-ident" version = "1.0.12" @@ -332,79 +254,48 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] -name = "unicode-segmentation" -version = "1.11.0" +name = "utf8parse" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] -name = "unicode-width" -version = "0.1.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" - -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "winapi" -version = "0.3.9" +name = "windows-sys" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", + "windows-targets 0.52.4", ] [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows-sys" -version = "0.48.0" +name = "windows-targets" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows-targets", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] name = "windows-targets" -version = "0.48.5" +version = "0.52.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[package]] @@ -413,38 +304,80 @@ version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" diff --git a/Cargo.toml b/Cargo.toml index 2a5eb6c..56d2143 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,6 @@ edition = "2018" publish = false [dependencies] -structopt = "0.3" anyhow = "1.0" -crossterm = "0.27" +crossterm = { version = "0.27", default-features = false } +clap = { version = "4.5.4", features = ["derive", "env"] } diff --git a/src/main.rs b/src/main.rs index 25e9a69..b15d799 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,39 +3,40 @@ use std::process::Command; use std::{fs, io, os::unix}; use anyhow::{anyhow, Context, Result}; +use clap::Parser; use crossterm::execute; use crossterm::style::{Attribute, Color, Print, SetAttribute, SetForegroundColor}; -use structopt::StructOpt; /// "Doh!" A CLI for managing your dotfiles! -#[derive(StructOpt)] -struct Opt { +#[derive(Parser, Debug)] +#[command(version, about)] +struct Args { /// Force the program to run without prompting for confirmation. - #[structopt(short, long)] + #[arg(short, long)] force: bool, /// Disable backup, an action plan will be created, when other files block /// symlink creation they will be deleted instead of moved to a safe backup /// location. - #[structopt(long = "no-backup")] + #[arg(long)] no_backup: bool, /// Directory containing scripts that will be run after the plan is completed. /// If force flag is passed, no confirmation prompt will be shown. - #[structopt(long, parse(from_os_str))] + #[arg(long)] scripts: Option, /// Directory containing files to link into user's home directory. - #[structopt(short, long, parse(from_os_str), default_value = "./home")] + #[arg(short, long, default_value = ".")] input: PathBuf, /// Directory the files will be linked to, defaults to $HOME. - #[structopt(short, long, parse(from_os_str), env = "HOME")] + #[structopt(short, long, env = "HOME")] output: PathBuf, } fn main() -> Result<()> { - let opt = Opt::from_args(); + let opt = Args::parse(); run_linking(opt.input, opt.output, !opt.no_backup, opt.force)?; @@ -201,6 +202,8 @@ impl Plan { anyhow::bail!("{:?} does not exist", path); } + let dest_exists_or_is_link = dest.exists() || std::fs::read_link(dest).is_ok(); + // When the current path denotes a directory, we should recurse into // it's entries and add them to the action plan accordingly. let mut children = Vec::new(); @@ -215,31 +218,55 @@ impl Plan { children.push(Plan::new(&entry.path(), &dest, backup)?); } + + if dest.is_dir() { + return Ok(Plan::Noop { + path: path.into(), + dest: dest.into(), + children, + }); + } else { + return Ok(Plan::Link { + path: path.into(), + dest: dest.into(), + backup, + replace: dest_exists_or_is_link, + }); + } } - // Check `path` and `dest` equality when both are directories. - let dir_equality = dest.exists() && path.is_dir() && dest.is_dir(); + // At this point we know that dest is a file and should have a parent. + let mut dest_parent = dest.parent().expect("dest to have a parent").to_path_buf(); + let canonicalized_dest = match std::fs::read_link(dest) { + Ok(dest) => { + if dest.is_absolute() { + dest.canonicalize().ok() + } else { + dest_parent.push(dest); + dest_parent.canonicalize().ok() + } + } + Err(_) => None, + }; - // When dealing with files, they will be equal if their `path`s canonicalized - // are equal, meaning that `dest` is a link to `path`. - let file_equality = - dest.exists() & path.is_file() && path.canonicalize()? == dest.canonicalize()?; + let canonicalized_path = path + .canonicalize() + .context(format!("failed to canonicalize {path:?}"))?; - // If they're equal, no action is needed. - if dir_equality || file_equality { - return Ok(Plan::Noop { + if canonicalized_dest.is_some() && canonicalized_dest.unwrap() == canonicalized_path { + Ok(Plan::Noop { path: path.into(), dest: dest.into(), children, - }); + }) + } else { + Ok(Plan::Link { + backup, + replace: dest_exists_or_is_link, + path: path.into(), + dest: dest.into(), + }) } - - Ok(Plan::Link { - backup, - path: path.into(), - dest: dest.into(), - replace: dest.exists(), - }) } /// Check if an action plan is empty, this is done by checking if the plan is `Plan::Noop`, @@ -369,6 +396,7 @@ mod tests { ); assert!(plan.is_err(), "input path should not exist"); } + #[test] fn missing_output() { let path: PathBuf = "./testdata/simple".into(); @@ -382,10 +410,10 @@ mod tests { backup, replace, }) => { - assert_eq!(p, path); - assert_eq!(d, dest); - assert!(!backup); - assert!(!replace); + assert_eq!(p, path, "the path should be the same as input"); + assert_eq!(d, dest, "the desitnation should be the new folder"); + assert!(!backup, "the input asked for no backup"); + assert!(!replace, "should not replace something that does not exist"); } _ => panic!("plan should be to link folder"), } @@ -409,7 +437,11 @@ mod tests { let plan = Plan::new(&path, &dest, false); assert!(plan.is_ok(), "everything should be fine"); - assert_eq!(plan.unwrap(), expected); + assert_eq!( + plan.unwrap(), + expected, + "the output should link, but not be replaced as it does not exist" + ); } #[test] @@ -429,7 +461,11 @@ mod tests { let plan = Plan::new(&path, &dest, false); assert!(plan.is_ok(), "everything should be fine"); - assert_eq!(plan.unwrap(), expected); + assert_eq!( + plan.unwrap(), + expected, + "the output should be noop, as the link already points to the input" + ); } #[test] @@ -450,7 +486,11 @@ mod tests { let plan = Plan::new(&path, &dest, false); assert!(plan.is_ok(), "everything should be fine"); - assert_eq!(plan.unwrap(), expected); + assert_eq!( + plan.unwrap(), + expected, + "the output should be replaced as it does not match the input" + ); } #[test] @@ -471,7 +511,11 @@ mod tests { let plan = Plan::new(&path, &dest, false); assert!(plan.is_ok(), "everything should be fine"); - assert_eq!(plan.unwrap(), expected); + assert_eq!( + plan.unwrap(), + expected, + "the output should be replaced as it does not match the input type" + ); } #[test] @@ -482,16 +526,29 @@ mod tests { let expected = Plan::Noop { path: path.clone(), dest: dest.clone(), - children: vec![Plan::Link { - path: path.join("different_link"), - dest: dest.join("different_link"), - backup: false, - replace: true, - }], + children: vec![ + Plan::Link { + path: path.join("different_link"), + dest: dest.join("different_link"), + backup: false, + replace: true, + }, + Plan::Link { + path: path.join("different_link_broken"), + dest: dest.join("different_link_broken"), + backup: false, + replace: true, + }, + ], }; let plan = Plan::new(&path, &dest, false); + println!("{:?}", plan); assert!(plan.is_ok(), "everything should be fine"); - assert_eq!(plan.unwrap(), expected); + assert_eq!( + plan.unwrap(), + expected, + "the output should be repalced in both cases as it does not link to the input" + ); } } diff --git a/testdata/different_link/different_link_broken b/testdata/different_link/different_link_broken new file mode 100644 index 0000000..e69de29 diff --git a/testdata/output/different_link_broken b/testdata/output/different_link_broken new file mode 120000 index 0000000..86a410d --- /dev/null +++ b/testdata/output/different_link_broken @@ -0,0 +1 @@ +broken \ No newline at end of file