Exemplo n.º 1
0
def gtest_list_tests(cmd, cwd):
  """List all the test cases for a google test.

  See more info at http://code.google.com/p/googletest/.
  """
  cmd = cmd[:]
  cmd.append('--gtest_list_tests')
  env = setup_gtest_env()
  timeout = 0.
  try:
    out, err, returncode, _ = subprocess42.call_with_timeout(
        cmd,
        timeout,
        stderr=subprocess42.PIPE,
        env=env,
        cwd=cwd)
  except OSError, e:
    raise Failure('Failed to run %s\ncwd=%s\n%s' % (' '.join(cmd), cwd, str(e)))
Exemplo n.º 2
0
  def test_call_with_timeout(self):
    timedout = 1 if sys.platform == 'win32' else -9
    # Format is:
    # ( (cmd, stderr_pipe, timeout), (stdout, stderr, returncode) ), ...
    test_data = [
      # 0 means no timeout, like None.
      (
        (['out_sleeping', '0.001', 'out_slept', 'err_print'], None, 0),
        ('Sleeping.\nSlept.\n', None, 0),
      ),
      (
        (['err_print'], subprocess42.STDOUT, 0),
        ('printing', None, 0),
      ),
      (
        (['err_print'], subprocess42.PIPE, 0),
        ('', 'printing', 0),
      ),

      # On a loaded system, this can be tight.
      (
        (['out_sleeping', 'out_flush', '100', 'out_slept'], None, 0.5),
        ('Sleeping.\n', '', timedout),
      ),
      (
        (
          # Note that err_flush is necessary on Windows but not on the other
          # OSes. This means the likelihood of missing stderr output from a
          # killed child process on Windows is much higher than on other OSes.
          [
            'out_sleeping', 'out_flush', 'err_print', 'err_flush', '100',
            'out_slept',
          ],
          subprocess42.PIPE,
          0.5),
        ('Sleeping.\n', 'printing', timedout),
      ),

      (
        (['out_sleeping', '0.001', 'out_slept'], None, 100),
        ('Sleeping.\nSlept.\n', '', 0),
      ),
    ]
    for i, (data, expected) in enumerate(test_data):
      stdout, stderr, code, duration = subprocess42.call_with_timeout(
          [sys.executable, OUTPUT] + data[0],
          stderr=data[1],
          timeout=data[2])
      self.assertTrue(duration > 0.0001, (data, duration))
      self.assertEqual(
          (i, stdout, stderr, code),
          (i,
            to_native_eol(expected[0]),
            to_native_eol(expected[1]),
            expected[2]))

      # Try again with universal_newlines=True.
      stdout, stderr, code, duration = subprocess42.call_with_timeout(
          [sys.executable, OUTPUT] + data[0],
          stderr=data[1],
          timeout=data[2],
          universal_newlines=True)
      self.assertTrue(duration > 0.0001, (data, duration))
      self.assertEqual(
          (i, stdout, stderr, code),
          (i,) + expected)
Exemplo n.º 3
0
    def test_call_with_timeout(self):
        timedout = 1 if sys.platform == 'win32' else -9
        # Format is:
        # ( (cmd, stderr_pipe, timeout), (stdout, stderr, returncode) ), ...
        test_data = [
            # 0 means no timeout, like None.
            (
                (['out_sleeping', '0.001', 'out_slept', 'err_print'], None, 0),
                ('Sleeping.\nSlept.\n', None, 0),
            ),
            (
                (['err_print'], subprocess42.STDOUT, 0),
                ('printing', None, 0),
            ),
            (
                (['err_print'], subprocess42.PIPE, 0),
                ('', 'printing', 0),
            ),

            # On a loaded system, this can be tight.
            (
                (['out_sleeping', 'out_flush', '100', 'out_slept'], None, 0.5),
                ('Sleeping.\n', '', timedout),
            ),
            (
                (
                    # Note that err_flush is necessary on Windows but not on the other
                    # OSes. This means the likelihood of missing stderr output from a
                    # killed child process on Windows is much higher than on other OSes.
                    [
                        'out_sleeping',
                        'out_flush',
                        'err_print',
                        'err_flush',
                        '100',
                        'out_slept',
                    ],
                    subprocess42.PIPE,
                    0.5),
                ('Sleeping.\n', 'printing', timedout),
            ),
            (
                (['out_sleeping', '0.001', 'out_slept'], None, 100),
                ('Sleeping.\nSlept.\n', '', 0),
            ),
        ]
        for i, (data, expected) in enumerate(test_data):
            stdout, stderr, code, duration = subprocess42.call_with_timeout(
                [sys.executable, OUTPUT] + data[0],
                stderr=data[1],
                timeout=data[2])
            self.assertTrue(duration > 0.0001, (data, duration))
            self.assertEqual(
                (i, stdout, stderr, code), (i, to_native_eol(
                    expected[0]), to_native_eol(expected[1]), expected[2]))

            # Try again with universal_newlines=True.
            stdout, stderr, code, duration = subprocess42.call_with_timeout(
                [sys.executable, OUTPUT] + data[0],
                stderr=data[1],
                timeout=data[2],
                universal_newlines=True)
            self.assertTrue(duration > 0.0001, (data, duration))
            self.assertEqual((i, stdout, stderr, code), (i, ) + expected)