diff --git a/.github/workflows/bats.yml b/.github/workflows/bats.yml index 5864827..5262715 100644 --- a/.github/workflows/bats.yml +++ b/.github/workflows/bats.yml @@ -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/setup-bats-libs@1.5.2 + run: | + apt-get update && apt-get install -y bats jq zstd - name: run bats run: | bats -x -r tests diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..0f71834 --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1703148052, + "narHash": "sha256-D2UaI7fxUrdBzSBwd7BVC9VvEl45XosNXc0A2HE7WlY=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "71807aee99a47a8bf1d606f858244bbd6803da23", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.lock.license b/flake.lock.license new file mode 100644 index 0000000..cd213ca --- /dev/null +++ b/flake.lock.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: Stefan Tatschner + +SPDX-License-Identifier: CC0-1.0 diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2f18901 --- /dev/null +++ b/flake.nix @@ -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; + }; +} diff --git a/tests/0001-invocation.bats b/tests/0001-invocation.bats index c6fdf84..ba23af0 100644 --- a/tests/0001-invocation.bats +++ b/tests/0001-invocation.bats @@ -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 }