Oleh Prypin | 69c0222 | 2018-05-23 15:18:12 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license |
| 6 | # that can be found in the LICENSE file in the root of the source |
| 7 | # tree. An additional intellectual property rights grant can be found |
| 8 | # in the file PATENTS. All contributing project authors may |
| 9 | # be found in the AUTHORS file in the root of the source tree. |
| 10 | |
| 11 | import unittest |
| 12 | |
| 13 | script = __import__('gtest-parallel-wrapper') # pylint: disable=invalid-name |
| 14 | |
| 15 | |
| 16 | class GtestParallelWrapperTest(unittest.TestCase): |
| 17 | @classmethod |
| 18 | def _Expected(cls, gtest_parallel_args): |
| 19 | return ['--shard_index=0', '--shard_count=1'] + gtest_parallel_args |
| 20 | |
| 21 | def testOverwrite(self): |
| 22 | result = script.ParseArgs(['--timeout=123', 'exec', '--timeout', '124']) |
| 23 | expected = self._Expected(['--timeout=124', 'exec']) |
| 24 | self.assertEqual(result.gtest_parallel_args, expected) |
| 25 | |
| 26 | def testMixing(self): |
| 27 | result = script.ParseArgs( |
| 28 | ['--timeout=123', '--param1', 'exec', '--param2', '--timeout', '124']) |
| 29 | expected = self._Expected( |
| 30 | ['--timeout=124', 'exec', '--', '--param1', '--param2']) |
| 31 | self.assertEqual(result.gtest_parallel_args, expected) |
| 32 | |
| 33 | def testMixingPositional(self): |
| 34 | result = script.ParseArgs(['--timeout=123', 'exec', '--foo1', 'bar1', |
| 35 | '--timeout', '124', '--foo2', 'bar2']) |
| 36 | expected = self._Expected(['--timeout=124', 'exec', '--', '--foo1', 'bar1', |
| 37 | '--foo2', 'bar2']) |
| 38 | self.assertEqual(result.gtest_parallel_args, expected) |
| 39 | |
| 40 | def testDoubleDash1(self): |
| 41 | result = script.ParseArgs( |
| 42 | ['--timeout', '123', 'exec', '--', '--timeout', '124']) |
| 43 | expected = self._Expected( |
| 44 | ['--timeout=123', 'exec', '--', '--timeout', '124']) |
| 45 | self.assertEqual(result.gtest_parallel_args, expected) |
| 46 | |
| 47 | def testDoubleDash2(self): |
| 48 | result = script.ParseArgs(['--timeout=123', '--', 'exec', '--timeout=124']) |
| 49 | expected = self._Expected(['--timeout=123', 'exec', '--', '--timeout=124']) |
| 50 | self.assertEqual(result.gtest_parallel_args, expected) |
| 51 | |
| 52 | def testArtifacts(self): |
| 53 | result = script.ParseArgs(['exec', '--store-test-artifacts', |
| 54 | '--output_dir', '/tmp/foo']) |
| 55 | expected = self._Expected(['--output_dir=/tmp/foo', 'exec', '--', |
| 56 | '--test_artifacts_dir=/tmp/foo/test_artifacts']) |
| 57 | self.assertEqual(result.gtest_parallel_args, expected) |
| 58 | self.assertEqual(result.output_dir, '/tmp/foo') |
| 59 | self.assertRegexpMatches(result.test_artifacts_dir, |
| 60 | '/tmp/foo.test_artifacts') |
| 61 | |
| 62 | def testNoDirsSpecified(self): |
| 63 | result = script.ParseArgs(['exec']) |
| 64 | self.assertEqual(result.output_dir, None) |
| 65 | self.assertEqual(result.test_artifacts_dir, None) |
| 66 | |
| 67 | def testOutputDirSpecified(self): |
| 68 | result = script.ParseArgs(['exec', '--output_dir', '/tmp/foo']) |
| 69 | self.assertEqual(result.output_dir, '/tmp/foo') |
| 70 | self.assertEqual(result.test_artifacts_dir, None) |
| 71 | |
| 72 | def testJsonTestResults(self): |
| 73 | result = script.ParseArgs(['--isolated-script-test-output', '/tmp/foo', |
| 74 | 'exec']) |
| 75 | expected = self._Expected(['--dump_json_test_results=/tmp/foo', 'exec']) |
| 76 | self.assertEqual(result.gtest_parallel_args, expected) |
| 77 | |
| 78 | def testShortArg(self): |
| 79 | result = script.ParseArgs(['-d', '/tmp/foo', 'exec']) |
| 80 | expected = self._Expected(['--output_dir=/tmp/foo', 'exec']) |
| 81 | self.assertEqual(result.gtest_parallel_args, expected) |
| 82 | self.assertEqual(result.output_dir, '/tmp/foo') |
| 83 | |
| 84 | def testBoolArg(self): |
| 85 | result = script.ParseArgs(['--gtest_also_run_disabled_tests', 'exec']) |
| 86 | expected = self._Expected(['--gtest_also_run_disabled_tests', 'exec']) |
| 87 | self.assertEqual(result.gtest_parallel_args, expected) |
| 88 | |
| 89 | def testNoArgs(self): |
| 90 | result = script.ParseArgs(['exec']) |
| 91 | expected = self._Expected(['exec']) |
| 92 | self.assertEqual(result.gtest_parallel_args, expected) |
| 93 | |
| 94 | def testDocExample(self): |
| 95 | result = script.ParseArgs([ |
| 96 | 'some_test', '--some_flag=some_value', '--another_flag', |
| 97 | '--output_dir=SOME_OUTPUT_DIR', '--store-test-artifacts', |
| 98 | '--isolated-script-test-output=SOME_DIR', |
| 99 | '--isolated-script-test-perf-output=SOME_OTHER_DIR', |
| 100 | '--foo=bar', '--baz']) |
| 101 | expected = self._Expected([ |
| 102 | '--output_dir=SOME_OUTPUT_DIR', '--dump_json_test_results=SOME_DIR', |
| 103 | 'some_test', '--', |
| 104 | '--test_artifacts_dir=SOME_OUTPUT_DIR/test_artifacts', |
| 105 | '--some_flag=some_value', '--another_flag', |
| 106 | '--isolated-script-test-perf-output=SOME_OTHER_DIR', |
| 107 | '--foo=bar', '--baz']) |
| 108 | self.assertEqual(result.gtest_parallel_args, expected) |
| 109 | |
| 110 | |
| 111 | if __name__ == '__main__': |
| 112 | unittest.main() |