From b6dadb440ac5fdfdf4f914edb1baebdcc488a166 Mon Sep 17 00:00:00 2001 From: Hannaeko <19394895+hannaeko@users.noreply.github.com> Date: Thu, 9 Apr 2026 16:04:42 +0200 Subject: [PATCH 01/55] wip: start reworking how the tests are structured --- .gitignore | 4 +- devtools/Dockerfile.tests | 26 +++++ docker-compose.yml | 14 +++ justfile | 8 +- tests/cli_tests.rs | 104 ++++++++++++++---- tests/cmd/absolute_file_all.stderr | 0 tests/cmd/absolute_file_all.stdout | 1 - tests/cmd/absolute_file_all.toml | 2 - tests/cmd/absolute_recurse_unix.stderr | 0 tests/cmd/absolute_recurse_unix.stdout | 50 --------- tests/cmd/absolute_recurse_unix.toml | 2 - tests/cmd/absolute_unix.stderr | 0 tests/cmd/absolute_unix.stdout | 22 ---- tests/cmd/absolute_unix.toml | 2 - tests/cmd/any/basic/help.toml | 89 +++++++++++++++ tests/cmd/any/basic/no_option.toml | 8 ++ .../any/no-git/fail_git_not_supported.toml | 7 ++ .../cmd/any/sort/extensions_ignore_dirs.toml | 13 +++ tests/cmd/basic_all.stderr | 0 tests/cmd/basic_all.stdout | 22 ---- tests/cmd/basic_all.toml | 2 - ...assify-hyperlink-width-50_nix_local.stderr | 0 ...assify-hyperlink-width-50_nix_local.stdout | 5 - tests/cmd/follow-symlinks_unix.stderr | 0 tests/cmd/follow-symlinks_unix.stdout | 40 ------- tests/cmd/follow-symlinks_unix.toml | 2 - tests/cmd/icons_all.stderr | 0 tests/cmd/icons_all.stdout | 22 ---- tests/cmd/icons_all.toml | 2 - tests/cmd/long_icons_always.stderr | 0 tests/cmd/long_icons_always.stdout | 21 ---- tests/cmd/long_icons_always.toml | 2 - tests/cmd/long_windows.stderr | 0 tests/cmd/long_windows.stdout | 22 ---- tests/cmd/long_windows.toml | 2 - tests/cmd/sort-ext-group-dirs-first.stderr | 0 tests/cmd/sort-ext-group-dirs-first.stdout | 1 - tests/cmd/sort-ext-group-dirs-first.toml | 2 - tests/cmd/sort-ext.stderr | 0 tests/cmd/sort-ext.stdout | 1 - tests/cmd/sort-ext.toml | 2 - tests/cmd/tree_unix.stderr | 0 tests/cmd/tree_unix.stdout | 37 ------- tests/cmd/tree_unix.toml | 2 - 44 files changed, 251 insertions(+), 288 deletions(-) create mode 100644 devtools/Dockerfile.tests create mode 100644 docker-compose.yml delete mode 100644 tests/cmd/absolute_file_all.stderr delete mode 100644 tests/cmd/absolute_file_all.stdout delete mode 100644 tests/cmd/absolute_file_all.toml delete mode 100644 tests/cmd/absolute_recurse_unix.stderr delete mode 100644 tests/cmd/absolute_recurse_unix.stdout delete mode 100644 tests/cmd/absolute_recurse_unix.toml delete mode 100644 tests/cmd/absolute_unix.stderr delete mode 100644 tests/cmd/absolute_unix.stdout delete mode 100644 tests/cmd/absolute_unix.toml create mode 100644 tests/cmd/any/basic/help.toml create mode 100644 tests/cmd/any/basic/no_option.toml create mode 100644 tests/cmd/any/no-git/fail_git_not_supported.toml create mode 100644 tests/cmd/any/sort/extensions_ignore_dirs.toml delete mode 100644 tests/cmd/basic_all.stderr delete mode 100644 tests/cmd/basic_all.stdout delete mode 100644 tests/cmd/basic_all.toml delete mode 100644 tests/cmd/classify-hyperlink-width-50_nix_local.stderr delete mode 100644 tests/cmd/classify-hyperlink-width-50_nix_local.stdout delete mode 100644 tests/cmd/follow-symlinks_unix.stderr delete mode 100644 tests/cmd/follow-symlinks_unix.stdout delete mode 100644 tests/cmd/follow-symlinks_unix.toml delete mode 100644 tests/cmd/icons_all.stderr delete mode 100644 tests/cmd/icons_all.stdout delete mode 100644 tests/cmd/icons_all.toml delete mode 100644 tests/cmd/long_icons_always.stderr delete mode 100644 tests/cmd/long_icons_always.stdout delete mode 100644 tests/cmd/long_icons_always.toml delete mode 100644 tests/cmd/long_windows.stderr delete mode 100644 tests/cmd/long_windows.stdout delete mode 100644 tests/cmd/long_windows.toml delete mode 100644 tests/cmd/sort-ext-group-dirs-first.stderr delete mode 100644 tests/cmd/sort-ext-group-dirs-first.stdout delete mode 100644 tests/cmd/sort-ext-group-dirs-first.toml delete mode 100644 tests/cmd/sort-ext.stderr delete mode 100644 tests/cmd/sort-ext.stdout delete mode 100644 tests/cmd/sort-ext.toml delete mode 100644 tests/cmd/tree_unix.stderr delete mode 100644 tests/cmd/tree_unix.stdout delete mode 100644 tests/cmd/tree_unix.toml diff --git a/.gitignore b/.gitignore index 52509262e..d59cc2456 100644 --- a/.gitignore +++ b/.gitignore @@ -36,8 +36,8 @@ stage out.gif tests/tmp -## Dynamically generated -tests/test_dir +## Dynamically generated test data +tests/data # Miscenallous .idea diff --git a/devtools/Dockerfile.tests b/devtools/Dockerfile.tests new file mode 100644 index 000000000..44719446d --- /dev/null +++ b/devtools/Dockerfile.tests @@ -0,0 +1,26 @@ +FROM ubuntu:latest + +# Install dependencies +RUN apt-get update && \ + apt-get -y install curl git sudo gcc locales + +COPY --from=ghcr.io/casey/just:latest /just /usr/local/bin/ + +# Generate locales +RUN sed -i '/fr_FR.UTF-8/s/^# //g' /etc/locale.gen && \ + sed -i '/ja_JP.UTF-8/s/^# //g' /etc/locale.gen && \ + locale-gen + +# Create working directories +RUN mkdir -p /workspace/target && \ + mkdir -p /workspace/tests/data && \ + chown -R ubuntu: /workspace + +USER ubuntu + +# Install Rust +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y + +ENV PATH=/home/ubuntu/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +WORKDIR /workspace diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..bf9188438 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +services: + tests: + image: eza-test-env:local + pull_policy: never + build: + context: ./devtools + dockerfile: Dockerfile.tests + volumes: + - ./:/workspace + - build_cache:/workspace/target + - test_data:/workspace/tests/data +volumes: + build_cache: + test_data: diff --git a/justfile b/justfile index ecf864cb0..2752701b7 100644 --- a/justfile +++ b/justfile @@ -44,6 +44,13 @@ genDemo: # run unit tests [group('testing')] @test: + docker compose run --build --rm tests just docker-tests + +# run unit tests +[group('testing')] +@docker-tests: + ./devtools/dir-generator.sh tests/data/test_dir + ./devtools/generate-timestamp-test-dir.sh tests/data/timestamp_test_dir cargo test --workspace -- --quiet # run unit tests (in release mode) @@ -351,4 +358,3 @@ gen_test_dir: powertest nix build -L ./#trydump find result/dump -type f \( -name "*.stdout" -o -name "*.stderr" \) -exec sh -c 'base=$(basename {}); if [ -e "tests/ptests/${base%.*}.toml" ]; then cp {} tests/ptests/; fi' \; - diff --git a/tests/cli_tests.rs b/tests/cli_tests.rs index 8fa1965f5..256470110 100644 --- a/tests/cli_tests.rs +++ b/tests/cli_tests.rs @@ -1,34 +1,100 @@ -#[test] -fn cli_all_tests() { - trycmd::TestCases::new().case("tests/cmd/*_all.toml"); +use std::fs; +use std::path; +use std::time::SystemTime; + +struct TransientDirectory { + path: path::PathBuf } -#[test] -#[cfg(unix)] -fn cli_unix_tests() { - trycmd::TestCases::new().case("tests/cmd/*_unix.toml"); +impl TransientDirectory { + fn create(platform: &str, group: &str) -> Self { + let path_str = format!("tests/data/{platform}/{group}"); + let path = path::PathBuf::from(&path_str); + fs::create_dir_all(&path).unwrap(); + TransientDirectory { path } + } + + fn create_files(&self, files: &[&str]) { + for file_name in files { + let file = fs::File::create(self.path.join(file_name)).unwrap(); + file.set_modified(SystemTime::UNIX_EPOCH).unwrap(); + } + } + + fn create_dirs(&self, dirs: &[&str]) { + for dir_name in dirs { + fs::create_dir(self.path.join(dir_name)).unwrap(); + } + } +} + +impl Drop for TransientDirectory { + fn drop(&mut self) { + fs::remove_dir_all(&self.path).unwrap(); + } +} + +impl AsRef for TransientDirectory { + fn as_ref(&self) -> &path::Path { + &self.path + } +} + +impl std::ops::Deref for TransientDirectory { + type Target = path::PathBuf; + + fn deref(&self) -> &path::PathBuf { + &self.path + } } #[test] -#[cfg(windows)] -fn cli_windows_tests() { - trycmd::TestCases::new().case("tests/cmd/*_windows.toml"); +fn cli_tests_any_basic() { + let test_dir = TransientDirectory::create("any", "basic"); + test_dir.create_files(&["file.txt"]); + test_dir.create_dirs(&["dir"]); + + trycmd::TestCases::new().case("tests/cmd/any/basic/*.toml"); } #[test] -#[cfg(feature = "nix-local")] -fn cli_nix_local_tests() { - trycmd::TestCases::new().case("tests/cmd/*_nix_local.toml"); +fn cli_tests_any_sort() { + let test_dir = TransientDirectory::create("any", "sort"); + + test_dir.create_files(&[ + "a.txt", + "abc.mp3", + "ab" + ]); + + test_dir.create_dirs(&[ + "test", + "abc", + "01.city", + "02.apple", + ]); + + trycmd::TestCases::new().case("tests/cmd/any/sort/*.toml"); } #[test] -#[cfg(feature = "powertest")] -fn cli_powertest_tests() { - trycmd::TestCases::new().case("tests/ptests/*.toml"); +#[cfg(feature = "git")] +fn cli_tests_any_git() { + use std::process::Command; + + let test_dir = TransientDirectory::create("any", "git"); + Command::new("git").args(["init", test_dir.to_str().unwrap()]).output().unwrap(); + + trycmd::TestCases::new().case("tests/cmd/any/git/*.toml"); } #[test] -#[cfg(feature = "nix")] -fn cli_nix_generated_tests() { - trycmd::TestCases::new().case("tests/gen/*.toml"); +#[cfg(not(feature = "git"))] +fn cli_tests_any_no_git() { + use std::process::Command; + + let test_dir = TransientDirectory::create("any", "no-git"); + Command::new("git").args(["init", test_dir.to_str().unwrap()]).output().unwrap(); + + trycmd::TestCases::new().case("tests/cmd/any/no-git/*.toml"); } diff --git a/tests/cmd/absolute_file_all.stderr b/tests/cmd/absolute_file_all.stderr deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/cmd/absolute_file_all.stdout b/tests/cmd/absolute_file_all.stdout deleted file mode 100644 index 3bbe5cbbc..000000000 --- a/tests/cmd/absolute_file_all.stdout +++ /dev/null @@ -1 +0,0 @@ -[CWD]/tests/itest/index.svg diff --git a/tests/cmd/absolute_file_all.toml b/tests/cmd/absolute_file_all.toml deleted file mode 100644 index 4666e76df..000000000 --- a/tests/cmd/absolute_file_all.toml +++ /dev/null @@ -1,2 +0,0 @@ -bin.name = "eza" -args = "tests/itest/index.svg --absolute" diff --git a/tests/cmd/absolute_recurse_unix.stderr b/tests/cmd/absolute_recurse_unix.stderr deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/cmd/absolute_recurse_unix.stdout b/tests/cmd/absolute_recurse_unix.stdout deleted file mode 100644 index 44233b948..000000000 --- a/tests/cmd/absolute_recurse_unix.stdout +++ /dev/null @@ -1,50 +0,0 @@ -[CWD]/tests/itest/a -[CWD]/tests/itest/b -[CWD]/tests/itest/c -[CWD]/tests/itest/d -[CWD]/tests/itest/dir-symlink -> vagrant/debug -[CWD]/tests/itest/e -[CWD]/tests/itest/exa -[CWD]/tests/itest/f -[CWD]/tests/itest/g -[CWD]/tests/itest/h -[CWD]/tests/itest/i -[CWD]/tests/itest/image.jpg.img.c.rs.log.png -[CWD]/tests/itest/index.svg -[CWD]/tests/itest/j -[CWD]/tests/itest/k -[CWD]/tests/itest/l -[CWD]/tests/itest/m -[CWD]/tests/itest/n -[CWD]/tests/itest/o -[CWD]/tests/itest/p -[CWD]/tests/itest/q -[CWD]/tests/itest/vagrant - -tests/itest/exa: -[CWD]/tests/itest/exa/file.c -> djihisudjuhfius -[CWD]/tests/itest/exa/sssssssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss - -tests/itest/exa/sssssssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss: -[CWD]/tests/itest/exa/sssssssssssssssssssssssssggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggsssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss/Makefile - -tests/itest/vagrant: -[CWD]/tests/itest/vagrant/debug -[CWD]/tests/itest/vagrant/dev -[CWD]/tests/itest/vagrant/log - -tests/itest/vagrant/debug: -[CWD]/tests/itest/vagrant/debug/a -[CWD]/tests/itest/vagrant/debug/symlink -> a -[CWD]/tests/itest/vagrant/debug/symlink-broken -> ./b - -tests/itest/vagrant/dev: -[CWD]/tests/itest/vagrant/dev/main.bf - -tests/itest/vagrant/log: -[CWD]/tests/itest/vagrant/log/file.png -[CWD]/tests/itest/vagrant/log/run - -tests/itest/vagrant/log/run: -[CWD]/tests/itest/vagrant/log/run/run.log.text -[CWD]/tests/itest/vagrant/log/run/sps.log.text diff --git a/tests/cmd/absolute_recurse_unix.toml b/tests/cmd/absolute_recurse_unix.toml deleted file mode 100644 index 9b941618f..000000000 --- a/tests/cmd/absolute_recurse_unix.toml +++ /dev/null @@ -1,2 +0,0 @@ -bin.name = "eza" -args = "tests/itest --absolute -R" diff --git a/tests/cmd/absolute_unix.stderr b/tests/cmd/absolute_unix.stderr deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/cmd/absolute_unix.stdout b/tests/cmd/absolute_unix.stdout deleted file mode 100644 index 64ff7ae26..000000000 --- a/tests/cmd/absolute_unix.stdout +++ /dev/null @@ -1,22 +0,0 @@ -[CWD]/tests/itest/a -[CWD]/tests/itest/b -[CWD]/tests/itest/c -[CWD]/tests/itest/d -[CWD]/tests/itest/dir-symlink -> vagrant/debug -[CWD]/tests/itest/e -[CWD]/tests/itest/exa -[CWD]/tests/itest/f -[CWD]/tests/itest/g -[CWD]/tests/itest/h -[CWD]/tests/itest/i -[CWD]/tests/itest/image.jpg.img.c.rs.log.png -[CWD]/tests/itest/index.svg -[CWD]/tests/itest/j -[CWD]/tests/itest/k -[CWD]/tests/itest/l -[CWD]/tests/itest/m -[CWD]/tests/itest/n -[CWD]/tests/itest/o -[CWD]/tests/itest/p -[CWD]/tests/itest/q -[CWD]/tests/itest/vagrant diff --git a/tests/cmd/absolute_unix.toml b/tests/cmd/absolute_unix.toml deleted file mode 100644 index d1442b947..000000000 --- a/tests/cmd/absolute_unix.toml +++ /dev/null @@ -1,2 +0,0 @@ -bin.name = "eza" -args = "tests/itest --absolute" diff --git a/tests/cmd/any/basic/help.toml b/tests/cmd/any/basic/help.toml new file mode 100644 index 000000000..af21e739a --- /dev/null +++ b/tests/cmd/any/basic/help.toml @@ -0,0 +1,89 @@ +bin.name = "eza" +args = ["--help"] +status.code = 0 +stdout = """ +A modern replacement for ls + +Usage: eza [OPTIONS] [FILE]... + +META OPTIONS: + --stdin read file names from stdin + -?, --help Print help + -v, --version Print help + +LAYOUT OPTIONS: + -1, --oneline display one entry per line + -l, --long display extended file metadata as a table + -G, --grid display entries as a grid (default) + -x, --across sort the grid across, rather than downwards + -R, --recurse recurse into directories + -T, --tree recurse into directories as a tree + -L, --level limit the depth of recursion + --follow-symlinks drill down into symbolic links that point to directories + -w, --width set screen width in columns + +DISPLAY OPTIONS: + -F, --classify [] display type indicator by file names [possible values: always, auto, never] + -X, --dereference dereference symbolic links when displaying information + --absolute [] display entries with their absolute path [possible values: on, off, follow] + --color [] When to use colours. [default: auto] [possible values: always, auto, never] + --color-scale [...] highlight value of FIELDS distinctly [possible values: all, age, size] + --color-scale-mode mode for --color-scale [default: gradient] [possible values: fixed, gradient] + --icons [] when to display icons [possible values: always, auto, never] + --hyperlink [] when to display entries as hyperlinks [possible values: always, auto, never] + --no-quotes don't quote file names with spaces + +FILTERING OPTIONS: + -a, --all... show hidden files. Use this twice to also show the '.' and '..' directories + -A, --almost-all equivalent to --all; included for compatibility with `ls -A` + -d, --treat-dirs-as-files treat directories as files; don't list their contents + -D, --only-dirs list only directories + -f, --only-files list only files + --show-symlinks explicitly show symbolic links (with --only-dirs and --only-files) + --no-symlinks do not show symbolic links + -I, --ignore-glob glob patterns (pipe-separated) of files to ignore + --git-ignore ignore files mentioned in '.gitignore' + +SORTING OPTIONS: + --group-directories-first list directories before other files + --group-directories-last list directories after other files + -s, --sort which field to sort by [default: name] [possible values: + name, Name, .name, .Name, ext, ext, created, + date, age, accessed, changed, + size, inode, type, none] + -r, --reverse reverse the sort order + +LONG VIEW OPTIONS: + -h, --header add a header row to each column + -i, --inode list each file's inode number + -o, --octal-permissions list each file's permission in octal format + -H, --links list each file's number of hard links + -b, --binary show file sizes with binary prefixes + -B, --bytes show file sizes in bytes, without any prefixes + --total-size show the size of a directory as the one of its content (unix only) + -S, --blocksize list size of allocated file system blocks + -g, --group list each file's group + --smart-group only show group if it has a different name from owner + -n, --numeric show user and group as their numeric IDs + -t, --time which timestamp field to show [possible values: + mod|modified, acc|accessed, ch|changed, cr|created] + -m, --modified show the modified timestamp field (replace default field, combinable) + -u, --accessed show the accessed timestamp field (replace default field, combinable) + --changed show the changed timestamp field (replace default field, combinable) + -U, --created show the created timestamp field (replace default field, combinable) + --time-style