Skip to content

Commit 710f8c2

Browse files
committed
test
1 parent ee3f72a commit 710f8c2

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎lib/preprocessor.cpp‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ bool Preprocessor::loadAllIncludes(std::vector<std::string> &files)
839839

840840
simplecpp::OutputList outputList;
841841
mFileCache = simplecpp::load(mTokens, files, dui, &outputList, std::move(mFileCache));
842+
reportSimplecppPortability(outputList);
842843
return !handleErrors(outputList);
843844
}
844845

@@ -887,6 +888,7 @@ simplecpp::TokenList Preprocessor::preprocess(const std::string &cfgStr, std::ve
887888
std::list<simplecpp::IfCond> ifCond;
888889
simplecpp::TokenList tokens2(files);
889890
simplecpp::preprocess(tokens2, mTokens, files, mFileCache, dui, &outputList, &macroUsage, &ifCond);
891+
reportSimplecppPortability(outputList);
890892
mMacroUsage = std::move(macroUsage);
891893
mIfCond = std::move(ifCond);
892894

‎test/cli/other_test.py‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,37 @@ def test_preprocessor_error(tmpdir):
9090
assert exitcode != 0
9191

9292

93+
# without -D the header is loaded by Preprocessor::loadAllIncludes(), with -D by Preprocessor::preprocess()
94+
@pytest.mark.parametrize("extra_args", [[], ['-DA']])
95+
def test_simplecpp_portability_header(tmpdir, extra_args):
96+
test_file = os.path.join(tmpdir, 'test.c')
97+
with open(test_file, 'wt') as f:
98+
f.write('#include "test.h"\n')
99+
test_h = os.path.join(tmpdir, 'test.h')
100+
with open(test_h, 'wt') as f:
101+
f.write('#ifdef A\nint a;\n#endif\nint x;') # no newline at end of file
102+
103+
args = ['-q', '--enable=portability', '--template=simple'] + extra_args + [test_file]
104+
105+
_, _, stderr = cppcheck(args)
106+
assert stderr == '{}:4:7: portability: No newline at end of file is undefined behavior in C. [simplecppPortabilityNoEofNewline]\n'.format(test_h)
107+
108+
109+
@pytest.mark.parametrize("extra_args", [[], ['-DA']])
110+
def test_simplecpp_portability_header_inline_suppr(tmpdir, extra_args):
111+
test_file = os.path.join(tmpdir, 'test.c')
112+
with open(test_file, 'wt') as f:
113+
f.write('#include "test.h"\n')
114+
test_h = os.path.join(tmpdir, 'test.h')
115+
with open(test_h, 'wt') as f:
116+
f.write('#ifdef A\nint a;\n#endif\n// cppcheck-suppress simplecppPortabilityNoEofNewline\nint x;')
117+
118+
args = ['-q', '--enable=portability', '--inline-suppr', '--template=simple'] + extra_args + [test_file]
119+
120+
_, _, stderr = cppcheck(args)
121+
assert stderr == ''
122+
123+
93124
__ANSI_BOLD = "\x1b[1m"
94125
__ANSI_FG_RED = "\x1b[31m"
95126
__ANSI_FG_DEFAULT = "\x1b[39m"

0 commit comments

Comments
 (0)