diff --git a/Cargo.lock b/Cargo.lock index 42a83504fb..991cc8ef51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -115,6 +115,15 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +[[package]] +name = "anstyle-lossy" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f45c79b3b9413932fc255f2c19ca0d48eaab72c4ea1913bafaebf289cbc099f2" +dependencies = [ + "anstyle", +] + [[package]] name = "anstyle-parse" version = "0.2.4" @@ -133,6 +142,19 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "anstyle-svg" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "962f6d5681926dbe5503b71057202d6723a33abe464c983b1d160bca3095a3bb" +dependencies = [ + "anstream", + "anstyle", + "anstyle-lossy", + "html-escape", + "unicode-width", +] + [[package]] name = "anstyle-wincon" version = "3.0.3" @@ -1131,6 +1153,7 @@ dependencies = [ "serde", "shellexpand", "simplelog", + "snapbox", "struct-patch", "syntect", "tempfile", @@ -1687,6 +1710,15 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "html-escape" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1ad449764d627e22bfd7cd5e8868264fc9236e07c752972b4080cd351cb476" +dependencies = [ + "utf8-width", +] + [[package]] name = "humantime" version = "2.1.0" @@ -2025,6 +2057,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + [[package]] name = "notify" version = "6.1.1" @@ -2185,6 +2223,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "os_pipe" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ffd2b0a5634335b135d5728d84c5e0fd726954b87111f7506a61c502280d982" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "p256" version = "0.13.2" @@ -2820,6 +2868,12 @@ dependencies = [ "rand_core", ] +[[package]] +name = "similar" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1de1d4f81173b03af4c0cbed3c898f6bff5b870e4a7f5d6f4057d62a7a4b686e" + [[package]] name = "simplelog" version = "0.12.2" @@ -2851,6 +2905,34 @@ version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" +[[package]] +name = "snapbox" +version = "0.6.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "027c936207f85d10d015e21faf5c676c7e08c453ed371adf55c0874c443ca77a" +dependencies = [ + "anstream", + "anstyle", + "anstyle-svg", + "libc", + "normalize-line-endings", + "os_pipe", + "serde_json", + "similar", + "snapbox-macros", + "wait-timeout", + "windows-sys 0.52.0", +] + +[[package]] +name = "snapbox-macros" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16569f53ca23a41bb6f62e0a5084aa1661f4814a67fa33696a79073e03a664af" +dependencies = [ + "anstream", +] + [[package]] name = "spin" version = "0.9.8" @@ -3217,6 +3299,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8-width" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86bd8d4e895da8537e5315b8254664e6b769c4ff3db18321b297a1e7004392e3" + [[package]] name = "utf8parse" version = "0.2.2" @@ -3235,6 +3323,15 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + [[package]] name = "walkdir" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index 7063d95ddb..0702b92a23 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,6 +67,7 @@ which = "6.0" [dev-dependencies] env_logger = "0.11" pretty_assertions = "1.4" +snapbox = { version = "0.6.16", features = ["cmd", "term-svg"] } tempfile = "3" [build-dependencies] diff --git a/tests/fixtures/empty_dir.svg b/tests/fixtures/empty_dir.svg new file mode 100644 index 0000000000..8f026cc663 --- /dev/null +++ b/tests/fixtures/empty_dir.svg @@ -0,0 +1,27 @@ + + + + + + + invalid path + + please run gitui inside of a non-bare git repository + + + + + + diff --git a/tests/ui.rs b/tests/ui.rs new file mode 100644 index 0000000000..07cf7d93d0 --- /dev/null +++ b/tests/ui.rs @@ -0,0 +1,21 @@ +use std::path::Path; + +use snapbox::{ + cmd::{cargo_bin, Command}, + data::DataFormat, + Data, +}; +use tempfile::TempDir; + +#[test] +fn test_empty_dir() { + let path: &Path = Path::new("tests/fixtures/empty_dir.svg"); + + let empty_dir = TempDir::new().unwrap(); + + Command::new(cargo_bin!("gitui")) + .current_dir(empty_dir.path()) + .assert() + .success() + .stderr_eq(Data::read_from(path, Some(DataFormat::TermSvg))); +}