Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions test/cli/helloworld_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Get Visual Studio configurations checking a file
# Checking {file} {config}...
def getVsConfigs(stdout, filename):
def __getVsConfigs(stdout, filename):
ret = []
for line in stdout.split('\n'):
if not line.startswith('Checking %s ' % filename):
Expand Down Expand Up @@ -148,7 +148,7 @@ def test_vs_project_local_path():
]
ret, stdout, stderr = cppcheck(args, cwd=__proj_dir)
assert ret == 0, stdout
assert getVsConfigs(stdout, 'main.c') == 'Debug|Win32 Debug|x64 Release|Win32 Release|x64'
assert __getVsConfigs(stdout, 'main.c') == 'Debug|Win32 Debug|x64 Release|Win32 Release|x64'
assert stderr == '[main.c:5]: (error) Division by zero.\n'

def test_vs_project_relative_path():
Expand All @@ -159,7 +159,7 @@ def test_vs_project_relative_path():
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
filename = os.path.join(__proj_dir, 'main.c')
assert ret == 0, stdout
assert getVsConfigs(stdout, filename) == 'Debug|Win32 Debug|x64 Release|Win32 Release|x64'
assert __getVsConfigs(stdout, filename) == 'Debug|Win32 Debug|x64 Release|Win32 Release|x64'
assert stderr == '[%s:5]: (error) Division by zero.\n' % filename

def test_vs_project_absolute_path():
Expand All @@ -170,7 +170,7 @@ def test_vs_project_absolute_path():
ret, stdout, stderr = cppcheck(args)
filename = os.path.join(__proj_dir, 'main.c')
assert ret == 0, stdout
assert getVsConfigs(stdout, filename) == 'Debug|Win32 Debug|x64 Release|Win32 Release|x64'
assert __getVsConfigs(stdout, filename) == 'Debug|Win32 Debug|x64 Release|Win32 Release|x64'
assert stderr == '[%s:5]: (error) Division by zero.\n' % filename

def test_cppcheck_project_local_path():
Expand All @@ -181,7 +181,7 @@ def test_cppcheck_project_local_path():
]
ret, stdout, stderr = cppcheck(args, cwd=__proj_dir)
assert ret == 0, stdout
assert getVsConfigs(stdout, 'main.c') == 'Debug|x64'
assert __getVsConfigs(stdout, 'main.c') == 'Debug|x64'
assert stderr == '[main.c:5]: (error) Division by zero.\n'

def test_cppcheck_project_relative_path():
Expand All @@ -193,7 +193,7 @@ def test_cppcheck_project_relative_path():
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
filename = os.path.join('helloworld', 'main.c')
assert ret == 0, stdout
assert getVsConfigs(stdout, filename) == 'Debug|x64'
assert __getVsConfigs(stdout, filename) == 'Debug|x64'
assert stderr == '[%s:5]: (error) Division by zero.\n' % filename

def test_cppcheck_project_absolute_path():
Expand All @@ -205,7 +205,7 @@ def test_cppcheck_project_absolute_path():
ret, stdout, stderr = cppcheck(args)
filename = os.path.join(__proj_dir, 'main.c')
assert ret == 0, stdout
assert getVsConfigs(stdout, filename) == 'Debug|x64'
assert __getVsConfigs(stdout, filename) == 'Debug|x64'
assert stderr == '[%s:5]: (error) Division by zero.\n' % filename

def test_suppress_command_line_related():
Expand Down
24 changes: 12 additions & 12 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def test_preprocessor_error(tmpdir):
assert exitcode != 0


ANSI_BOLD = "\x1b[1m"
ANSI_FG_RED = "\x1b[31m"
ANSI_FG_DEFAULT = "\x1b[39m"
ANSI_FG_RESET = "\x1b[0m"
__ANSI_BOLD = "\x1b[1m"
__ANSI_FG_RED = "\x1b[31m"
__ANSI_FG_DEFAULT = "\x1b[39m"
__ANSI_FG_RESET = "\x1b[0m"


@pytest.mark.parametrize("env,color_expected", [({"CLICOLOR_FORCE":"1"}, True), ({"NO_COLOR": "1", "CLICOLOR_FORCE":"1"}, False)])
Expand All @@ -101,10 +101,10 @@ def test_color_non_tty(tmpdir, env, color_expected):

assert exitcode == 0
assert stderr
assert (ANSI_BOLD in stderr) == color_expected
assert (ANSI_FG_RED in stderr) == color_expected
assert (ANSI_FG_DEFAULT in stderr) == color_expected
assert (ANSI_FG_RESET in stderr) == color_expected
assert (__ANSI_BOLD in stderr) == color_expected
assert (__ANSI_FG_RED in stderr) == color_expected
assert (__ANSI_FG_DEFAULT in stderr) == color_expected
assert (__ANSI_FG_RESET in stderr) == color_expected


@pytest.mark.skipif(sys.platform == "win32", reason="TTY not supported in Windows")
Expand All @@ -117,10 +117,10 @@ def test_color_tty(tmpdir, env, color_expected):

assert exitcode == 0
assert stderr
assert (ANSI_BOLD in stderr) == color_expected
assert (ANSI_FG_RED in stderr) == color_expected
assert (ANSI_FG_DEFAULT in stderr) == color_expected
assert (ANSI_FG_RESET in stderr) == color_expected
assert (__ANSI_BOLD in stderr) == color_expected
assert (__ANSI_FG_RED in stderr) == color_expected
assert (__ANSI_FG_DEFAULT in stderr) == color_expected
assert (__ANSI_FG_RESET in stderr) == color_expected


def test_invalid_library(tmpdir):
Expand Down
8 changes: 4 additions & 4 deletions test/cli/premium_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

from testutils import cppcheck, __lookup_cppcheck_exe

PRODUCT_NAME = 'Cppcheck Premium ' + str(time.time())
__PRODUCT_NAME = 'Cppcheck Premium ' + str(time.time())


def copy_cppcheck_premium(tmpdir):
def __copy_cppcheck_premium(tmpdir):
exe = shutil.copy2(__lookup_cppcheck_exe(), tmpdir)

# add minimum cfg/std.cfg
Expand All @@ -28,7 +28,7 @@ def copy_cppcheck_premium(tmpdir):
"about": "NAME",
"safety": true
}
""".replace('NAME', PRODUCT_NAME))
""".replace('NAME', __PRODUCT_NAME))

return exe

Expand All @@ -42,7 +42,7 @@ def test_misra_c_builtin_style_checks(tmpdir):
with open(test_file, 'wt') as f:
f.write('void foo() { int x; y = 0; }')

exe = copy_cppcheck_premium(tmpdir)
exe = __copy_cppcheck_premium(tmpdir)

exitcode, _, stderr = cppcheck(['--premium=autosar', '--xml', test_file], cppcheck_exe=exe)
assert exitcode == 0
Expand Down
24 changes: 12 additions & 12 deletions test/cli/project_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_missing_project(project_ext):
assert "" == stderr


def _test_project_error(tmpdir, ext, content, expected):
def __test_project_error(tmpdir, ext, content, expected):
project_file = os.path.join(tmpdir, "file.{}".format(ext))

with open(project_file, 'w') as f:
Expand All @@ -38,7 +38,7 @@ def _test_project_error(tmpdir, ext, content, expected):
("cppcheck", "Cppcheck GUI project file is not a valid XML - XML_ERROR_EMPTY_DOCUMENT")
])
def test_empty_project(tmpdir, project_ext, expected):
_test_project_error(tmpdir, project_ext, None, expected)
__test_project_error(tmpdir, project_ext, None, expected)


def test_json_entry_file_not_found(tmpdir):
Expand All @@ -53,7 +53,7 @@ def test_json_entry_file_not_found(tmpdir):
if sys.platform == "win32":
expected = expected.replace('\\', '/')

_test_project_error(tmpdir, "json", json.dumps(compilation_db), expected)
__test_project_error(tmpdir, "json", json.dumps(compilation_db), expected)


def test_json_no_arguments(tmpdir):
Expand All @@ -65,7 +65,7 @@ def test_json_no_arguments(tmpdir):

expected = "no 'arguments' or 'command' field found in compilation database entry"

_test_project_error(tmpdir, "json", json.dumps(compilation_db), expected)
__test_project_error(tmpdir, "json", json.dumps(compilation_db), expected)


def test_json_invalid_arguments(tmpdir):
Expand All @@ -78,15 +78,15 @@ def test_json_invalid_arguments(tmpdir):

expected = "'arguments' field in compilation database entry is not a JSON array"

_test_project_error(tmpdir, "json", json.dumps(compilation_db), expected)
__test_project_error(tmpdir, "json", json.dumps(compilation_db), expected)


def test_sln_invalid_file(tmpdir):
content = "some file"

expected = "Visual Studio solution file header not found"

_test_project_error(tmpdir, "sln", content, expected)
__test_project_error(tmpdir, "sln", content, expected)


def test_sln_no_header(tmpdir):
Expand All @@ -95,7 +95,7 @@ def test_sln_no_header(tmpdir):

expected = "Visual Studio solution file header not found"

_test_project_error(tmpdir, "sln", content, expected)
__test_project_error(tmpdir, "sln", content, expected)


def test_sln_no_projects(tmpdir):
Expand All @@ -104,7 +104,7 @@ def test_sln_no_projects(tmpdir):

expected = "no projects found in Visual Studio solution file"

_test_project_error(tmpdir, "sln", content, expected)
__test_project_error(tmpdir, "sln", content, expected)


def test_sln_project_file_not_found(tmpdir):
Expand All @@ -124,28 +124,28 @@ def test_sln_project_file_not_found(tmpdir):
if sys.platform == "win32":
expected = expected.replace('\\', '/')

_test_project_error(tmpdir, "sln", content, expected)
__test_project_error(tmpdir, "sln", content, expected)


def test_vcxproj_no_xml_root(tmpdir):
content = '<?xml version="1.0" encoding="utf-8"?>'

expected = "Visual Studio project file has no XML root node"

_test_project_error(tmpdir, "vcxproj", content, expected)
__test_project_error(tmpdir, "vcxproj", content, expected)


def test_bpr_no_xml_root(tmpdir):
content = '<?xml version="1.0" encoding="utf-8"?>'

expected = "Borland project file has no XML root node"

_test_project_error(tmpdir, "bpr", content, expected)
__test_project_error(tmpdir, "bpr", content, expected)


def test_cppcheck_no_xml_root(tmpdir):
content = '<?xml version="1.0" encoding="utf-8"?>'

expected = "Cppcheck GUI project file has no XML root node"

_test_project_error(tmpdir, "cppcheck", content, expected)
__test_project_error(tmpdir, "cppcheck", content, expected)