Skip to content

Commit

Permalink
Add minimalistic tests
Browse files Browse the repository at this point in the history
* ensure that clang-tidy binary file exists and is executable
* run clang-tidy on a very simple C++ file

Fixes #1
  • Loading branch information
tristan0x authored and renefritze committed Jul 22, 2022
1 parent 6ae0b72 commit ac1c55e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,8 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps

# scikit-build cache
_skbuild/

clang_tidy/data/
21 changes: 15 additions & 6 deletions clang_tidy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@
def _get_executable(name):
return os.path.join(os.path.dirname(__file__), "data", "bin", name)

def _run(name):
executable = _get_executable(name)
return subprocess.call([executable] + sys.argv[1:])
def _run(name, *args):
command = [_get_executable(name)]
if args:
command += list(args)
else:
command += sys.argv[1:]
return subprocess.call(command)

def _run_python(name, *args):
command = [sys.executable, _get_executable(name)]
if args:
command += list(args)
else:
command += sys.argv[1:]

def _run_python(name):
script = _get_executable(name)
# as MS Windows is not able to run Python scripts directly by name,
# we have to call the interpreter and pass the script as parameter
return subprocess.call([sys.executable, script] + sys.argv[1:])
return subprocess.call(command)


def clang_tidy():
Expand Down
2 changes: 0 additions & 2 deletions test/test_empty.py

This file was deleted.

21 changes: 21 additions & 0 deletions test/test_executable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import tempfile

import clang_tidy


def test_executable_file():
exe = clang_tidy._get_executable("clang-tidy")
assert os.path.exists(exe), "'clang-tidy' executable is missing"
assert os.access(exe, os.X_OK), "'clang-tidy'program is not executable"


def test_include_iostream():
fd, compilation_unit = tempfile.mkstemp(suffix=".cpp")
os.close(fd)
with open(compilation_unit, "w") as ostr:
ostr.write("#include <iostream>\n")
try:
assert clang_tidy._run("clang-tidy", compilation_unit) == 0
finally:
os.remove(compilation_unit)

0 comments on commit ac1c55e

Please sign in to comment.