Skip to content
Snippets Groups Projects
Commit 2a8c9287 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

Merge branch 'fix/bats-report' into 'master'

fix bats report

See merge request to-be-continuous/bash!24
parents df727abf 824fb9c3
Branches
Tags
No related merge requests found
......@@ -20,6 +20,8 @@ stages:
variables:
GITLAB_CI_FILES: "templates/gitlab-ci-bash.yml"
BASH_SHELLCHECK_FILES: "*.sh"
BASH_BATS_ENABLED: "true"
BASH_BATS_LIBRARIES: "bats-support@https://github.com/bats-core/bats-support/archive/v0.3.0.zip bats-assert@https://github.com/bats-core/bats-assert/archive/v2.1.0.zip"
semantic-release:
rules:
......
......@@ -246,19 +246,21 @@ bash-bats:
image:
name: "$BASH_BATS_IMAGE"
entrypoint: [""]
variables:
BATS_REPORT_FILENAME: bash-bats.xunit.xml
script:
- install_bats_libs
- mkdir reports
- bats --formatter junit --output reports $BASH_BATS_OPTS $BASH_BATS_TESTS
- bats --report-formatter junit --output reports $BASH_BATS_OPTS $BASH_BATS_TESTS
artifacts:
name: "$CI_JOB_NAME artifacts from $CI_PROJECT_NAME on $CI_COMMIT_REF_SLUG"
expire_in: 1 day
when: always
reports:
junit:
- "reports/*.bats.xml"
- "reports/bash-bats.xunit.xml"
paths:
- "reports/*.bats.xml"
- "reports/bash-bats.xunit.xml"
rules:
- if: '$BASH_BATS_ENABLED != "true"'
when: never
......
#!/usr/bin/env bash
# load scripts from template
scripts=/tmp/bash-scripts.sh
echo "#!/bin/bash" > $scripts
sed -n '/BEGSCRIPT/,/ENDSCRIPT/p' "$(dirname ${BASH_SOURCE[0]})/../templates/gitlab-ci-bash.yml" >> $scripts
source $scripts
#!/usr/bin/env bats
load "$BATS_LIBRARIES_DIR/bats-support/load.bash"
load "$BATS_LIBRARIES_DIR/bats-assert/load.bash"
load 'bash-scripts'
function setup() {
export TESTVAR="default"
export scoped__TESTVAR__if__CONDVAR__equals__case1="case1"
export scoped__TESTVAR__if__CONDVAR__startswith__case2="case2"
export scoped__TESTVAR__if__CONDVAR__endswith__case3="case3"
export scoped__TESTVAR__if__CONDVAR__contains__case4="case4"
export scoped__TESTVAR__if__CONDVAR__in__apple__banana__orange="fruit"
}
function unscope_variables_and_check() {
unscope_variables
echo ">>> TESTVAR=$TESTVAR"
}
@test "no scoped var" {
# GIVEN
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=default"
}
@test "equals condition should match" {
# GIVEN
export CONDVAR=case1
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=case1"
}
@test "startswith condition should match" {
# GIVEN
export CONDVAR='case2 and bla bla'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=case2"
}
@test "startswith condition should not match" {
# GIVEN
export CONDVAR='does not start with case2'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=default"
}
@test "endswith condition should match" {
# GIVEN
export CONDVAR='ends with case3'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=case3"
}
@test "endswith condition should not match" {
# GIVEN
export CONDVAR='does not end with case3...'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=default"
}
@test "contains condition should match" {
# GIVEN
export CONDVAR='contains case4 in the middle'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=case4"
}
@test "in condition should match 1" {
# GIVEN
export CONDVAR='apple'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=fruit"
}
@test "in condition should match 2" {
# GIVEN
export CONDVAR='banana'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=fruit"
}
@test "in condition should match 3" {
# GIVEN
export CONDVAR='orange'
# WHEN
run unscope_variables_and_check
# THEN
assert_line ">>> TESTVAR=fruit"
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment