check.py revision 262339
1#!/usr/bin/env python
2#
3# check.py :  Run all the test cases.
4#
5# ====================================================================
6#   Copyright 2013 Justin Erenkrantz and Greg Stein
7#
8#   Licensed under the Apache License, Version 2.0 (the "License");
9#   you may not use this file except in compliance with the License.
10#   You may obtain a copy of the License at
11#
12#        http://www.apache.org/licenses/LICENSE-2.0
13#
14#   Unless required by applicable law or agreed to in writing, software
15#   distributed under the License is distributed on an "AS IS" BASIS,
16#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17#   See the License for the specific language governing permissions and
18#   limitations under the License.
19# ====================================================================
20
21import sys
22import glob
23import subprocess
24import os
25
26
27if __name__ == '__main__':
28  # get the test directory from the commandline, if set.
29  if len(sys.argv) > 1:
30    testdir = sys.argv[1]
31  else:
32    testdir = 'test'
33
34  # define test executable paths
35  if sys.platform == 'win32':
36    SERF_RESPONSE_EXE = 'serf_response.exe'
37    TEST_ALL_EXE = 'test_all.exe'
38  else:
39    SERF_RESPONSE_EXE = 'serf_response'
40    TEST_ALL_EXE = 'test_all'
41  SERF_RESPONSE_EXE = os.path.join(testdir, SERF_RESPONSE_EXE)
42  TEST_ALL_EXE = os.path.join(testdir, TEST_ALL_EXE)
43
44  # Find test responses and run them one by one
45  for case in glob.glob(testdir + "/testcases/*.response"):
46    print "== Testing %s ==" % (case)
47    try:
48      subprocess.check_call([SERF_RESPONSE_EXE, case])
49    except subprocess.CalledProcessError:
50      print "ERROR: test case %s failed" % (case)
51      sys.exit(1)
52
53  print "== Running the unit tests =="
54  try:
55    subprocess.check_call(TEST_ALL_EXE)
56  except subprocess.CalledProcessError:
57    print "ERROR: test(s) failed in test_all"
58    sys.exit(1)
59