diff --git a/flake.nix b/flake.nix index f73f75f..cd5cf60 100644 --- a/flake.nix +++ b/flake.nix @@ -79,7 +79,7 @@ resolveTimeDeps = [ pkgs.bash pkgs.coreutils pkgs.file pkgs.findutils pkgs.gettext ]; in { default = pkgs.mkShell { - buildInputs = [ pkgs.bash pkgs.resholve pkgs.bats ]; + buildInputs = [ pkgs.bash pkgs.resholve (pkgs.bats.withLibraries (p: [ bats-require ])) ]; RESHOLVE_PATH = "${pkgs.lib.makeBinPath resolveTimeDeps}"; RESHOLVE_LORE = "${pkgs.binlore.collect { drvs = resolveTimeDeps; } }"; INTERP = "${pkgs.bash}/bin/bash"; diff --git a/nixpkgs/test.nix b/nixpkgs/test.nix index 7834d84..7799986 100644 --- a/nixpkgs/test.nix +++ b/nixpkgs/test.nix @@ -11,6 +11,7 @@ , jq , bash , bats +, bats-require , libressl , openssl , python27 @@ -127,7 +128,7 @@ rec { ''; doCheck = true; buildInputs = [ resholve ]; - nativeCheckInputs = [ coreutils bats ]; + nativeCheckInputs = [ coreutils (bats.withLibraries (p: [ bats-require ])) ]; # LOGLEVEL="DEBUG"; # default path diff --git a/tests/behavior.bats b/tests/behavior.bats index ba2b4c6..31ed3fc 100644 --- a/tests/behavior.bats +++ b/tests/behavior.bats @@ -2,6 +2,7 @@ # that try to stake out/exercise specific behavior that demonstrate and # codify where the boundaries of what resholve knows how to handle are. +bats_load_library bats-require load helpers # TODO: replace w/ real test once issue is sorted diff --git a/tests/cli.bats b/tests/cli.bats index 24fcc88..c129a67 100644 --- a/tests/cli.bats +++ b/tests/cli.bats @@ -14,6 +14,7 @@ # it is also covered here. But not the inverse--the demo doesn't need to cover the same # exact ground as thoroughly as this suite. +bats_load_library bats-require load helpers @test "invoking resholve without --interpreter prints an error" { diff --git a/tests/demo.bash b/tests/demo.bash index 98bfed1..95abaa6 100644 --- a/tests/demo.bash +++ b/tests/demo.bash @@ -1,3 +1,4 @@ +bats_load_library bats-require load helpers _cols="${COLUMNS:-80}" diff --git a/tests/helpers.bash b/tests/helpers.bash index 4393746..687c338 100644 --- a/tests/helpers.bash +++ b/tests/helpers.bash @@ -11,164 +11,6 @@ teardown() { } > /dev/null } -# status -_expect_status() { - if [[ $status != "$1" ]]; then - return 1 - fi -} - -# line (-) equals|contains|begins|ends|!equals|!contains|!begins|!ends "value" -# CAUTION: one gotcha; blank lines not included; you have to -# adjust down for each one -_expect_line() { - if [[ $1 -lt 0 ]]; then - let lineno=$1 - else - # adjust to 0-index - let lineno=$1-1 || true # 1-0 causes let to return 1 - fi - - local line=${lines[$lineno]} kind=$2 - case $kind in - equals) - if [[ $line == "$3" ]]; then - return 0 - else - echo " expected line $1:" - echo " '$3'" - echo " actual:" - echo " '$line'" - return 1 - fi - ;; - contains) - if [[ $line == *"$3"* ]]; then - return 0 - else - echo " expected line $1:" - echo " '$3'" - echo " actual:" - echo " '$line'" - return 1 - fi - ;; - begins) - if [[ $line == "$3"* ]]; then - return 0 - else - echo " expected line $1 to begin with:" - echo " '$3'" - echo " actual line:" - echo " '$line'" - return 1 - fi - ;; - ends) - if [[ $line == *"$3" ]]; then - return 0 - else - echo " expected line $1 to end with:" - echo " '$3'" - echo " actual line:" - echo " '$line'" - return 1 - fi - ;; - !equals) - if [[ $line != "$3" ]]; then - return 0 - else - echo " expected line $1:" - echo " '$3'" - echo " actual:" - echo " '$line'" - return 1 - fi - ;; - !contains) - if [[ $line != *"$3"* ]]; then - return 0 - else - echo " expected line $1:" - echo " '$3'" - echo " actual:" - echo " '$line'" - return 1 - fi - ;; - !begins) - if [[ $line != "$3"* ]]; then - return 0 - else - echo " expected line $1 to begin with:" - echo " '$3'" - echo " actual line:" - echo " '$line'" - return 1 - fi - ;; - !ends) - if [[ $line != *"$3" ]]; then - return 0 - else - echo " expected line $1 to end with:" - echo " '$3'" - echo " actual line:" - echo " '$line'" - return 1 - fi - ;; - esac - # shouldn't get here - echo "unexpected input: $@" - return 2 -} - -status() { - echo "_expect_status ${@@Q}" -} - -line() { - echo "_expect_line ${@@Q}" -} - -# cases are on STDIN -# expectations in fd passed as arg 1 -require() { - mapfile _cases - mapfile _expectations < "$1" - - # TODO: I'd like to print numbers by these in the TAP output, but contrary to the docs they're leaking into the pretty-print output. Worth trying after the next bats version bump. - # casenum=0 - for case in "${_cases[@]}"; do - # ((casenum = casenum + 1))# - run eval "${case@E}" - # echo "# ${BATS_TEST_NUMBER}-${casenum}: ${case%$'\n'}" >&3 - printf "status: %s\n" $status - printf "output:\n%s" "$output" - - echo "" - echo "expectations:" - echo "${_expectations[@]}" - for expected in "${_expectations[@]}"; do - echo "expected=${expected%$'\n'}" - eval "$expected" - done - - # TODO: this is probably a little faster - # but it was only respecting the last line - # and my efforts to shim in errexit weren't - # working for some reason and it's hard to debug down under bats. - # if ! source "$1"; then - - # # eval "$case" - # false - # fi - - done -} - parsers() { cat parse_*.sh > parsed.sh resholve --interpreter none --path "${PKG_PARSED}:${PKG_COREUTILS}" < parsed.sh > resolved.sh diff --git a/tests/in-file-directives.bats b/tests/in-file-directives.bats index 649714b..0c7a003 100644 --- a/tests/in-file-directives.bats +++ b/tests/in-file-directives.bats @@ -5,6 +5,7 @@ # older version of resholve against this suite to learn how compatible it is # with newer versions of the format. +bats_load_library bats-require load helpers @test "modern resholve versions reject v1 files" {