From 9b17ba5feebfe96d420d4a7028cfbf0c6e484c2c Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Sun, 5 Sep 2021 22:40:22 -0500 Subject: [PATCH] testing around with proot --- .editorconfig | 2 +- flake.nix | 3 ++- tests/.common.sh | 1 + tests/default.nix | 5 ++-- tests/issue-1-non-unicode-paths.sh | 3 ++- tests/issue-4-restore-current-partition.sh | 27 ++++++++++++++++++++++ 6 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 tests/.common.sh create mode 100755 tests/issue-4-restore-current-partition.sh diff --git a/.editorconfig b/.editorconfig index cb51778..63ce0bf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,5 +8,5 @@ charset = utf-8 indent_style = space indent_size = 4 -[*.nix] +[*.{nix,sh}] indent_size = 2 diff --git a/flake.nix b/flake.nix index 6e4361c..371db79 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,7 @@ let pkgs = nixpkgs.legacyPackages.${system}; garbageProj = import ./Cargo.nix { inherit pkgs; }; + garbageProjDebug = import ./Cargo.nix { inherit pkgs; release = false; }; garbage = pkgs.lib.recursiveUpdate garbageProj.rootCrate.build { meta = { description = "CLI tool to interact with the FreeDesktop trash API."; @@ -16,7 +17,7 @@ }; flakePkgs = { inherit garbage; - tests = pkgs.callPackage ./tests { inherit garbage; }; + tests = pkgs.callPackage ./tests { garbage = garbageProjDebug.rootCrate.build; }; }; in rec { diff --git a/tests/.common.sh b/tests/.common.sh new file mode 100644 index 0000000..beded84 --- /dev/null +++ b/tests/.common.sh @@ -0,0 +1 @@ +export RUST_BACKTRACE=1 diff --git a/tests/default.nix b/tests/default.nix index 480ec03..6ce2e63 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,4 +1,4 @@ -{ stdenv, garbage }: +{ stdenv, garbage, pkgs }: stdenv.mkDerivation { name = "garbage-tests"; @@ -7,7 +7,8 @@ stdenv.mkDerivation { installPhase = "mkdir -p $out"; doCheck = true; - garbage = "${garbage}/bin/garbage"; + buildInputs = with pkgs; [ garbage proot mktemp mount which bash ]; + checkPhase = '' find . -executable -name "*.sh" | xargs bash ''; diff --git a/tests/issue-1-non-unicode-paths.sh b/tests/issue-1-non-unicode-paths.sh index ac7dc2a..8fe4a77 100755 --- a/tests/issue-1-non-unicode-paths.sh +++ b/tests/issue-1-non-unicode-paths.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash +source .common.sh filename=$'\377'$'\017'$'\224'$'\353'\`$'\001' touch $filename -$garbage put $filename +garbage put $filename diff --git a/tests/issue-4-restore-current-partition.sh b/tests/issue-4-restore-current-partition.sh new file mode 100755 index 0000000..057bec8 --- /dev/null +++ b/tests/issue-4-restore-current-partition.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +source .common.sh + +garbage=$(which garbage) +tmproot=$(mktemp -d) +mkdir -p $tmproot/{mnt,home} +echo "delete" > $tmproot/mnt/mnt-delete +echo "delete" > touch $tmproot/home/home-delete + +cat > $tmproot/run.sh << EOF + cd /mnt + ls -al + cat mnt-delete + garbage put mnt-delete + garbage list +EOF +chmod +x $tmproot/run.sh + +proot \ + -0 \ + -r $tmproot \ + -b /bin \ + -b /nix \ + -w / \ + --kill-on-exit \ + "/run.sh" +