bringing in testkit tools
[feisty_meow.git] / testkit / library / establish_environment.sh
1 #!/bin/bash
2
3 # Supports the TestKit with a few handy functions and many variables.
4 #
5 # Author: Chris Koeritz
6
7 ##############
8
9 # pull in the really basic functions...
10 source "$TESTKIT_ROOT/library/helper_methods.sh"
11
12 ##############
13
14 # this check should be called first, in oneTimeSetUp, in every test script that uses shunit.
15 # it will make sure that important facts are true about the test environment.
16 #
17 #hmmm: need to extend this to allow them to add their own sanity checks to it,
18 #      similarly to how we need to add log parsing capability as an extension.
19 #
20 function sanity_test_and_init()
21 {
22   if [ -z "$WORKDIR" ]; then
23     echo "The WORKDIR variable is not set.  This should be established by each test, near the top."
24     exit 1
25   fi
26   # establish this for shunit so tests do not have to run in current directory.
27   export SHUNIT_PARENT="$WORKDIR/$(basename "$0")"
28
29 #hmmm: add other checks here, including the user provided ones.
30
31   return 0
32 }
33
34 ##############
35
36 # this is the main source of parameters for the tests.
37 export TESTKIT_CFG_FILE
38 if [ ! -f "$TESTKIT_CFG_FILE" ]; then
39   # well, no config file variable defined, so we go with our default.
40   # this file must exist or we're stumped.
41   TESTKIT_CFG_FILE="$TESTKIT_ROOT/testkit.config"
42 fi
43 if [ ! -f "$TESTKIT_CFG_FILE" -a -z "$BADNESS" ]; then
44   echo "----"
45   echo "This script requires that you prepare a customized file in:"
46   echo "    $TESTKIT_CFG_FILE"
47   echo "    (above is current value of TESTKIT_CFG_FILE variable)"
48   echo "with the details of your testing configuration."
49   echo "There are some example config files in the folder:"
50   echo "    $TESTKIT_ROOT/examples"
51   BADNESS=true
52 fi
53
54 ##############
55
56 # make sure we aren't premature in processing the config file.
57 if [ -z "$TESTKIT_BOOTSTRAPPING" ]; then
58
59   # read the config file and generate environment variables for all the entries.
60   source "$TESTKIT_ROOT/library/process_configuration.sh"
61   define_and_export_variables
62   check_if_failed "Not all variables could be imported properly from the configuration file '$TESTKIT_CFG_FILE'"
63
64 fi
65
66 ##############
67
68 # announce status if in debugging mode.
69
70 if [ ! -z "$DEBUGGING" -a -z "$SHOWED_SETTINGS_ALREADY" ]; then
71   echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
72   echo TestKit running from: $TESTKIT_ROOT
73   echo TestKit config file: $TESTKIT_CFG_FILE
74   echo +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
75 fi
76
77 ##############
78
79 # more steps we're not ready for if still bootstrapping our environment.
80 if [ -z "$TESTKIT_BOOTSTRAPPING" ]; then
81   # try to not blast out the above block of info again during this run.
82   export SHOWED_SETTINGS_ALREADY=true
83
84   # now that we have the environment set up, we can pull in all the functions
85   # we use for running the tests...
86   source "$TESTKIT_ROOT/library/runner_functions.sh"
87   source "$TESTKIT_ROOT/library/random_ids_manager.sh"
88   #hmmm: random ids are not used yet, are they?  are they working?
89   source "$TESTKIT_ROOT/library/file_management.sh"
90
91 fi
92
93 ##############
94