X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=testkit%2Fexamples%2Fblank_test.sh;h=aa77ac3e71fddb5b7ede820dd892ed6be2f2cd61;hb=8b9ecb1c64d19bac9885605779e9b9b73024f75b;hp=47dfd3a6f12b4986f3eb040138bd041212f9f75e;hpb=e7c657cd5544c1e4e5108412f9fa5e51d56a0ad3;p=feisty_meow.git diff --git a/testkit/examples/blank_test.sh b/testkit/examples/blank_test.sh index 47dfd3a6..aa77ac3e 100644 --- a/testkit/examples/blank_test.sh +++ b/testkit/examples/blank_test.sh @@ -1,14 +1,15 @@ #!/bin/bash -# Test: X -# Author: Y +# Test: Blank +# Author: Fill ItIn export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory. cd "$WORKDIR" -# this needs to be relative to where the test will actually reside; the ../../../../../etc -# should get to the top of the tools and tests hierarchy. -source "../prepare_tools.sh" "../prepare_tools.sh" +# this needs to be relative to where the test will actually reside; the .. components below +# need to get to the top of the tools and tests hierarchy. +relative_depth=".." +source "$relative_depth/prepare_tools.sh" "$relative_depth/prepare_tools.sh" if [ -z "$TEST_TEMP" ]; then echo The TestKit could not be automatically located. exit 1 @@ -34,8 +35,8 @@ testSanity() testCleaningPriorTestRun() { - echo taking steps to clean last test... -#if any. + # take steps to clean last test, if any are needed. + true } testDoAThing() @@ -54,9 +55,96 @@ testDoAnotherThing() assertNotEquals "an explicit failure should be seen" 0 $? } +testShunitExamples() +{ + echo running through shunit tests available. + + # values must be the same. + assertEquals "equals test" 5 5 + + # similar test, different name. + assertSame "same test" oof oof + + # values must not be the same. + assertNotEquals "not equals test" 3 5 + + # a parallel not same test. + assertNotSame "not same test" orp 3 + + # value must have no content (or not be defined). + assertNull "empty null test" "" + assertNull "undefined null test" "$variableDoesntExistOrShouldntSinceWeDidntDefineIt" + + # value must have content. + assertNotNull "not null test" "sugarwater" + + # value must be true, which in bash means equal to zero. + assertTrue "true test simple" 0 + # this shows how true return value can be tested. + true + assertTrue "true test return value" $? + + # value must be false, or non-zero. + assertFalse "false test simple" 13 + # shows how false return value can be tested. + false + assertFalse "false test" $? +} + +testShowSkipping() +{ + # the failures below are intentionally skipped, so as to avoid the failure + # results in our full output. + # this shows two things; how to skip the rest of the tests if needed, + # and how to cause a test failure without using an assertion. + + # show if we're skipping already. + isSkipping + if [ $? -eq 0 ]; then + echo we are skipping tests. + else + echo we are not skipping tests. + fi + + # start skipping tests. + startSkipping + + # show that we're skipping. + isSkipping + if [ $? -eq 0 ]; then + echo we are skipping tests. + else + echo we are not skipping tests. + fi + + # can be used to set a test failed state, without using an assertion. + # this might be used if there is complex logic and one doesn't feel + # like boiling that down to a single variable to test on. + fail "one of the tests above failed" + + # indicates a failure because two values were not the same. + failNotSame "values should have been the same" toyBoat oatBoy + + # indicates a failure when two values should have been different. + failSame "values should not have been the same" 3 3 + + # stop skipping tests again. + endSkipping + + # show that we're no longer skipping. + isSkipping + if [ $? -eq 0 ]; then + echo we are skipping tests. + else + echo we are not skipping tests. + fi + + assertSame "shunit is cool" cool cool +} + oneTimeTearDown() { - echo cleaning up after test now... -#if anything to do. + # cleaning up after test, if needed. + true } # load and run shUnit2