6 export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )" # obtain the script's working directory.
9 # this needs to be relative to where the test will actually reside; the .. components below
10 # need to get to the top of the tools and tests hierarchy.
12 source "$relative_depth/prepare_tools.sh" "$relative_depth/prepare_tools.sh"
13 if [ -z "$TEST_TEMP" ]; then
14 echo The TestKit could not be automatically located.
18 if [ -z "$TESTKIT_SENTINEL" ]; then echo Please run prepare_tools.sh before testing.; exit 3; fi
19 source "$TESTKIT_ROOT/library/establish_environment.sh"
23 # a test environment initializer method called directly by shunit.
24 # you can add your own code here that is needed before the test run starts.
28 # this exact test should always be the first one in a test suite.
31 # make sure the test environment is good.
33 assertEquals "sanity test" 0 $?
36 testCleaningPriorTestRun()
38 # take steps to clean last test, if any are needed.
45 assertEquals "doing that thing should work" 0 $?
50 echo doing another thing here
51 assertEquals "doing that other thing should work" 0 $?
53 echo "about to cause a failure, to test assertNotEquals..."
55 assertNotEquals "an explicit failure should be seen" 0 $?
60 echo running through shunit tests available.
62 # values must be the same.
63 assertEquals "equals test" 5 5
65 # similar test, different name.
66 assertSame "same test" oof oof
68 # values must not be the same.
69 assertNotEquals "not equals test" 3 5
71 # a parallel not same test.
72 assertNotSame "not same test" orp 3
74 # value must have no content (or not be defined).
75 assertNull "empty null test" ""
76 assertNull "undefined null test" "$variableDoesntExistOrShouldntSinceWeDidntDefineIt"
78 # value must have content.
79 assertNotNull "not null test" "sugarwater"
81 # value must be true, which in bash means equal to zero.
82 assertTrue "true test simple" 0
83 # this shows how true return value can be tested.
85 assertTrue "true test return value" $?
87 # value must be false, or non-zero.
88 assertFalse "false test simple" 13
89 # shows how false return value can be tested.
91 assertFalse "false test" $?
96 # the failures below are intentionally skipped, so as to avoid the failure
97 # results in our full output.
98 # this shows two things; how to skip the rest of the tests if needed,
99 # and how to cause a test failure without using an assertion.
101 # show if we're skipping already.
103 if [ $? -eq 0 ]; then
104 echo we are skipping tests.
106 echo we are not skipping tests.
109 # start skipping tests.
112 # show that we're skipping.
114 if [ $? -eq 0 ]; then
115 echo we are skipping tests.
117 echo we are not skipping tests.
120 # can be used to set a test failed state, without using an assertion.
121 # this might be used if there is complex logic and one doesn't feel
122 # like boiling that down to a single variable to test on.
123 fail "one of the tests above failed"
125 # indicates a failure because two values were not the same.
126 failNotSame "values should have been the same" toyBoat oatBoy
128 # indicates a failure when two values should have been different.
129 failSame "values should not have been the same" 3 3
131 # stop skipping tests again.
134 # show that we're no longer skipping.
136 if [ $? -eq 0 ]; then
137 echo we are skipping tests.
139 echo we are not skipping tests.
142 assertSame "shunit is cool" cool cool
146 # cleaning up after test, if needed.
150 # load and run shUnit2
151 source "$SHUNIT_DIR/shunit2"