added more example assertions and shunit docs in blank
[feisty_meow.git] / testkit / examples / blank_test.sh
1 #!/bin/bash
2
3 # Test: Blank
4 # Author: Fill ItIn
5
6 export WORKDIR="$( \cd "$(\dirname "$0")" && \pwd )"  # obtain the script's working directory.
7 cd "$WORKDIR"
8
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.
11 relative_depth=".."
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.
15   exit 1
16 fi
17
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"
20
21 oneTimeSetUp()
22 {
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.
25   true
26 }
27
28 # this exact test should always be the first one in a test suite.
29 testSanity()
30 {
31   # make sure the test environment is good.
32   sanity_test_and_init
33   assertEquals "sanity test" 0 $?
34 }
35
36 testCleaningPriorTestRun()
37 {
38   # take steps to clean last test, if any are needed.
39   true
40 }
41
42 testDoAThing()
43 {
44   echo doing one thing
45   assertEquals "doing that thing should work" 0 $?
46 }
47
48 testDoAnotherThing()
49 {
50   echo doing another thing here
51   assertEquals "doing that other thing should work" 0 $?
52
53   echo "about to cause a failure, to test assertNotEquals..."
54   false
55   assertNotEquals "an explicit failure should be seen" 0 $?
56 }
57
58 testShunitExamples()
59 {
60   echo running through shunit tests available.
61
62   # values must be the same.
63   assertEquals "equals test" 5 5
64
65   # similar test, different name.
66   assertSame "same test" oof oof
67
68   # values must not be the same.
69   assertNotEquals "not equals test" 3 5
70
71   # a parallel not same test.
72   assertNotSame "not same test" orp 3
73   
74   # value must have no content (or not be defined).
75   assertNull "empty null test" ""
76   assertNull "undefined null test" "$variableDoesntExistOrShouldntSinceWeDidntDefineIt"
77
78   # value must have content.
79   assertNotNull "not null test" "sugarwater"
80
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.
84   true
85   assertTrue "true test return value" $?
86
87   # value must be false, or non-zero.
88   assertFalse "false test simple" 13
89   # shows how false return value can be tested.
90   false
91   assertFalse "false test" $?
92 }
93
94 testShowSkipping()
95 {
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.
100   
101   # show if we're skipping already.
102   isSkipping
103   if [ $? -eq 0 ]; then
104     echo we are skipping tests.
105   else
106     echo we are not skipping tests.
107   fi
108
109   # start skipping tests.
110   startSkipping
111
112   # show that we're skipping.
113   isSkipping
114   if [ $? -eq 0 ]; then
115     echo we are skipping tests.
116   else
117     echo we are not skipping tests.
118   fi
119
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"
124
125   # indicates a failure because two values were not the same.
126   failNotSame "values should have been the same" toyBoat oatBoy
127
128   # indicates a failure when two values should have been different.
129   failSame "values should not have been the same" 3 3
130
131   # stop skipping tests again.
132   endSkipping
133
134   # show that we're no longer skipping.
135   isSkipping
136   if [ $? -eq 0 ]; then
137     echo we are skipping tests.
138   else
139     echo we are not skipping tests.
140   fi
141
142   assertSame "shunit is cool" cool cool
143 }
144
145 oneTimeTearDown() {
146   # cleaning up after test, if needed.
147   true
148 }
149
150 # load and run shUnit2
151 source "$SHUNIT_DIR/shunit2"
152