Skip to content

Commit 6bd4d6e

Browse files
ludviggunnefirewave
authored andcommitted
update cli tests
update tests fix #14265
1 parent 1a275fd commit 6bd4d6e

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

lib/preprocessor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ bool Preprocessor::reportOutput(const simplecpp::OutputList &outputList, bool sh
870870
const std::string::size_type pos1 = out.msg.find_first_of("<\"");
871871
const std::string::size_type pos2 = out.msg.find_first_of(">\"", pos1 + 1U);
872872
if (pos1 < pos2 && pos2 != std::string::npos)
873-
missingInclude(out.location.file(), out.location.line, out.msg.substr(pos1+1, pos2-pos1-1), out.msg[pos1] == '\"' ? UserHeader : SystemHeader);
873+
missingInclude(out.location.file(), out.location.line, out.location.col, out.msg.substr(pos1+1, pos2-pos1-1), out.msg[pos1] == '\"' ? UserHeader : SystemHeader);
874874
}
875875
break;
876876
case simplecpp::Output::INCLUDE_NESTED_TOO_DEEPLY:
@@ -910,14 +910,14 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const
910910
}
911911

912912
// Report that include is missing
913-
void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType)
913+
void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &header, HeaderTypes headerType)
914914
{
915915
if (!mSettings.checks.isEnabled(Checks::missingInclude))
916916
return;
917917

918918
std::list<ErrorMessage::FileLocation> locationList;
919919
if (!filename.empty()) {
920-
locationList.emplace_back(filename, linenr, 0);
920+
locationList.emplace_back(filename, linenr, col);
921921
}
922922
ErrorMessage errmsg(std::move(locationList), mFile0, Severity::information,
923923
(headerType==SystemHeader) ?
@@ -933,8 +933,8 @@ void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &se
933933
std::vector<std::string> files;
934934
simplecpp::TokenList tokens(files);
935935
Preprocessor preprocessor(tokens, settings, errorLogger, Standards::Language::CPP);
936-
preprocessor.missingInclude("", 1, "", UserHeader);
937-
preprocessor.missingInclude("", 1, "", SystemHeader);
936+
preprocessor.missingInclude("", 1, 2, "", UserHeader);
937+
preprocessor.missingInclude("", 1, 2, "", SystemHeader);
938938
preprocessor.error("", 1, "#error message"); // #error ..
939939
}
940940

lib/preprocessor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
157157
SystemHeader
158158
};
159159

160-
void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType);
160+
void missingInclude(const std::string &filename, unsigned int linenr, unsigned int col, const std::string &header, HeaderTypes headerType);
161161
void error(const std::string &filename, unsigned int linenr, const std::string &msg);
162162

163163
void addRemarkComments(const simplecpp::TokenList &tokens, std::vector<RemarkComment> &remarkComments) const;

test/cli/helloworld_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def test_missing_include_system(): # #11283
357357
]
358358

359359
_, _, stderr = cppcheck(args, cwd=__script_dir)
360-
assert stderr.replace('\\', '/') == 'helloworld/main.c:1:0: information: Include file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n'
360+
assert stderr.replace('\\', '/') == 'helloworld/main.c:1:2: information: Include file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n'
361361

362362

363363
def test_sarif():

test/cli/other_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ def test_missing_include(tmpdir): # #11283
2525
test_file = os.path.join(tmpdir, 'test.c')
2626
with open(test_file, 'wt') as f:
2727
f.write("""
28-
#include "test.h"
29-
""")
28+
#include "test.h"
29+
""")
3030

3131
args = ['--enable=missingInclude', '--template=simple', test_file]
3232

3333
_, _, stderr = cppcheck(args)
34-
assert stderr == '{}:2:0: information: Include file: "test.h" not found. [missingInclude]\n'.format(test_file)
34+
assert stderr == '{}:2:2: information: Include file: "test.h" not found. [missingInclude]\n'.format(test_file)
3535

3636

3737
def __test_missing_include_check_config(tmpdir, use_j):

test/testpreprocessor.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,7 @@ class TestPreprocessor : public TestFixture {
24152415
const char code[] = "#include \"header.h\"";
24162416
(void)getcodeforcfg(settings, *this, code, "", "test.c");
24172417

2418-
ASSERT_EQUALS("test.c:1:0: information: Include file: \"header.h\" not found. [missingInclude]\n", errout_str());
2418+
ASSERT_EQUALS("test.c:1:2: information: Include file: \"header.h\" not found. [missingInclude]\n", errout_str());
24192419
}
24202420

24212421
// test for missing local include - no include path given
@@ -2431,7 +2431,7 @@ class TestPreprocessor : public TestFixture {
24312431
const char code[] = "#include \"header.h\"";
24322432
(void)getcodeforcfg(settings, *this, code, "", "test.c");
24332433

2434-
ASSERT_EQUALS("test.c:1:0: information: Include file: \"header.h\" not found. [missingInclude]\n", errout_str());
2434+
ASSERT_EQUALS("test.c:1:2: information: Include file: \"header.h\" not found. [missingInclude]\n", errout_str());
24352435
}
24362436

24372437
// test for existing local include - include path provided
@@ -2481,7 +2481,7 @@ class TestPreprocessor : public TestFixture {
24812481
std::string code("#include \"" + header + "\"");
24822482
(void)getcodeforcfg(settings, *this, code.data(), code.size(), "", "test.c");
24832483

2484-
ASSERT_EQUALS("test.c:1:0: information: Include file: \"" + header + "\" not found. [missingInclude]\n", errout_str());
2484+
ASSERT_EQUALS("test.c:1:2: information: Include file: \"" + header + "\" not found. [missingInclude]\n", errout_str());
24852485
}
24862486

24872487
// test for missing system include - system includes are not searched for in relative path
@@ -2497,7 +2497,7 @@ class TestPreprocessor : public TestFixture {
24972497
const char code[] = "#include <header.h>";
24982498
(void)getcodeforcfg(settings, *this, code, "", "test.c");
24992499

2500-
ASSERT_EQUALS("test.c:1:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
2500+
ASSERT_EQUALS("test.c:1:2: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
25012501
}
25022502

25032503
// test for missing system include
@@ -2511,7 +2511,7 @@ class TestPreprocessor : public TestFixture {
25112511
const char code[] = "#include <header.h>";
25122512
(void)getcodeforcfg(settings, *this, code, "", "test.c");
25132513

2514-
ASSERT_EQUALS("test.c:1:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
2514+
ASSERT_EQUALS("test.c:1:2: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
25152515
}
25162516

25172517
// test for existing system include in system include path
@@ -2561,7 +2561,7 @@ class TestPreprocessor : public TestFixture {
25612561
std::string code("#include <" + header + ">");
25622562
(void)getcodeforcfg(settings, *this, code.data(), code.size(), "", "test.c");
25632563

2564-
ASSERT_EQUALS("test.c:1:0: information: Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
2564+
ASSERT_EQUALS("test.c:1:2: information: Include file: <" + header + "> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
25652565
}
25662566

25672567
// test for missing local and system include
@@ -2581,9 +2581,9 @@ class TestPreprocessor : public TestFixture {
25812581
"#include \"header2.h\"";
25822582
(void)getcodeforcfg(settings, *this, code, "", "test.c");
25832583

2584-
ASSERT_EQUALS("test.c:1:0: information: Include file: \"missing.h\" not found. [missingInclude]\n"
2585-
"test.c:2:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n"
2586-
"test.c:3:0: information: Include file: <missing2.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
2584+
ASSERT_EQUALS("test.c:1:2: information: Include file: \"missing.h\" not found. [missingInclude]\n"
2585+
"test.c:2:2: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n"
2586+
"test.c:3:2: information: Include file: <missing2.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
25872587
}
25882588

25892589
void testMissingIncludeCheckConfig() {
@@ -2617,12 +2617,12 @@ class TestPreprocessor : public TestFixture {
26172617
"#include <" + missing4 + ">\n");
26182618
(void)getcodeforcfg(settings, *this, code.data(), code.size(), "", "test.c");
26192619

2620-
ASSERT_EQUALS("test.c:1:0: information: Include file: \"missing.h\" not found. [missingInclude]\n"
2621-
"test.c:2:0: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n"
2622-
"test.c:3:0: information: Include file: <missing2.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n"
2623-
"test.c:6:0: information: Include file: \"header4.h\" not found. [missingInclude]\n"
2624-
"test.c:9:0: information: Include file: \"" + missing3 + "\" not found. [missingInclude]\n"
2625-
"test.c:11:0: information: Include file: <" + missing4 + "> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
2620+
ASSERT_EQUALS("test.c:1:2: information: Include file: \"missing.h\" not found. [missingInclude]\n"
2621+
"test.c:2:2: information: Include file: <header.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n"
2622+
"test.c:3:2: information: Include file: <missing2.h> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n"
2623+
"test.c:6:2: information: Include file: \"header4.h\" not found. [missingInclude]\n"
2624+
"test.c:9:2: information: Include file: \"" + missing3 + "\" not found. [missingInclude]\n"
2625+
"test.c:11:2: information: Include file: <" + missing4 + "> not found. Please note: Cppcheck does not need standard library headers to get proper results. [missingIncludeSystem]\n", errout_str());
26262626
}
26272627

26282628
void hasInclude() {

0 commit comments

Comments
 (0)