You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#! /bin/sh# file: examples/math_test.shtestAdding() {
result=`add_generic 1 2`
assertEquals \
"the result of '${result}' was wrong" \
3 "${result}"# Disable non-generic tests.
[ -z"${BASH_VERSION:-}" ] && startSkipping
result=`add_bash 1 2`
assertEquals \
"the result of '${result}' was wrong" \
3 "${result}"
}
oneTimeSetUp() {
# Load include to test.. ./math.inc
}
# Load and run shUnit2.. ./shunit2
ShellSpec
#shellcheck shell=sh
Include ./math.inc
Describe 'add_generic()'
It 'adds values using expr'
When call add_generic 1 2
The output should eq 3
End
End
Describe 'add_bash()'
Skip if'non-generic tests' [ -z"${BASH_VERSION:-}" ]
It 'adds values using arithmetic expansion'
When call add_bash 1 2
The output should eq 3
End
End
#!/usr/bin/env bats
@test "addition using bc" {
result="$(echo 2+2 | bc)"
[ "$result"-eq 4 ]
}
@test "addition using dc" {
result="$(echo 2 2+p | dc)"
[ "$result"-eq 4 ]
}
@test "invoking foo with a nonexistent file prints an error" {
run foo nonexistent_filename
[ "$status"-eq 1 ]
[ "$output"="foo: no such file 'nonexistent_filename'" ]
}
@test "invoking foo without arguments prints usage" {
run foo
[ "$status"-eq 1 ]
[ "${lines[0]}"="usage: foo <filename>" ]
}
ShellSpec
#shellcheck shell=sh
Example "addition using bc"
Data "2+2"
When run bc
The output should eq 4
End
Example "addition using dc"
Data "2 2+p"
When run dc
The output should eq 4
End
Example "invoking foo with a nonexistent file prints an error"
When run foo nonexistent_filename
The status should eq 1
The output should eq "foo: no such file 'nonexistent_filename'"
End
Example "invoking foo without arguments prints usage"
When run foo
The status should eq 1
The line 1 should eq "usage: foo <filename>"
End