diff options
| author | Lei YU <yulei.sh@bytedance.com> | 2023-08-30 06:47:14 +0000 |
|---|---|---|
| committer | Jussi Pakkanen <jpakkane@gmail.com> | 2023-09-25 16:25:01 +0300 |
| commit | 8d6b474bf67bb8a75e8f60196f7eaf7528a85c62 (patch) | |
| tree | 1a5d56603a4e64c6878577ba45fb3af15ebf2fd8 /unittests/allplatformstests.py | |
| parent | f20f33149495b5b43bba5f06aa5b9ff4ee59a474 (diff) | |
| download | meson-8d6b474bf67bb8a75e8f60196f7eaf7528a85c62.tar.gz | |
Add clang-tidy-fix target
Add the `clang-tidy-fix` target to apply clang-tidy fixes to the source
code.
This is done by calling `run-clang-tidy` with `-fix` argument.
Add a test case to run `clang-tidy-fix` and verify the file is changed.
Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Diffstat (limited to 'unittests/allplatformstests.py')
| -rw-r--r-- | unittests/allplatformstests.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index acab026e9..f06279a2f 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py @@ -42,7 +42,7 @@ from mesonbuild.mesonlib import ( is_sunos, windows_proof_rmtree, python_command, version_compare, split_args, quote_arg, relpath, is_linux, git, search_version, do_conf_file, do_conf_str, default_prefix, MesonException, EnvironmentException, OptionKey, - windows_proof_rm + windows_proof_rm, quiet_git ) from mesonbuild.programs import ExternalProgram @@ -3029,6 +3029,26 @@ class AllPlatformTests(BasePlatformTests): self.assertIn('cttest.cpp:4:20', out) self.assertNotIn(dummydir, out) + @skipIfNoExecutable('clang-tidy') + @unittest.skipIf(not is_git_repo(), 'Skipping because this is not in git repo') + def test_clang_tidy_fix(self): + if self.backend is not Backend.ninja: + raise SkipTest(f'Clang-tidy is for now only supported on Ninja, not {self.backend.name}') + if shutil.which('c++') is None: + raise SkipTest('Clang-tidy breaks when ccache is used and "c++" not in path.') + if is_osx(): + raise SkipTest('Apple ships a broken clang-tidy that chokes on -pipe.') + testdir = os.path.join(self.unit_test_dir, '68 clang-tidy') + dummydir = os.path.join(testdir, 'dummydir.h') + self.init(testdir, override_envvars={'CXX': 'c++'}) + out = self.run_target('clang-tidy-fix') + self.assertIn('cttest.cpp:4:20', out) + self.assertNotIn(dummydir, out) + ret = quiet_git(['diff', '--exit-code', 'test cases/unit/68 clang-tidy/cttest.cpp'], '.') + self.assertFalse(ret[0]) + # Restore the file + quiet_git(['checkout', '--', 'test cases/unit/68 clang-tidy/cttest.cpp'], '.') + def test_identity_cross(self): testdir = os.path.join(self.unit_test_dir, '69 cross') # Do a build to generate a cross file where the host is this target |
