mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
add bats testing
This commit is contained in:
parent
e70e13e265
commit
2d05eccb87
4 changed files with 97 additions and 3 deletions
10
.github/workflows/docker.yml
vendored
10
.github/workflows/docker.yml
vendored
|
@ -43,7 +43,7 @@ jobs:
|
|||
name: Shellcheck
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run ShellCheck
|
||||
uses: ludeeus/action-shellcheck@master
|
||||
env:
|
||||
|
@ -52,6 +52,14 @@ jobs:
|
|||
version: v0.9.0
|
||||
additional_files: "*.envsh .env .env.docker .env.example .env.testing"
|
||||
|
||||
bats:
|
||||
name: Bats Testing
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Run bats
|
||||
run: docker run -v "$PWD:/var/www" bats/bats:latest /var/www/tests/bats
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
|
10
.gitmodules
vendored
Normal file
10
.gitmodules
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
|
||||
[submodule "tests/shell/bats"]
|
||||
path = tests/shell/bats
|
||||
url = https://github.com/bats-core/bats-core.git
|
||||
[submodule "tests/shell/test_helper/bats-support"]
|
||||
path = tests/shell/test_helper/bats-support
|
||||
url = https://github.com/bats-core/bats-support.git
|
||||
[submodule "tests/shell/test_helper/bats-assert"]
|
||||
path = tests/shell/test_helper/bats-assert
|
||||
url = https://github.com/bats-core/bats-assert.git
|
|
@ -487,6 +487,7 @@ function show-call-stack() {
|
|||
}
|
||||
|
||||
# @description Helper function see if $1 could be considered truthy
|
||||
# returns [0] if input is truthy, otherwise [1]
|
||||
# @arg $1 string The string to evaluate
|
||||
# @see as-boolean
|
||||
function is-true() {
|
||||
|
@ -496,12 +497,13 @@ function is-true() {
|
|||
}
|
||||
|
||||
# @description Helper function see if $1 could be considered falsey
|
||||
# returns [0] if input is falsey, otherwise [1]
|
||||
# @arg $1 string The string to evaluate
|
||||
# @see as-boolean
|
||||
function is-false() {
|
||||
as-boolean "${1:-}" || return 0
|
||||
as-boolean "${1:-}" && return 1
|
||||
|
||||
return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
# @description Helper function see if $1 could be truethy or falsey.
|
||||
|
|
74
tests/bats/helpers.bats
Normal file
74
tests/bats/helpers.bats
Normal file
|
@ -0,0 +1,74 @@
|
|||
setup() {
|
||||
DIR="$(cd "$(dirname "${BATS_TEST_FILENAME:-}")" >/dev/null 2>&1 && pwd)"
|
||||
ROOT="$(dirname "$(dirname "$DIR")")"
|
||||
|
||||
load "$ROOT/docker/shared/root/docker/helpers.sh"
|
||||
}
|
||||
|
||||
@test "test [is-true]" {
|
||||
is-true "1"
|
||||
is-true "true"
|
||||
is-true "TrUe"
|
||||
}
|
||||
|
||||
@test "test [is-false]" {
|
||||
is-false "0"
|
||||
is-false "false"
|
||||
is-false "FaLsE"
|
||||
}
|
||||
|
||||
@test "test [is-false-expressions-0]" {
|
||||
if is-false "0"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@test "test [is-false-expressions-false]" {
|
||||
if is-false "false"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@test "test [is-false-expressions-FaLse]" {
|
||||
if is-false "FaLse"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@test "test [is-false-expressions-invalid]" {
|
||||
if is-false "invalid"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@test "test [is-true-expressions-1]" {
|
||||
if is-true "1"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@test "test [is-true-expressions-true]" {
|
||||
if is-true "true"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
@test "test [is-true-expressions-TrUE]" {
|
||||
if is-true "TrUE"; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
Loading…
Reference in a new issue