Li-Yu Yu | 83b1b30 | 2023-02-22 20:39:00 +0800 | [diff] [blame] | 1 | # Copyright 2023 The ChromiumOS Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Tests the clang-format wrapper.""" |
| 6 | |
| 7 | from chromite.lib import cros_build_lib |
| 8 | from chromite.lib import cros_test_lib |
| 9 | from chromite.scripts import clang_format |
| 10 | |
| 11 | |
Li-Yu Yu | 83b1b30 | 2023-02-22 20:39:00 +0800 | [diff] [blame] | 12 | class ClangFormatTest(cros_test_lib.TestCase): |
| 13 | """Tests the clang-format wrapper.""" |
| 14 | |
| 15 | def testClangFormatVersion(self): |
| 16 | """Check that clang-format can return the version.""" |
| 17 | with clang_format.ClangFormat() as prog: |
| 18 | result = cros_build_lib.run( |
| 19 | [prog, "--version"], |
| 20 | encoding="utf-8", |
| 21 | capture_output=True, |
| 22 | ) |
| 23 | self.assertStartsWith(result.stdout, "clang-format version ") |
| 24 | |
| 25 | def testClangFormatStdin(self): |
| 26 | """Check clang-format can format from stdin.""" |
| 27 | with clang_format.ClangFormat() as prog: |
| 28 | result = cros_build_lib.run( |
| 29 | [prog, "--style={BasedOnStyle: Chromium}"], |
| 30 | input="int main(){ }", |
| 31 | encoding="utf-8", |
| 32 | capture_output=True, |
| 33 | ) |
| 34 | self.assertEqual(result.stdout, "int main() {}") |