1253893Speter#!/usr/bin/env python
2253893Speter#
3253893Speter# check.py :  Run all the test cases.
4253893Speter#
5362181Sdim# ===================================================================
6362181Sdim#   Licensed to the Apache Software Foundation (ASF) under one
7362181Sdim#   or more contributor license agreements.  See the NOTICE file
8362181Sdim#   distributed with this work for additional information
9362181Sdim#   regarding copyright ownership.  The ASF licenses this file
10362181Sdim#   to you under the Apache License, Version 2.0 (the
11362181Sdim#   "License"); you may not use this file except in compliance
12362181Sdim#   with the License.  You may obtain a copy of the License at
13362181Sdim#
14362181Sdim#     http://www.apache.org/licenses/LICENSE-2.0
15362181Sdim#
16362181Sdim#   Unless required by applicable law or agreed to in writing,
17362181Sdim#   software distributed under the License is distributed on an
18362181Sdim#   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19362181Sdim#   KIND, either express or implied.  See the License for the
20362181Sdim#   specific language governing permissions and limitations
21362181Sdim#   under the License.
22362181Sdim# ===================================================================
23253893Speter#
24253893Speter
25253893Speterimport sys
26253893Speterimport glob
27253893Speterimport subprocess
28253893Speterimport os
29253893Speter
30253893Speter
31253893Speterif __name__ == '__main__':
32253893Speter  # get the test directory from the commandline, if set.
33253893Speter  if len(sys.argv) > 1:
34253893Speter    testdir = sys.argv[1]
35253893Speter  else:
36253893Speter    testdir = 'test'
37253893Speter
38362181Sdim  if len(sys.argv) > 2:
39362181Sdim    test_builddir = sys.argv[2]
40362181Sdim  else:
41362181Sdim    test_builddir = 'test'
42362181Sdim
43253893Speter  # define test executable paths
44253893Speter  if sys.platform == 'win32':
45253893Speter    SERF_RESPONSE_EXE = 'serf_response.exe'
46253893Speter    TEST_ALL_EXE = 'test_all.exe'
47253893Speter  else:
48253893Speter    SERF_RESPONSE_EXE = 'serf_response'
49253893Speter    TEST_ALL_EXE = 'test_all'
50362181Sdim  SERF_RESPONSE_EXE = os.path.join(test_builddir, SERF_RESPONSE_EXE)
51362181Sdim  TEST_ALL_EXE = os.path.join(test_builddir, TEST_ALL_EXE)
52253893Speter
53253893Speter  # Find test responses and run them one by one
54253893Speter  for case in glob.glob(testdir + "/testcases/*.response"):
55253893Speter    print "== Testing %s ==" % (case)
56253893Speter    try:
57253893Speter      subprocess.check_call([SERF_RESPONSE_EXE, case])
58253893Speter    except subprocess.CalledProcessError:
59253893Speter      print "ERROR: test case %s failed" % (case)
60262324Speter      sys.exit(1)
61253893Speter
62253893Speter  print "== Running the unit tests =="
63253893Speter  try:
64253893Speter    subprocess.check_call(TEST_ALL_EXE)
65253893Speter  except subprocess.CalledProcessError:
66253893Speter    print "ERROR: test(s) failed in test_all"
67262324Speter    sys.exit(1)
68