blob: 77308d07a85c96eea9ed5583a54b15b8cc9beeaf [file] [log] [blame]
Li-Yu Yu83b1b302023-02-22 20:39:00 +08001# 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
7from chromite.lib import cros_build_lib
8from chromite.lib import cros_test_lib
9from chromite.scripts import clang_format
10
11
Li-Yu Yu83b1b302023-02-22 20:39:00 +080012class 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() {}")