blob: c3fc02dfa77990e8f181838a3280ac651630ebe3 [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
12@cros_test_lib.pytestmark_network_test
13class ClangFormatTest(cros_test_lib.TestCase):
14 """Tests the clang-format wrapper."""
15
16 def testClangFormatVersion(self):
17 """Check that clang-format can return the version."""
18 with clang_format.ClangFormat() as prog:
19 result = cros_build_lib.run(
20 [prog, "--version"],
21 encoding="utf-8",
22 capture_output=True,
23 )
24 self.assertStartsWith(result.stdout, "clang-format version ")
25
26 def testClangFormatStdin(self):
27 """Check clang-format can format from stdin."""
28 with clang_format.ClangFormat() as prog:
29 result = cros_build_lib.run(
30 [prog, "--style={BasedOnStyle: Chromium}"],
31 input="int main(){ }",
32 encoding="utf-8",
33 capture_output=True,
34 )
35 self.assertEqual(result.stdout, "int main() {}")