Skip to content

Commit acf22d2

Browse files
dmcppcheckclaude
andcommitted
Fix CI: sort the macro usage in the tests, and no doxygen comment for expandedTokens()
The order of the macro usage depends on the standard library, and clang -Wdocumentation reads @macro as a command. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 3c0144b commit acf22d2

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

‎test.cpp‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include "simplecpp.h"
77

8+
#include <algorithm>
9+
810
#include <cctype>
911
#include <cstdint>
1012
#include <cstdlib>
@@ -300,10 +302,8 @@ static std::string toString(const simplecpp::OutputList &outputList)
300302
return ostr.str();
301303
}
302304

303-
/**
304-
* Preprocess the code. Each output token is written as str(line:col), or
305-
* str@macro(line:col) when it comes from a macro expansion.
306-
*/
305+
// Preprocess the code. Each output token is written as str(line:col), or
306+
// str@macro(line:col) when it comes from a macro expansion.
307307
static std::string expandedTokens(const char code[], const simplecpp::DUI &dui = simplecpp::DUI(), std::list<simplecpp::MacroUsage> *macroUsage = nullptr)
308308
{
309309
std::vector<std::string> files;
@@ -323,17 +323,24 @@ static std::string expandedTokens(const char code[], const simplecpp::DUI &dui =
323323
return ret;
324324
}
325325

326-
/** Each macro usage as "name line:col use line:col", with " unknown" if the value is not known */
326+
/**
327+
* Each macro usage as "name line:col use line:col", with " unknown" if the value is not known.
328+
* The lines are sorted, the order of the macro usage depends on the standard library.
329+
*/
327330
static std::string toString(const std::list<simplecpp::MacroUsage> &macroUsage)
328331
{
329-
std::string ret;
332+
std::vector<std::string> lines;
330333
for (const simplecpp::MacroUsage &mu : macroUsage) {
331-
ret += mu.macroName + ' ' + std::to_string(mu.macroLocation.line) + ':' + std::to_string(mu.macroLocation.col) +
332-
" use " + std::to_string(mu.useLocation.line) + ':' + std::to_string(mu.useLocation.col);
334+
std::string line = mu.macroName + ' ' + std::to_string(mu.macroLocation.line) + ':' + std::to_string(mu.macroLocation.col) +
335+
" use " + std::to_string(mu.useLocation.line) + ':' + std::to_string(mu.useLocation.col);
333336
if (!mu.macroValueKnown)
334-
ret += " unknown";
335-
ret += '\n';
337+
line += " unknown";
338+
lines.push_back(std::move(line));
336339
}
340+
std::sort(lines.begin(), lines.end());
341+
std::string ret;
342+
for (const std::string &line : lines)
343+
ret += line + '\n';
337344
return ret;
338345
}
339346

@@ -4753,7 +4760,7 @@ static void tokenMacro3()
47534760
"ADD(FRED,2)";
47544761
std::list<simplecpp::MacroUsage> macroUsage;
47554762
ASSERT_EQUALS("1@FRED(3:1) +@ADD(3:1) 2(3:1)", expandedTokens(code, simplecpp::DUI(), &macroUsage));
4756-
ASSERT_EQUALS("FRED 2:9 use 3:1\nADD 1:9 use 3:1\n", toString(macroUsage));
4763+
ASSERT_EQUALS("ADD 1:9 use 3:1\nFRED 2:9 use 3:1\n", toString(macroUsage));
47574764
}
47584765

47594766
static void tokenMacro4()
@@ -4805,7 +4812,7 @@ static void tokenMacro8()
48054812
"f(2)\n";
48064813
std::list<simplecpp::MacroUsage> macroUsage;
48074814
ASSERT_EQUALS("2(3:2) +@g(3:2) 1@g(3:2)", expandedTokens(code, simplecpp::DUI(), &macroUsage));
4808-
ASSERT_EQUALS("g 2:9 use 3:2\nf 1:9 use 3:1\n", toString(macroUsage));
4815+
ASSERT_EQUALS("f 1:9 use 3:1\ng 2:9 use 3:2\n", toString(macroUsage));
48094816
}
48104817

48114818
static void tokenMacro9()
@@ -4817,7 +4824,7 @@ static void tokenMacro9()
48174824
"f 2)\n";
48184825
std::list<simplecpp::MacroUsage> macroUsage;
48194826
ASSERT_EQUALS("2(3:3) +@g(3:3) 1@g(3:3)", expandedTokens(code, simplecpp::DUI(), &macroUsage));
4820-
ASSERT_EQUALS("g 1:9 use 3:3\nf 2:9 use 3:1\n", toString(macroUsage));
4827+
ASSERT_EQUALS("f 2:9 use 3:1\ng 1:9 use 3:3\n", toString(macroUsage));
48214828
}
48224829

48234830
static void tokenMacro10()
@@ -4829,7 +4836,7 @@ static void tokenMacro10()
48294836
"str(a b) cat(x,y)\n";
48304837
std::list<simplecpp::MacroUsage> macroUsage;
48314838
ASSERT_EQUALS("\"a b\"(3:1) xy(3:10)", expandedTokens(code, simplecpp::DUI(), &macroUsage));
4832-
ASSERT_EQUALS("str 1:9 use 3:1\ncat 2:9 use 3:10\n", toString(macroUsage));
4839+
ASSERT_EQUALS("cat 2:9 use 3:10\nstr 1:9 use 3:1\n", toString(macroUsage));
48334840
}
48344841

48354842
static void tokenMacro11()

0 commit comments

Comments
 (0)