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