summaryrefslogtreecommitdiffstats
path: root/tools/isolate/run_test_cases_test.py
blob: bfea85144a2fd80a2d907f285aac314d2d0277ef (plain)
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
#!/usr/bin/env python
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import logging
import os
import re
import subprocess
import sys
import unittest

ROOT_DIR = os.path.dirname(os.path.abspath(__file__))

sys.path.append(os.path.join(ROOT_DIR, 'data', 'gtest_fake'))
import gtest_fake


class TraceTestCases(unittest.TestCase):
  def test_simple(self):
    target = os.path.join(ROOT_DIR, 'data', 'gtest_fake', 'gtest_fake.py')
    cmd = [
        sys.executable,
        os.path.join(ROOT_DIR, 'run_test_cases.py'),
        '--no-dump',
        target,
    ]
    logging.debug(' '.join(cmd))
    proc = subprocess.Popen(
        cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # pylint is confused.
    out, err = proc.communicate() or ('', '')
    self.assertEquals(0, proc.returncode)
    if sys.platform == 'win32':
      # TODO(maruel): Figure out why replace('\r\n', '\n') doesn't work.
      out = out.replace('\r', '')
    expected = (
      'Note: Google Test filter = Baz.Fail\n'
      '\n'
      '%(test_output)s\n'
      '%(test_footer)s\n'
      '\n'
      'Success:    3 75.00%%\n'
      'Flaky:      0  0.00%%\n'
      'Fail:       1 25.00%%\n') % {
        'test_output': gtest_fake.get_test_output('Baz.Fail'),
        'test_footer': gtest_fake.get_footer(1),
      }

    self.assertTrue(
        out.startswith(expected),
        '\n'.join(['XXX', expected, 'XXX', out[:len(expected)], 'XXX']))
    remaining_actual = out[len(expected):]
    regexp = (
        r'\d+\.\ds Done running 4 tests with 6 executions. \d+\.\d test/s'
        + '\n')
    self.assertTrue(re.match(regexp, remaining_actual), remaining_actual)
    # Progress junk went to stderr.
    self.assertTrue(err.startswith('\r'), err)


if __name__ == '__main__':
  VERBOSE = '-v' in sys.argv
  logging.basicConfig(level=logging.DEBUG if VERBOSE else logging.ERROR)
  unittest.main()