Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpelsepp committed Dec 21, 2023
1 parent b6a7833 commit 805e50b
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 32 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/bats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

on: [push, pull_request]

name: "Tests"
permissions: {}

jobs:
bats:
runs-on: ubuntu-latest
container: debian:latest
steps:
- uses: actions/checkout@v3
- name: install bats
uses: brokenpip3/[email protected]
run: |
apt-get update && apt-get install -y bats jq zstd
- name: run bats
run: |
bats -x -r tests
26 changes: 26 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions flake.lock.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: Stefan Tatschner

SPDX-License-Identifier: CC0-1.0
24 changes: 24 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: Stefan Tatschner
#
# SPDX-License-Identifier: CC0-1.0

{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
};

outputs = { self, nixpkgs }:
with import nixpkgs { system = "x86_64-linux"; };
let pkgs = nixpkgs.legacyPackages.x86_64-linux;
in {
devShell.x86_64-linux = pkgs.mkShell {
buildInputs = with pkgs; [
bats
];
shellHook = ''
LD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath [stdenv.cc.cc]}
'';
};
formatter.x86_64-linux = pkgs.nixpkgs-fmt;
};
}
56 changes: 25 additions & 31 deletions tests/0001-invocation.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,29 @@ setup() {
}

@test "invoke penrun without parameters" {
local tmpdir
tmpdir="$(mktemp -d)"
(
cd "$tmpdir"
penrun -c /dev/null ls -lah
if [[ ! -d "ls" ]]; then
echo "output directory is missing"
return 1
fi

mapfile -t meta < "ls/LATEST/META.json"
for line in "${meta[@]}"; do
local cmd
local exit_code
if [[ "$line" =~ EXIT:(.+) ]]; then
exit_code="${BASH_REMATCH[1]}"
if ((exit_code != 0)); then
return 1
fi
fi
if [[ "$line" =~ COMMAND:(.+)\s$ ]]; then
cmd="${BASH_REMATCH[1]}"
if [[ "$cmd" != "ls -lah" ]]; then
echo "$cmd"
return 1
fi
fi
done

rm -rf "$tmpdir"
)
cd "$BATS_TEST_TMPDIR"

mkdir foo

run penrun -c /dev/null ls -lah

if (( $status != "0" )); then
echo "penrun failed"
return 1
fi

if [[ ! -d "ls" ]]; then
echo "output directory is missing"
return 1
fi

if (( "$(jq ".exit_code" < ls/LATEST/META.json)" != "0" )); then
echo "exit_code in META != 0"
return 1
fi

if [[ "$(jq -r '.command | join(" ")' < ls/LATEST/META.json)" != "ls -lah" ]]; then
echo "command != ls -lah"
return 1
fi
}

0 comments on commit 805e50b

Please sign in to comment.