{pkgs', ...}: let
  bashFktScript = import ./bash-fkt.nix {
    inherit pkgs';
  };
in
  pkgs'.writeShellScriptBin "run-tests" ''

    source ${pkgs'.common}/bin/common
    ${bashFktScript}

    echo_header "Running tests"
    echo_hint "The command is executed in the current working directory and not in a nix derivation."
    cd_working_dir

    setup_go_env

    echo_section "Select test to run"
    selection=$(${pkgs'.gum}/bin/gum choose "run all tests" "run specific test" "Cancel")

    if [[ "$selection" == "Cancel" ]]; then
      echo_ok "Exiting."
      exit 0
    fi
    
    if [[ -f "assets/test.env" ]]; then
      echo_hint "Loading test environment variables"
      set -a
      source "assets/test.env"
      set +a
    fi

    if [[ "$selection" == "run all tests" ]]; then
      echo_ok "Running all tests"
      if ! CGO_CFLAGS="-Wno-format-security" ${pkgs'.go}/bin/go test -tags runOnTask -v -failfast ./...
      then
        echo_fail "ERROR: Tests failed, check your Go!"
        exit 1
      fi
      echo_ok "All tests passed!"
      exit 0
    fi

    test_files=$(${pkgs'.findutils}/bin/find . -name "*_test.go")

    test_names=""
    for file in $test_files; do
        names=$(${pkgs'.gnugrep}/bin/grep -oP 'func (Test\w+)' $file | ${pkgs'.gawk}/bin/gawk '{print $2}')
        test_names+="$names "
    done

    if [[ -z "$test_names" ]]; then
        echo_fail "No tests found!"
        exit 1
    fi

    selected_tests=$(echo "$test_names" | ${pkgs'.coreutils}/bin/tr ' ' '\n' | ${pkgs'.gum}/bin/gum filter --no-limit  )

    if [[ -z "$selected_tests" ]]; then
        echo_ok "No tests selected, exiting."
        exit 0
    fi

    if ! CGO_CFLAGS="-Wno-format-security" ${pkgs'.go}/bin/go test -tags runOnTask -run "$(echo $selected_tests)"
    then
      echo_fail "ERROR: Tests failed, check your Go!"
      exit 1
    fi

    echo_ok "All tests passed!"


  ''