Commit 40affc9f authored by nimrod's avatar nimrod
Browse files

Better Bats tests.

- Add a submodule for assertions. Should provide better output.
  Hopefully it will help debugging the failing tests.
- Add some perf data examples (no tests or code yet).
parent dc2eeb15
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -7,6 +7,9 @@ include:
  - project: shore/ci-templates
    file: templates/gitlab-release.yml

variables:
  GIT_SUBMODULE_STRATEGY: recursive

build-wheel:
  extends: .python3-build
  script:

.gitmodules

0 → 100644
+3 −0
Original line number Diff line number Diff line
[submodule "tests/bats_helpers/bats-assert"]
	path = tests/bats_helpers/bats-assert
	url = https://github.com/bats-core/bats-assert.git
Original line number Diff line number Diff line
Subproject commit e0de84e9c011223e7f88b7ccf1c929f4327097ba

tests/mnpw.bats

deleted100644 → 0
+0 −49
Original line number Diff line number Diff line
# vim:ft=bash

@test "help" {
    run dist/mnpw --help
    [ "$status" -eq 0 ]
}

@test "version" {
    run dist/mnpw --version
    [ "$status" -eq 0 ]
}

@test "true" {
    run dist/mnpw true
    [ "$status" -eq 0 ]
}

@test "command not found" {
    run dist/mnpw --dry-run /foobar
    [ "$status" -eq 2 ]
}

@test "warning" {
    run dist/mnpw --dry-run -- /bin/sh -c 'exit 1'
}

@test "critical" {
    run dist/mnpw --dry-run -- /bin/sh -c 'exit 2'
}

@test "unknown" {
    run dist/mnpw --dry-run -- /bin/sh -c 'exit 3'
}

@test "other" {
    run dist/mnpw --dry-run -- /bin/sh -c 'exit 4'
}

@test "timeout" {
    run dist/mnpw --dry-run --timeout 2 -- /bin/sh -c 'sleep 6'
    [ "$status" -eq 2 ]
}

@test "quiet" {
    run dist/mnpw --dry-run --quiet false
    [ "$output" = '' ]
    run dist/mnpw --dry-run --quiet foobar
    [ "$output" != '' ]
}

tests/test_mnpw.bats

0 → 100644
+61 −0
Original line number Diff line number Diff line
# vim:ft=bash

setup () {
    load "bats_helpers/bats-assert/load"
    PATH="$BATS_TEST_DIRNAME/../dist:$PATH"
}

@test "help" {
    run mnpw --help
    assert_success
    assert_output --partial 'usage:'
}

@test "version" {
    run mnpw --version
    assert_success
    assert_output --partial 'mnpw version'
}

@test "silent and verbose" {
    run mnpw --silent --verbose /bin/true
    assert_failure 2
}

@test "true" {
    run mnpw /bin/true
    assert_success
}

@test "command not found" {
    run mnpw --dry-run /foobar
    assert_failure 2
}

@test "warning" {
    run mnpw --dry-run -- /bin/sh -c 'exit 1'
}

@test "critical" {
    run mnpw --dry-run -- /bin/sh -c 'exit 2'
}

@test "unknown" {
    run mnpw --dry-run -- /bin/sh -c 'exit 3'
}

@test "invalid return code" {
    run mnpw --dry-run -- /bin/sh -c 'exit 4'
}

@test "timeout" {
    run mnpw --dry-run --timeout 2 -- /bin/sh -c 'sleep 6'
    assert_failure 2
}

@test "quiet" {
    run mnpw --dry-run --quiet false
    assert_output ''
    run mnpw --dry-run --quiet foobar
    assert_output
}
Loading