My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
#
# Run all common_schema tests
#

export MYSQL_USER=$1
export MYSQL_PASSWORD=$2
export MYSQL_SOCKET=$3
export MYSQL_SCHEMA=common_schema

export INITIAL_PATH=$(pwd)
export TESTS_ROOT_PATH=${INITIAL_PATH}/root

export TEST_OUTPUT_PATH=/tmp
export TEST_OUTPUT_FILE=common_schema_test_output.txt
export TEST_ERROR_FILE=common_schema_test_error.txt
export DIFF_OUTPUT_FILE=common_schema_test_diff.txt

let num_tests=0

cd $TESTS_ROOT_PATH

if [ -f pre.sql ] ; then
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --socket=$MYSQL_SOCKET $MYSQL_SCHEMA < pre.sql
if [ $? -ne 0 ] ; then
echo "Test startup failed on pre.sql"
exit 1
fi
fi

for TEST_FAMILY_PATH in $(find * -maxdepth 0 -type d)
do
# Test family: suite of tests, testing a specific feature or feature set
echo "Testing family: ${TEST_FAMILY_PATH}"
cd $TESTS_ROOT_PATH/$TEST_FAMILY_PATH
if [ -f pre.sql ] ; then
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --socket=$MYSQL_SOCKET $MYSQL_SCHEMA < pre.sql
if [ $? -ne 0 ] ; then
echo "Test family ${TEST_FAMILY_PATH} failed on pre.sql"
exit 1
fi
fi

for TEST_PATH in $(find * -maxdepth 0 -type d)
do
# Particular test
cd $TESTS_ROOT_PATH/$TEST_FAMILY_PATH/$TEST_PATH

# verbose
if [ -f description.txt ] ; then
export TEST_BRIEF_DESCRIPTION="$(cat description.txt | head -n 1 | cut -c 1-60)"
else
export TEST_BRIEF_DESCRIPTION=""
fi
echo " ${TEST_FAMILY_PATH}/${TEST_PATH}: ${TEST_BRIEF_DESCRIPTION}"

# prepare test
if [ -f pre.sql ] ; then
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --socket=$MYSQL_SOCKET $MYSQL_SCHEMA < pre.sql
if [ $? -ne 0 ] ; then
echo "Test ${TEST_FAMILY_PATH}/${TEST_PATH} failed on pre.sql"
exit 1
fi
fi

# execute test code
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --socket=$MYSQL_SOCKET $MYSQL_SCHEMA --silent --raw < test.sql > ${TEST_OUTPUT_PATH}/${TEST_OUTPUT_FILE} 2> ${TEST_OUTPUT_PATH}/${TEST_ERROR_FILE}
if [ $? -eq 0 ] ; then
# check test results
if [ -f error_expected.txt ] ; then
# error is expected. How come no error?
echo "Test ${TEST_FAMILY_PATH}/${TEST_PATH} failed on test.sql; expected error, found none"
exit 1
fi
if [ -f expected.txt ] ; then
# There is an "expected.txt" file: results must match that file
diff expected.txt ${TEST_OUTPUT_PATH}/${TEST_OUTPUT_FILE} > ${TEST_OUTPUT_PATH}/${DIFF_OUTPUT_FILE}
if [ $? -ne 0 ] ; then
echo "** Test ${TEST_FAMILY_PATH}/${TEST_PATH} failed: unexpected output."
echo "** Output: ${TEST_OUTPUT_PATH}/${TEST_OUTPUT_FILE}"
echo "** Expected: $(pwd)/expected.txt"
echo "** Diff: ${TEST_OUTPUT_PATH}/${DIFF_OUTPUT_FILE}"

exit 1
fi
else
# No explicit "expected.txt" result.
# By default, we expect "1"
TEST_RESULT=$(cat ${TEST_OUTPUT_PATH}/${TEST_OUTPUT_FILE})
if [ "$TEST_RESULT" != "1" ] ; then
echo "Test ${TEST_FAMILY_PATH}/${TEST_PATH} failed: got $TEST_RESULT"
exit 1
fi
fi
else
# Test executes with error
if [ -f error_expected.txt ] ; then
# error is expected
:
else
echo "Test ${TEST_FAMILY_PATH}/${TEST_PATH} failed on test.sql"
echo "** Error: " $(cat ${TEST_OUTPUT_PATH}/${TEST_ERROR_FILE})
exit 1
fi
fi

# post test code (typically cleanup)
if [ -f post.sql ] ; then
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --socket=$MYSQL_SOCKET $MYSQL_SCHEMA < post.sql
if [ $? -ne 0 ] ; then
echo "Test ${TEST_FAMILY_PATH}/${TEST_PATH} failed on post.sql"
exit 1
fi
fi
let num_tests=num_tests+1
done
# Post family code (typicaly cleanup)
if [ -f post.sql ] ; then
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --socket=$MYSQL_SOCKET $MYSQL_SCHEMA < post.sql
if [ $? -ne 0 ] ; then
echo "Test family ${TEST_FAMILY_PATH} failed on post.sql"
exit 1
fi
fi
done

cd $TESTS_ROOT_PATH
if [ -f post.sql ] ; then
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --socket=$MYSQL_SOCKET $MYSQL_SCHEMA < post.sql
if [ $? -ne 0 ] ; then
echo "Test cleanup failed on post.sql"
exit 1
fi
fi

echo "Tests complete. Total num tests: ${num_tests}"

cd ${INITIAL_PATH}

Change log

r194 by shlomi.noach on Dec 27, 2011   Diff
test_all.sh: not echoing error when
expected
Go to: 
Project members, sign in to write a code review

Older revisions

r186 by shlomi.noach on Dec 17, 2011   Diff
tests allowed to throw error, accepted
as test-pass indicator using the
error_expected.txt test file.
r140 by shlomi.noach on Oct 15, 2011   Diff
Documentation:
- various text routines
- security routines
- other fixes
minor fixes to text routines internal
...
r120 by shlomi.noach on Oct 4, 2011   Diff
test_all.sh: now accepts
- global pre/post
- post script per family
- post script per test
All revisions of this file

File info

Size: 4225 bytes, 138 lines
Powered by Google Project Hosting