From e25d1262aef53fcf55fbb79911ae1148449e2d78 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Mar 2024 02:11:50 +0100 Subject: [PATCH 1/7] testrunner: refactored `givenACodeSampleToTokenize` into `SimpleTokenizer` and `SimpleTokenList` --- test/helpers.h | 44 ++++++++--- test/testlibrary.cpp | 16 ++-- test/testsymboldatabase.cpp | 2 +- test/testtoken.cpp | 148 ++++++++++++++++++------------------ 4 files changed, 116 insertions(+), 94 deletions(-) diff --git a/test/helpers.h b/test/helpers.h index 9326b7255eb..9748d41da5c 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -24,6 +24,7 @@ #include "tokenlist.h" #include +#include #include #include #include @@ -35,19 +36,13 @@ namespace simplecpp { struct DUI; } -class givenACodeSampleToTokenize { -private: - const Settings settings; - Tokenizer tokenizer; - +class SimpleTokenizer { public: - explicit givenACodeSampleToTokenize(const char sample[], bool createOnly = false, bool cpp = true) - : tokenizer(settings, nullptr) { + explicit SimpleTokenizer(const char sample[], bool cpp = true) + { std::istringstream iss(sample); - if (createOnly) - tokenizer.list.createTokens(iss, cpp ? "test.cpp" : "test.c"); - else - tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c"); + if (!tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c")) + throw std::runtime_error("creating tokens failed"); } Token* tokens() { @@ -57,6 +52,33 @@ class givenACodeSampleToTokenize { const Token* tokens() const { return tokenizer.tokens(); } + +private: + const Settings settings; + Tokenizer tokenizer{settings, nullptr}; +}; + +class SimpleTokenList +{ +public: + explicit SimpleTokenList(const char code[], bool cpp = true) + { + std::istringstream iss(code); + if (!list.createTokens(iss, cpp ? "test.cpp" : "test.c")) + throw std::runtime_error("creating tokens failed"); + } + + Token* tokens() { + return list.front(); + } + + const Token* tokens() const { + return list.front(); + } + +private: + const Settings settings; + TokenList list{&settings}; }; diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index ff444a7a57c..c3f05fff0b4 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -871,7 +871,7 @@ class TestLibrary : public TestFixture { ASSERT_EQUALS(C.arrayLike_indexOp, true); { - givenACodeSampleToTokenize var("std::A a;"); + SimpleTokenizer var("std::A a;"); ASSERT_EQUALS(&A, library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -880,14 +880,14 @@ class TestLibrary : public TestFixture { } { - givenACodeSampleToTokenize var("std::A::size_type a_s;"); + SimpleTokenizer var("std::A::size_type a_s;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); } { - givenACodeSampleToTokenize var("std::A::iterator a_it;"); + SimpleTokenizer var("std::A::iterator a_it;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT_EQUALS(&A, library.detectIterator(var.tokens())); bool isIterator; @@ -896,7 +896,7 @@ class TestLibrary : public TestFixture { } { - givenACodeSampleToTokenize var("std::B b;"); + SimpleTokenizer var("std::B b;"); ASSERT_EQUALS(&B, library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -905,14 +905,14 @@ class TestLibrary : public TestFixture { } { - givenACodeSampleToTokenize var("std::B::size_type b_s;"); + SimpleTokenizer var("std::B::size_type b_s;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); } { - givenACodeSampleToTokenize var("std::B::iterator b_it;"); + SimpleTokenizer var("std::B::iterator b_it;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT_EQUALS(&B, library.detectIterator(var.tokens())); bool isIterator; @@ -921,14 +921,14 @@ class TestLibrary : public TestFixture { } { - givenACodeSampleToTokenize var("C c;"); + SimpleTokenizer var("C c;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); } { - givenACodeSampleToTokenize var("D d;"); + SimpleTokenizer var("D d;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 68fd0d0a227..d5a16131463 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -817,7 +817,7 @@ class TestSymbolDatabase : public TestFixture { } { reset(); - givenACodeSampleToTokenize constpointer("const int* p;"); + SimpleTokenizer constpointer("const int* p;"); Variable v2(constpointer.tokens()->tokAt(3), constpointer.tokens()->next(), constpointer.tokens()->tokAt(2), 0, AccessControl::Public, nullptr, nullptr, &settings1); ASSERT(false == v2.isArray()); ASSERT(true == v2.isPointer()); diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 7972d27a190..e10ba8ad5c0 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -233,7 +233,7 @@ class TestToken : public TestFixture { void multiCompare2() const { // #3294 // Original pattern that failed: [[,(=<>+-*|&^] %num% [+-*/] %num% ]|,|)|;|=|%op% - givenACodeSampleToTokenize toks("a == 1", true); + SimpleTokenList toks("a == 1"); ASSERT_EQUALS(true, Token::Match(toks.tokens(), "a =|%op%")); } @@ -242,28 +242,28 @@ class TestToken : public TestFixture { // Code snippet that failed: "return lv@86 |= rv@87 ;" // Note: Also test "reverse" alternative pattern, two different code paths to handle it - givenACodeSampleToTokenize toks("return a |= b ;", true); + SimpleTokenList toks("return a |= b ;"); ASSERT_EQUALS(false, Token::Match(toks.tokens(), "return %name% xyz|%or% %name% ;")); ASSERT_EQUALS(false, Token::Match(toks.tokens(), "return %name% %or%|xyz %name% ;")); - givenACodeSampleToTokenize toks2("return a | b ;", true); + SimpleTokenList toks2("return a | b ;"); ASSERT_EQUALS(true, Token::Match(toks2.tokens(), "return %name% xyz|%or% %name% ;")); ASSERT_EQUALS(true, Token::Match(toks2.tokens(), "return %name% %or%|xyz %name% ;")); - givenACodeSampleToTokenize toks3("return a || b ;", true); + SimpleTokenList toks3("return a || b ;"); ASSERT_EQUALS(false, Token::Match(toks3.tokens(), "return %name% xyz|%or% %name% ;")); ASSERT_EQUALS(false, Token::Match(toks3.tokens(), "return %name% %or%|xyz %name% ;")); ASSERT_EQUALS(true, Token::Match(toks3.tokens(), "return %name% xyz|%oror% %name% ;")); ASSERT_EQUALS(true, Token::Match(toks3.tokens(), "return %name% %oror%|xyz %name% ;")); - givenACodeSampleToTokenize toks4("a % b ;", true); + SimpleTokenList toks4("a % b ;"); ASSERT_EQUALS(true, Token::Match(toks4.tokens(), "%name% >>|<<|&|%or%|^|% %name% ;")); ASSERT_EQUALS(true, Token::Match(toks4.tokens(), "%name% %|>>|<<|&|%or%|^ %name% ;")); ASSERT_EQUALS(true, Token::Match(toks4.tokens(), "%name% >>|<<|&|%or%|%|^ %name% ;")); //%name%|%num% support - givenACodeSampleToTokenize num("100", true); + SimpleTokenList num("100"); ASSERT_EQUALS(true, Token::Match(num.tokens(), "%num%|%name%")); ASSERT_EQUALS(true, Token::Match(num.tokens(), "%name%|%num%")); ASSERT_EQUALS(true, Token::Match(num.tokens(), "%name%|%num%|%bool%")); @@ -273,7 +273,7 @@ class TestToken : public TestFixture { ASSERT_EQUALS(false, Token::Match(num.tokens(), "%type%|%bool%|%char%")); ASSERT_EQUALS(true, Token::Match(num.tokens(), "%type%|%bool%|100")); - givenACodeSampleToTokenize numparen("( 100 )", true); + SimpleTokenList numparen("( 100 )"); ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| %num%|%name% )|")); ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| %name%|%num% )|")); ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| %name%|%num%|%bool% )|")); @@ -290,7 +290,7 @@ class TestToken : public TestFixture { } void multiCompare4() const { - givenACodeSampleToTokenize var("std :: queue < int > foo ;"); + SimpleTokenizer var("std :: queue < int > foo ;"); ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(3)->tokType()); ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(5)->tokType()); @@ -546,37 +546,37 @@ class TestToken : public TestFixture { } void nextArgument() const { - givenACodeSampleToTokenize example1("foo(1, 2, 3, 4);"); + SimpleTokenizer example1("foo(1, 2, 3, 4);"); ASSERT_EQUALS(true, Token::simpleMatch(example1.tokens()->tokAt(2)->nextArgument(), "2 , 3")); ASSERT_EQUALS(true, Token::simpleMatch(example1.tokens()->tokAt(4)->nextArgument(), "3 , 4")); - givenACodeSampleToTokenize example2("foo();"); + SimpleTokenizer example2("foo();"); ASSERT_EQUALS(true, example2.tokens()->tokAt(2)->nextArgument() == nullptr); - givenACodeSampleToTokenize example3("foo(bar(a, b), 2, 3);"); + SimpleTokenizer example3("foo(bar(a, b), 2, 3);"); ASSERT_EQUALS(true, Token::simpleMatch(example3.tokens()->tokAt(2)->nextArgument(), "2 , 3")); - givenACodeSampleToTokenize example4("foo(x.i[1], \"\", 3);"); + SimpleTokenizer example4("foo(x.i[1], \"\", 3);"); ASSERT_EQUALS(true, Token::simpleMatch(example4.tokens()->tokAt(2)->nextArgument(), "\"\" , 3")); } void eraseTokens() const { - givenACodeSampleToTokenize code("begin ; { this code will be removed } end", true); + SimpleTokenList code("begin ; { this code will be removed } end", true); Token::eraseTokens(code.tokens()->next(), code.tokens()->tokAt(9)); ASSERT_EQUALS("begin ; end", code.tokens()->stringifyList(nullptr, false)); } void matchAny() const { - givenACodeSampleToTokenize varBitOrVar("abc|def", true); + SimpleTokenList varBitOrVar("abc|def", true); ASSERT_EQUALS(true, Token::Match(varBitOrVar.tokens(), "%name% %or% %name%")); - givenACodeSampleToTokenize varLogOrVar("abc||def", true); + SimpleTokenList varLogOrVar("abc||def", true); ASSERT_EQUALS(true, Token::Match(varLogOrVar.tokens(), "%name% %oror% %name%")); } void matchSingleChar() const { - givenACodeSampleToTokenize singleChar("a", true); + SimpleTokenList singleChar("a", true); ASSERT_EQUALS(true, Token::Match(singleChar.tokens(), "[a|bc]")); ASSERT_EQUALS(false, Token::Match(singleChar.tokens(), "[d|ef]")); @@ -587,81 +587,81 @@ class TestToken : public TestFixture { } void matchNothingOrAnyNotElse() const { - givenACodeSampleToTokenize empty_String("", true); + SimpleTokenList empty_String(""); ASSERT_EQUALS(true, Token::Match(empty_String.tokens(), "!!else")); ASSERT_EQUALS(false, Token::Match(empty_String.tokens(), "!!else something")); - givenACodeSampleToTokenize ifSemicolon("if ;", true); + SimpleTokenList ifSemicolon("if ;"); ASSERT_EQUALS(true, Token::Match(ifSemicolon.tokens(), "if ; !!else")); - givenACodeSampleToTokenize ifSemicolonSomething("if ; something", true); + SimpleTokenList ifSemicolonSomething("if ; something", true); ASSERT_EQUALS(true, Token::Match(ifSemicolonSomething.tokens(), "if ; !!else")); - givenACodeSampleToTokenize justElse("else", true); + SimpleTokenList justElse("else"); ASSERT_EQUALS(false, Token::Match(justElse.tokens(), "!!else")); - givenACodeSampleToTokenize ifSemicolonElse("if ; else", true); + SimpleTokenList ifSemicolonElse("if ; else"); ASSERT_EQUALS(false, Token::Match(ifSemicolonElse.tokens(), "if ; !!else")); } void matchType() const { - givenACodeSampleToTokenize type("abc", true); + SimpleTokenList type("abc"); ASSERT_EQUALS(true, Token::Match(type.tokens(), "%type%")); - givenACodeSampleToTokenize isVar("int a = 3 ;"); + SimpleTokenizer isVar("int a = 3 ;"); ASSERT_EQUALS(true, Token::Match(isVar.tokens(), "%type%")); ASSERT_EQUALS(true, Token::Match(isVar.tokens(), "%type% %name%")); ASSERT_EQUALS(false, Token::Match(isVar.tokens(), "%type% %type%")); - givenACodeSampleToTokenize noType1_cpp("delete", true, true); + SimpleTokenList noType1_cpp("delete"); ASSERT_EQUALS(false, Token::Match(noType1_cpp.tokens(), "%type%")); - givenACodeSampleToTokenize noType1_c("delete", true, false); + SimpleTokenList noType1_c("delete", false); ASSERT_EQUALS(true, Token::Match(noType1_c.tokens(), "%type%")); - givenACodeSampleToTokenize noType2("void delete", true); + SimpleTokenList noType2("void delete"); ASSERT_EQUALS(false, Token::Match(noType2.tokens(), "!!foo %type%")); } void matchChar() const { - givenACodeSampleToTokenize chr1("'a'", true); + SimpleTokenList chr1("'a'"); ASSERT_EQUALS(true, Token::Match(chr1.tokens(), "%char%")); - givenACodeSampleToTokenize chr2("'1'", true); + SimpleTokenList chr2("'1'"); ASSERT_EQUALS(true, Token::Match(chr2.tokens(), "%char%")); - givenACodeSampleToTokenize noChr("\"10\"", true); + SimpleTokenList noChr("\"10\""); ASSERT_EQUALS(false, Token::Match(noChr.tokens(), "%char%")); } void matchCompOp() const { - givenACodeSampleToTokenize comp1("<=", true); + SimpleTokenList comp1("<="); ASSERT_EQUALS(true, Token::Match(comp1.tokens(), "%comp%")); - givenACodeSampleToTokenize comp2(">", true); + SimpleTokenList comp2(">"); ASSERT_EQUALS(true, Token::Match(comp2.tokens(), "%comp%")); - givenACodeSampleToTokenize noComp("=", true); + SimpleTokenList noComp("="); ASSERT_EQUALS(false, Token::Match(noComp.tokens(), "%comp%")); } void matchStr() const { - givenACodeSampleToTokenize noStr1("abc", true); + SimpleTokenList noStr1("abc"); ASSERT_EQUALS(false, Token::Match(noStr1.tokens(), "%str%")); - givenACodeSampleToTokenize noStr2("'a'", true); + SimpleTokenList noStr2("'a'"); ASSERT_EQUALS(false, Token::Match(noStr2.tokens(), "%str%")); - givenACodeSampleToTokenize str("\"abc\"", true); + SimpleTokenList str("\"abc\""); ASSERT_EQUALS(true, Token::Match(str.tokens(), "%str%")); // Empty string - givenACodeSampleToTokenize emptyStr("\"\"", true); + SimpleTokenList emptyStr("\"\""); ASSERT_EQUALS(true, Token::Match(emptyStr.tokens(), "%str%")); } void matchVarid() const { - givenACodeSampleToTokenize var("int a ; int b ;"); + SimpleTokenizer var("int a ; int b ;"); // Varid == 0 should throw exception ASSERT_THROW((void)Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 0),InternalError); @@ -678,86 +678,86 @@ class TestToken : public TestFixture { } void matchNumeric() const { - givenACodeSampleToTokenize nonNumeric("abc", true); + SimpleTokenList nonNumeric("abc"); ASSERT_EQUALS(false, Token::Match(nonNumeric.tokens(), "%num%")); - givenACodeSampleToTokenize msLiteral("5ms", true); // #11438 + SimpleTokenList msLiteral("5ms"); // #11438 ASSERT_EQUALS(false, Token::Match(msLiteral.tokens(), "%num%")); - givenACodeSampleToTokenize sLiteral("3s", true); + SimpleTokenList sLiteral("3s"); ASSERT_EQUALS(false, Token::Match(sLiteral.tokens(), "%num%")); - givenACodeSampleToTokenize octal("0123", true); + SimpleTokenList octal("0123"); ASSERT_EQUALS(true, Token::Match(octal.tokens(), "%num%")); - givenACodeSampleToTokenize decimal("4567", true); + SimpleTokenList decimal("4567"); ASSERT_EQUALS(true, Token::Match(decimal.tokens(), "%num%")); - givenACodeSampleToTokenize hexadecimal("0xDEADBEEF", true); + SimpleTokenList hexadecimal("0xDEADBEEF"); ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%")); - givenACodeSampleToTokenize floatingPoint("0.0f", true); + SimpleTokenList floatingPoint("0.0f"); ASSERT_EQUALS(true, Token::Match(floatingPoint.tokens(), "%num%")); - givenACodeSampleToTokenize signedLong("0L", true); + SimpleTokenList signedLong("0L"); ASSERT_EQUALS(true, Token::Match(signedLong.tokens(), "%num%")); - givenACodeSampleToTokenize negativeSignedLong("-0L", true); + SimpleTokenList negativeSignedLong("-0L"); ASSERT_EQUALS(true, Token::Match(negativeSignedLong.tokens(), "- %num%")); - givenACodeSampleToTokenize positiveSignedLong("+0L", true); + SimpleTokenList positiveSignedLong("+0L"); ASSERT_EQUALS(true, Token::Match(positiveSignedLong.tokens(), "+ %num%")); - givenACodeSampleToTokenize unsignedInt("0U", true); + SimpleTokenList unsignedInt("0U"); ASSERT_EQUALS(true, Token::Match(unsignedInt.tokens(), "%num%")); - givenACodeSampleToTokenize unsignedLong("0UL", true); + SimpleTokenList unsignedLong("0UL"); ASSERT_EQUALS(true, Token::Match(unsignedLong.tokens(), "%num%")); - givenACodeSampleToTokenize unsignedLongLong("0ULL", true); + SimpleTokenList unsignedLongLong("0ULL"); ASSERT_EQUALS(true, Token::Match(unsignedLongLong.tokens(), "%num%")); - givenACodeSampleToTokenize positive("+666", true); + SimpleTokenList positive("+666"); ASSERT_EQUALS(true, Token::Match(positive.tokens(), "+ %num%")); - givenACodeSampleToTokenize negative("-42", true); + SimpleTokenList negative("-42"); ASSERT_EQUALS(true, Token::Match(negative.tokens(), "- %num%")); - givenACodeSampleToTokenize negativeNull("-.0", true); + SimpleTokenList negativeNull("-.0"); ASSERT_EQUALS(true, Token::Match(negativeNull.tokens(), "- %num%")); - givenACodeSampleToTokenize positiveNull("+.0", true); + SimpleTokenList positiveNull("+.0"); ASSERT_EQUALS(true, Token::Match(positiveNull.tokens(), "+ %num%")); } void matchBoolean() const { - givenACodeSampleToTokenize yes("YES", true); + SimpleTokenList yes("YES"); ASSERT_EQUALS(false, Token::Match(yes.tokens(), "%bool%")); - givenACodeSampleToTokenize positive("true", true); + SimpleTokenList positive("true"); ASSERT_EQUALS(true, Token::Match(positive.tokens(), "%bool%")); - givenACodeSampleToTokenize negative("false", true); + SimpleTokenList negative("false"); ASSERT_EQUALS(true, Token::Match(negative.tokens(), "%bool%")); } void matchOr() const { - givenACodeSampleToTokenize bitwiseOr(";|;", true); + SimpleTokenList bitwiseOr(";|;"); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "; %or%")); ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "; %op%")); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "; %oror%")); - givenACodeSampleToTokenize bitwiseOrAssignment(";|=;"); + SimpleTokenizer bitwiseOrAssignment(";|=;"); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.tokens(), "; %or%")); ASSERT_EQUALS(true, Token::Match(bitwiseOrAssignment.tokens(), "; %op%")); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.tokens(), "; %oror%")); - givenACodeSampleToTokenize logicalOr(";||;", true); + SimpleTokenList logicalOr(";||;"); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(logicalOr.tokens(), "; %or%")); ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "; %op%")); @@ -766,7 +766,7 @@ class TestToken : public TestFixture { ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "; &&|%oror%")); ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "; %oror%|&&")); - givenACodeSampleToTokenize logicalAnd(";&&;", true); + SimpleTokenList logicalAnd(";&&;"); ASSERT_EQUALS(true, Token::simpleMatch(logicalAnd.tokens(), "; &&")); ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "; &&|%oror%")); ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "; %oror%|&&")); @@ -1106,14 +1106,14 @@ class TestToken : public TestFixture { } void canFindMatchingBracketsNeedsOpen() const { - givenACodeSampleToTokenize var("std::deque > intsets;"); + SimpleTokenizer var("std::deque > intsets;"); const Token* const t = var.tokens()->findClosingBracket(); ASSERT(t == nullptr); } void canFindMatchingBracketsInnerPair() const { - givenACodeSampleToTokenize var("std::deque > intsets;"); + SimpleTokenizer var("std::deque > intsets;"); const Token * const t = var.tokens()->tokAt(7)->findClosingBracket(); ASSERT_EQUALS(">", t->str()); @@ -1121,7 +1121,7 @@ class TestToken : public TestFixture { } void canFindMatchingBracketsOuterPair() const { - givenACodeSampleToTokenize var("std::deque > intsets;"); + SimpleTokenizer var("std::deque > intsets;"); const Token* const t = var.tokens()->tokAt(3)->findClosingBracket(); ASSERT_EQUALS(">", t->str()); @@ -1129,7 +1129,7 @@ class TestToken : public TestFixture { } void canFindMatchingBracketsWithTooManyClosing() const { - givenACodeSampleToTokenize var("X< 1>2 > x1;"); + SimpleTokenizer var("X< 1>2 > x1;"); const Token* const t = var.tokens()->next()->findClosingBracket(); ASSERT_EQUALS(">", t->str()); @@ -1137,7 +1137,7 @@ class TestToken : public TestFixture { } void canFindMatchingBracketsWithTooManyOpening() const { - givenACodeSampleToTokenize var("X < (2 < 1) > x1;"); + SimpleTokenizer var("X < (2 < 1) > x1;"); const Token* t = var.tokens()->next()->findClosingBracket(); ASSERT(t != nullptr && t->str() == ">"); @@ -1147,38 +1147,38 @@ class TestToken : public TestFixture { } void findClosingBracket() const { - givenACodeSampleToTokenize var("template struct S : public Fred> {}"); + SimpleTokenizer var("template struct S : public Fred> {}"); const Token* const t = var.tokens()->next()->findClosingBracket(); ASSERT(Token::simpleMatch(t, "> struct")); } void findClosingBracket2() const { - givenACodeSampleToTokenize var("const auto g = []() {};\n"); // #11275 + SimpleTokenizer var("const auto g = []() {};\n"); // #11275 const Token* const t = Token::findsimplematch(var.tokens(), "<"); ASSERT(t && Token::simpleMatch(t->findClosingBracket(), ">")); } void expressionString() const { - givenACodeSampleToTokenize var1("void f() { *((unsigned long long *)x) = 0; }"); + SimpleTokenizer var1("void f() { *((unsigned long long *)x) = 0; }"); const Token *const tok1 = Token::findsimplematch(var1.tokens(), "*"); ASSERT_EQUALS("*((unsigned long long*)x)", tok1->expressionString()); - givenACodeSampleToTokenize var2("typedef unsigned long long u64; void f() { *((u64 *)x) = 0; }"); + SimpleTokenizer var2("typedef unsigned long long u64; void f() { *((u64 *)x) = 0; }"); const Token *const tok2 = Token::findsimplematch(var2.tokens(), "*"); ASSERT_EQUALS("*((unsigned long long*)x)", tok2->expressionString()); - givenACodeSampleToTokenize data3("void f() { return (t){1,2}; }"); + SimpleTokenizer data3("void f() { return (t){1,2}; }"); ASSERT_EQUALS("return(t){1,2}", data3.tokens()->tokAt(5)->expressionString()); - givenACodeSampleToTokenize data4("void f() { return L\"a\"; }"); + SimpleTokenizer data4("void f() { return L\"a\"; }"); ASSERT_EQUALS("returnL\"a\"", data4.tokens()->tokAt(5)->expressionString()); - givenACodeSampleToTokenize data5("void f() { return U\"a\"; }"); + SimpleTokenizer data5("void f() { return U\"a\"; }"); ASSERT_EQUALS("returnU\"a\"", data5.tokens()->tokAt(5)->expressionString()); - givenACodeSampleToTokenize data6("x = \"\\0\\x1\\x2\\x3\\x4\\x5\\x6\\x7\";"); + SimpleTokenizer data6("x = \"\\0\\x1\\x2\\x3\\x4\\x5\\x6\\x7\";"); ASSERT_EQUALS("x=\"\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\"", data6.tokens()->next()->expressionString()); } From 25a6859edd8e37a727fc3775ab03f5ebbcbdd1ff Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 5 Mar 2024 12:00:49 +0100 Subject: [PATCH 2/7] testrunner: pass `ErrorLogger` into `SimpleTokenizer` --- test/helpers.h | 6 ++-- test/testlibrary.cpp | 18 +++++----- test/testsymboldatabase.cpp | 2 +- test/testtoken.cpp | 68 ++++++++++++++++++------------------- 4 files changed, 48 insertions(+), 46 deletions(-) diff --git a/test/helpers.h b/test/helpers.h index 9748d41da5c..952e664c339 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -32,13 +32,15 @@ class Token; class Preprocessor; class SuppressionList; +class ErrorLogger; namespace simplecpp { struct DUI; } class SimpleTokenizer { public: - explicit SimpleTokenizer(const char sample[], bool cpp = true) + SimpleTokenizer(ErrorLogger& errorlogger, const char sample[], bool cpp = true) + : tokenizer{settings, &errorlogger} { std::istringstream iss(sample); if (!tokenizer.tokenize(iss, cpp ? "test.cpp" : "test.c")) @@ -55,7 +57,7 @@ class SimpleTokenizer { private: const Settings settings; - Tokenizer tokenizer{settings, nullptr}; + Tokenizer tokenizer; }; class SimpleTokenList diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index c3f05fff0b4..5b34e00dc09 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -791,7 +791,7 @@ class TestLibrary : public TestFixture { } } - void container() const { + void container() { constexpr char xmldata[] = "\n" "\n" " \n" @@ -871,7 +871,7 @@ class TestLibrary : public TestFixture { ASSERT_EQUALS(C.arrayLike_indexOp, true); { - SimpleTokenizer var("std::A a;"); + SimpleTokenizer var(*this, "std::A a;"); ASSERT_EQUALS(&A, library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -880,14 +880,14 @@ class TestLibrary : public TestFixture { } { - SimpleTokenizer var("std::A::size_type a_s;"); + SimpleTokenizer var(*this, "std::A::size_type a_s;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); } { - SimpleTokenizer var("std::A::iterator a_it;"); + SimpleTokenizer var(*this, "std::A::iterator a_it;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT_EQUALS(&A, library.detectIterator(var.tokens())); bool isIterator; @@ -896,7 +896,7 @@ class TestLibrary : public TestFixture { } { - SimpleTokenizer var("std::B b;"); + SimpleTokenizer var(*this, "std::B b;"); ASSERT_EQUALS(&B, library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -905,14 +905,14 @@ class TestLibrary : public TestFixture { } { - SimpleTokenizer var("std::B::size_type b_s;"); + SimpleTokenizer var(*this, "std::B::size_type b_s;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); } { - SimpleTokenizer var("std::B::iterator b_it;"); + SimpleTokenizer var(*this, "std::B::iterator b_it;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT_EQUALS(&B, library.detectIterator(var.tokens())); bool isIterator; @@ -921,14 +921,14 @@ class TestLibrary : public TestFixture { } { - SimpleTokenizer var("C c;"); + SimpleTokenizer var(*this, "C c;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); } { - SimpleTokenizer var("D d;"); + SimpleTokenizer var(*this, "D d;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index d5a16131463..0ec998e5879 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -817,7 +817,7 @@ class TestSymbolDatabase : public TestFixture { } { reset(); - SimpleTokenizer constpointer("const int* p;"); + SimpleTokenizer constpointer(*this, "const int* p;"); Variable v2(constpointer.tokens()->tokAt(3), constpointer.tokens()->next(), constpointer.tokens()->tokAt(2), 0, AccessControl::Public, nullptr, nullptr, &settings1); ASSERT(false == v2.isArray()); ASSERT(true == v2.isPointer()); diff --git a/test/testtoken.cpp b/test/testtoken.cpp index e10ba8ad5c0..da9a6b21754 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -289,8 +289,8 @@ class TestToken : public TestFixture { ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| 100 %bool%|%name%| )|")); } - void multiCompare4() const { - SimpleTokenizer var("std :: queue < int > foo ;"); + void multiCompare4() { + SimpleTokenizer var(*this, "std :: queue < int > foo ;"); ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(3)->tokType()); ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(5)->tokType()); @@ -545,18 +545,18 @@ class TestToken : public TestFixture { ASSERT_EQUALS(true, *tokensFront == &tok); } - void nextArgument() const { - SimpleTokenizer example1("foo(1, 2, 3, 4);"); + void nextArgument() { + SimpleTokenizer example1(*this, "foo(1, 2, 3, 4);"); ASSERT_EQUALS(true, Token::simpleMatch(example1.tokens()->tokAt(2)->nextArgument(), "2 , 3")); ASSERT_EQUALS(true, Token::simpleMatch(example1.tokens()->tokAt(4)->nextArgument(), "3 , 4")); - SimpleTokenizer example2("foo();"); + SimpleTokenizer example2(*this, "foo();"); ASSERT_EQUALS(true, example2.tokens()->tokAt(2)->nextArgument() == nullptr); - SimpleTokenizer example3("foo(bar(a, b), 2, 3);"); + SimpleTokenizer example3(*this, "foo(bar(a, b), 2, 3);"); ASSERT_EQUALS(true, Token::simpleMatch(example3.tokens()->tokAt(2)->nextArgument(), "2 , 3")); - SimpleTokenizer example4("foo(x.i[1], \"\", 3);"); + SimpleTokenizer example4(*this, "foo(x.i[1], \"\", 3);"); ASSERT_EQUALS(true, Token::simpleMatch(example4.tokens()->tokAt(2)->nextArgument(), "\"\" , 3")); } @@ -604,11 +604,11 @@ class TestToken : public TestFixture { ASSERT_EQUALS(false, Token::Match(ifSemicolonElse.tokens(), "if ; !!else")); } - void matchType() const { + void matchType() { SimpleTokenList type("abc"); ASSERT_EQUALS(true, Token::Match(type.tokens(), "%type%")); - SimpleTokenizer isVar("int a = 3 ;"); + SimpleTokenizer isVar(*this, "int a = 3 ;"); ASSERT_EQUALS(true, Token::Match(isVar.tokens(), "%type%")); ASSERT_EQUALS(true, Token::Match(isVar.tokens(), "%type% %name%")); ASSERT_EQUALS(false, Token::Match(isVar.tokens(), "%type% %type%")); @@ -660,8 +660,8 @@ class TestToken : public TestFixture { ASSERT_EQUALS(true, Token::Match(emptyStr.tokens(), "%str%")); } - void matchVarid() const { - SimpleTokenizer var("int a ; int b ;"); + void matchVarid() { + SimpleTokenizer var(*this, "int a ; int b ;"); // Varid == 0 should throw exception ASSERT_THROW((void)Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 0),InternalError); @@ -742,7 +742,7 @@ class TestToken : public TestFixture { ASSERT_EQUALS(true, Token::Match(negative.tokens(), "%bool%")); } - void matchOr() const { + void matchOr() { SimpleTokenList bitwiseOr(";|;"); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "; %or%")); @@ -750,7 +750,7 @@ class TestToken : public TestFixture { // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "; %oror%")); - SimpleTokenizer bitwiseOrAssignment(";|=;"); + SimpleTokenizer bitwiseOrAssignment(*this, ";|=;"); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.tokens(), "; %or%")); ASSERT_EQUALS(true, Token::Match(bitwiseOrAssignment.tokens(), "; %op%")); @@ -1105,39 +1105,39 @@ class TestToken : public TestFixture { ASSERT_EQUALS(true, tok.isName()); } - void canFindMatchingBracketsNeedsOpen() const { - SimpleTokenizer var("std::deque > intsets;"); + void canFindMatchingBracketsNeedsOpen() { + SimpleTokenizer var(*this, "std::deque > intsets;"); const Token* const t = var.tokens()->findClosingBracket(); ASSERT(t == nullptr); } - void canFindMatchingBracketsInnerPair() const { - SimpleTokenizer var("std::deque > intsets;"); + void canFindMatchingBracketsInnerPair() { + SimpleTokenizer var(*this, "std::deque > intsets;"); const Token * const t = var.tokens()->tokAt(7)->findClosingBracket(); ASSERT_EQUALS(">", t->str()); ASSERT(var.tokens()->tokAt(9) == t); } - void canFindMatchingBracketsOuterPair() const { - SimpleTokenizer var("std::deque > intsets;"); + void canFindMatchingBracketsOuterPair() { + SimpleTokenizer var(*this, "std::deque > intsets;"); const Token* const t = var.tokens()->tokAt(3)->findClosingBracket(); ASSERT_EQUALS(">", t->str()); ASSERT(var.tokens()->tokAt(10) == t); } - void canFindMatchingBracketsWithTooManyClosing() const { - SimpleTokenizer var("X< 1>2 > x1;"); + void canFindMatchingBracketsWithTooManyClosing() { + SimpleTokenizer var(*this, "X< 1>2 > x1;"); const Token* const t = var.tokens()->next()->findClosingBracket(); ASSERT_EQUALS(">", t->str()); ASSERT(var.tokens()->tokAt(3) == t); } - void canFindMatchingBracketsWithTooManyOpening() const { - SimpleTokenizer var("X < (2 < 1) > x1;"); + void canFindMatchingBracketsWithTooManyOpening() { + SimpleTokenizer var(*this, "X < (2 < 1) > x1;"); const Token* t = var.tokens()->next()->findClosingBracket(); ASSERT(t != nullptr && t->str() == ">"); @@ -1146,39 +1146,39 @@ class TestToken : public TestFixture { ASSERT(t == nullptr); } - void findClosingBracket() const { - SimpleTokenizer var("template struct S : public Fred> {}"); + void findClosingBracket() { + SimpleTokenizer var(*this, "template struct S : public Fred> {}"); const Token* const t = var.tokens()->next()->findClosingBracket(); ASSERT(Token::simpleMatch(t, "> struct")); } - void findClosingBracket2() const { - SimpleTokenizer var("const auto g = []() {};\n"); // #11275 + void findClosingBracket2() { + SimpleTokenizer var(*this, "const auto g = []() {};\n"); // #11275 const Token* const t = Token::findsimplematch(var.tokens(), "<"); ASSERT(t && Token::simpleMatch(t->findClosingBracket(), ">")); } - void expressionString() const { - SimpleTokenizer var1("void f() { *((unsigned long long *)x) = 0; }"); + void expressionString() { + SimpleTokenizer var1(*this, "void f() { *((unsigned long long *)x) = 0; }"); const Token *const tok1 = Token::findsimplematch(var1.tokens(), "*"); ASSERT_EQUALS("*((unsigned long long*)x)", tok1->expressionString()); - SimpleTokenizer var2("typedef unsigned long long u64; void f() { *((u64 *)x) = 0; }"); + SimpleTokenizer var2(*this, "typedef unsigned long long u64; void f() { *((u64 *)x) = 0; }"); const Token *const tok2 = Token::findsimplematch(var2.tokens(), "*"); ASSERT_EQUALS("*((unsigned long long*)x)", tok2->expressionString()); - SimpleTokenizer data3("void f() { return (t){1,2}; }"); + SimpleTokenizer data3(*this, "void f() { return (t){1,2}; }"); ASSERT_EQUALS("return(t){1,2}", data3.tokens()->tokAt(5)->expressionString()); - SimpleTokenizer data4("void f() { return L\"a\"; }"); + SimpleTokenizer data4(*this, "void f() { return L\"a\"; }"); ASSERT_EQUALS("returnL\"a\"", data4.tokens()->tokAt(5)->expressionString()); - SimpleTokenizer data5("void f() { return U\"a\"; }"); + SimpleTokenizer data5(*this, "void f() { return U\"a\"; }"); ASSERT_EQUALS("returnU\"a\"", data5.tokens()->tokAt(5)->expressionString()); - SimpleTokenizer data6("x = \"\\0\\x1\\x2\\x3\\x4\\x5\\x6\\x7\";"); + SimpleTokenizer data6(*this, "x = \"\\0\\x1\\x2\\x3\\x4\\x5\\x6\\x7\";"); ASSERT_EQUALS("x=\"\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\"", data6.tokens()->next()->expressionString()); } From cc9b7a759f4a7096e17ca8e141f60c2067b29c2a Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 5 Mar 2024 12:30:16 +0100 Subject: [PATCH 3/7] testrunner: renamed `SimpleTokenList` members --- test/helpers.h | 4 +- test/testtoken.cpp | 180 ++++++++++++++++++++++----------------------- 2 files changed, 92 insertions(+), 92 deletions(-) diff --git a/test/helpers.h b/test/helpers.h index 952e664c339..7c49020b634 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -70,11 +70,11 @@ class SimpleTokenList throw std::runtime_error("creating tokens failed"); } - Token* tokens() { + Token* front() { return list.front(); } - const Token* tokens() const { + const Token* front() const { return list.front(); } diff --git a/test/testtoken.cpp b/test/testtoken.cpp index da9a6b21754..09aab594f9c 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -234,7 +234,7 @@ class TestToken : public TestFixture { void multiCompare2() const { // #3294 // Original pattern that failed: [[,(=<>+-*|&^] %num% [+-*/] %num% ]|,|)|;|=|%op% SimpleTokenList toks("a == 1"); - ASSERT_EQUALS(true, Token::Match(toks.tokens(), "a =|%op%")); + ASSERT_EQUALS(true, Token::Match(toks.front(), "a =|%op%")); } void multiCompare3() const { @@ -243,50 +243,50 @@ class TestToken : public TestFixture { // Note: Also test "reverse" alternative pattern, two different code paths to handle it SimpleTokenList toks("return a |= b ;"); - ASSERT_EQUALS(false, Token::Match(toks.tokens(), "return %name% xyz|%or% %name% ;")); - ASSERT_EQUALS(false, Token::Match(toks.tokens(), "return %name% %or%|xyz %name% ;")); + ASSERT_EQUALS(false, Token::Match(toks.front(), "return %name% xyz|%or% %name% ;")); + ASSERT_EQUALS(false, Token::Match(toks.front(), "return %name% %or%|xyz %name% ;")); SimpleTokenList toks2("return a | b ;"); - ASSERT_EQUALS(true, Token::Match(toks2.tokens(), "return %name% xyz|%or% %name% ;")); - ASSERT_EQUALS(true, Token::Match(toks2.tokens(), "return %name% %or%|xyz %name% ;")); + ASSERT_EQUALS(true, Token::Match(toks2.front(), "return %name% xyz|%or% %name% ;")); + ASSERT_EQUALS(true, Token::Match(toks2.front(), "return %name% %or%|xyz %name% ;")); SimpleTokenList toks3("return a || b ;"); - ASSERT_EQUALS(false, Token::Match(toks3.tokens(), "return %name% xyz|%or% %name% ;")); - ASSERT_EQUALS(false, Token::Match(toks3.tokens(), "return %name% %or%|xyz %name% ;")); + ASSERT_EQUALS(false, Token::Match(toks3.front(), "return %name% xyz|%or% %name% ;")); + ASSERT_EQUALS(false, Token::Match(toks3.front(), "return %name% %or%|xyz %name% ;")); - ASSERT_EQUALS(true, Token::Match(toks3.tokens(), "return %name% xyz|%oror% %name% ;")); - ASSERT_EQUALS(true, Token::Match(toks3.tokens(), "return %name% %oror%|xyz %name% ;")); + ASSERT_EQUALS(true, Token::Match(toks3.front(), "return %name% xyz|%oror% %name% ;")); + ASSERT_EQUALS(true, Token::Match(toks3.front(), "return %name% %oror%|xyz %name% ;")); SimpleTokenList toks4("a % b ;"); - ASSERT_EQUALS(true, Token::Match(toks4.tokens(), "%name% >>|<<|&|%or%|^|% %name% ;")); - ASSERT_EQUALS(true, Token::Match(toks4.tokens(), "%name% %|>>|<<|&|%or%|^ %name% ;")); - ASSERT_EQUALS(true, Token::Match(toks4.tokens(), "%name% >>|<<|&|%or%|%|^ %name% ;")); + ASSERT_EQUALS(true, Token::Match(toks4.front(), "%name% >>|<<|&|%or%|^|% %name% ;")); + ASSERT_EQUALS(true, Token::Match(toks4.front(), "%name% %|>>|<<|&|%or%|^ %name% ;")); + ASSERT_EQUALS(true, Token::Match(toks4.front(), "%name% >>|<<|&|%or%|%|^ %name% ;")); //%name%|%num% support SimpleTokenList num("100"); - ASSERT_EQUALS(true, Token::Match(num.tokens(), "%num%|%name%")); - ASSERT_EQUALS(true, Token::Match(num.tokens(), "%name%|%num%")); - ASSERT_EQUALS(true, Token::Match(num.tokens(), "%name%|%num%|%bool%")); - ASSERT_EQUALS(true, Token::Match(num.tokens(), "%name%|%bool%|%num%")); - ASSERT_EQUALS(true, Token::Match(num.tokens(), "%name%|%bool%|%str%|%num%")); - ASSERT_EQUALS(false, Token::Match(num.tokens(), "%bool%|%name%")); - ASSERT_EQUALS(false, Token::Match(num.tokens(), "%type%|%bool%|%char%")); - ASSERT_EQUALS(true, Token::Match(num.tokens(), "%type%|%bool%|100")); + ASSERT_EQUALS(true, Token::Match(num.front(), "%num%|%name%")); + ASSERT_EQUALS(true, Token::Match(num.front(), "%name%|%num%")); + ASSERT_EQUALS(true, Token::Match(num.front(), "%name%|%num%|%bool%")); + ASSERT_EQUALS(true, Token::Match(num.front(), "%name%|%bool%|%num%")); + ASSERT_EQUALS(true, Token::Match(num.front(), "%name%|%bool%|%str%|%num%")); + ASSERT_EQUALS(false, Token::Match(num.front(), "%bool%|%name%")); + ASSERT_EQUALS(false, Token::Match(num.front(), "%type%|%bool%|%char%")); + ASSERT_EQUALS(true, Token::Match(num.front(), "%type%|%bool%|100")); SimpleTokenList numparen("( 100 )"); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| %num%|%name% )|")); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| %name%|%num% )|")); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| %name%|%num%|%bool% )|")); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| %name%|%bool%|%num% )|")); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| %name%|%bool%|%str%|%num% )|")); - ASSERT_EQUALS(false, Token::Match(numparen.tokens(), "(| %bool%|%name% )|")); - - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| 100 %num%|%name%| )|")); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| 100 %name%|%num%| )|")); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| 100 %name%|%num%|%bool%| )|")); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| 100 %name%|%bool%|%num%| )|")); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| 100 %name%|%bool%|%str%|%num%| )|")); - ASSERT_EQUALS(true, Token::Match(numparen.tokens(), "(| 100 %bool%|%name%| )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| %num%|%name% )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| %name%|%num% )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| %name%|%num%|%bool% )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| %name%|%bool%|%num% )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| %name%|%bool%|%str%|%num% )|")); + ASSERT_EQUALS(false, Token::Match(numparen.front(), "(| %bool%|%name% )|")); + + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| 100 %num%|%name%| )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| 100 %name%|%num%| )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| 100 %name%|%num%|%bool%| )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| 100 %name%|%bool%|%num%| )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| 100 %name%|%bool%|%str%|%num%| )|")); + ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| 100 %bool%|%name%| )|")); } void multiCompare4() { @@ -562,23 +562,23 @@ class TestToken : public TestFixture { void eraseTokens() const { SimpleTokenList code("begin ; { this code will be removed } end", true); - Token::eraseTokens(code.tokens()->next(), code.tokens()->tokAt(9)); - ASSERT_EQUALS("begin ; end", code.tokens()->stringifyList(nullptr, false)); + Token::eraseTokens(code.front()->next(), code.front()->tokAt(9)); + ASSERT_EQUALS("begin ; end", code.front()->stringifyList(nullptr, false)); } void matchAny() const { SimpleTokenList varBitOrVar("abc|def", true); - ASSERT_EQUALS(true, Token::Match(varBitOrVar.tokens(), "%name% %or% %name%")); + ASSERT_EQUALS(true, Token::Match(varBitOrVar.front(), "%name% %or% %name%")); SimpleTokenList varLogOrVar("abc||def", true); - ASSERT_EQUALS(true, Token::Match(varLogOrVar.tokens(), "%name% %oror% %name%")); + ASSERT_EQUALS(true, Token::Match(varLogOrVar.front(), "%name% %oror% %name%")); } void matchSingleChar() const { SimpleTokenList singleChar("a", true); - ASSERT_EQUALS(true, Token::Match(singleChar.tokens(), "[a|bc]")); - ASSERT_EQUALS(false, Token::Match(singleChar.tokens(), "[d|ef]")); + ASSERT_EQUALS(true, Token::Match(singleChar.front(), "[a|bc]")); + ASSERT_EQUALS(false, Token::Match(singleChar.front(), "[d|ef]")); TokensFrontBack tokensFrontBack(list); Token multiChar(tokensFrontBack); @@ -588,25 +588,25 @@ class TestToken : public TestFixture { void matchNothingOrAnyNotElse() const { SimpleTokenList empty_String(""); - ASSERT_EQUALS(true, Token::Match(empty_String.tokens(), "!!else")); - ASSERT_EQUALS(false, Token::Match(empty_String.tokens(), "!!else something")); + ASSERT_EQUALS(true, Token::Match(empty_String.front(), "!!else")); + ASSERT_EQUALS(false, Token::Match(empty_String.front(), "!!else something")); SimpleTokenList ifSemicolon("if ;"); - ASSERT_EQUALS(true, Token::Match(ifSemicolon.tokens(), "if ; !!else")); + ASSERT_EQUALS(true, Token::Match(ifSemicolon.front(), "if ; !!else")); SimpleTokenList ifSemicolonSomething("if ; something", true); - ASSERT_EQUALS(true, Token::Match(ifSemicolonSomething.tokens(), "if ; !!else")); + ASSERT_EQUALS(true, Token::Match(ifSemicolonSomething.front(), "if ; !!else")); SimpleTokenList justElse("else"); - ASSERT_EQUALS(false, Token::Match(justElse.tokens(), "!!else")); + ASSERT_EQUALS(false, Token::Match(justElse.front(), "!!else")); SimpleTokenList ifSemicolonElse("if ; else"); - ASSERT_EQUALS(false, Token::Match(ifSemicolonElse.tokens(), "if ; !!else")); + ASSERT_EQUALS(false, Token::Match(ifSemicolonElse.front(), "if ; !!else")); } void matchType() { SimpleTokenList type("abc"); - ASSERT_EQUALS(true, Token::Match(type.tokens(), "%type%")); + ASSERT_EQUALS(true, Token::Match(type.front(), "%type%")); SimpleTokenizer isVar(*this, "int a = 3 ;"); ASSERT_EQUALS(true, Token::Match(isVar.tokens(), "%type%")); @@ -614,50 +614,50 @@ class TestToken : public TestFixture { ASSERT_EQUALS(false, Token::Match(isVar.tokens(), "%type% %type%")); SimpleTokenList noType1_cpp("delete"); - ASSERT_EQUALS(false, Token::Match(noType1_cpp.tokens(), "%type%")); + ASSERT_EQUALS(false, Token::Match(noType1_cpp.front(), "%type%")); SimpleTokenList noType1_c("delete", false); - ASSERT_EQUALS(true, Token::Match(noType1_c.tokens(), "%type%")); + ASSERT_EQUALS(true, Token::Match(noType1_c.front(), "%type%")); SimpleTokenList noType2("void delete"); - ASSERT_EQUALS(false, Token::Match(noType2.tokens(), "!!foo %type%")); + ASSERT_EQUALS(false, Token::Match(noType2.front(), "!!foo %type%")); } void matchChar() const { SimpleTokenList chr1("'a'"); - ASSERT_EQUALS(true, Token::Match(chr1.tokens(), "%char%")); + ASSERT_EQUALS(true, Token::Match(chr1.front(), "%char%")); SimpleTokenList chr2("'1'"); - ASSERT_EQUALS(true, Token::Match(chr2.tokens(), "%char%")); + ASSERT_EQUALS(true, Token::Match(chr2.front(), "%char%")); SimpleTokenList noChr("\"10\""); - ASSERT_EQUALS(false, Token::Match(noChr.tokens(), "%char%")); + ASSERT_EQUALS(false, Token::Match(noChr.front(), "%char%")); } void matchCompOp() const { SimpleTokenList comp1("<="); - ASSERT_EQUALS(true, Token::Match(comp1.tokens(), "%comp%")); + ASSERT_EQUALS(true, Token::Match(comp1.front(), "%comp%")); SimpleTokenList comp2(">"); - ASSERT_EQUALS(true, Token::Match(comp2.tokens(), "%comp%")); + ASSERT_EQUALS(true, Token::Match(comp2.front(), "%comp%")); SimpleTokenList noComp("="); - ASSERT_EQUALS(false, Token::Match(noComp.tokens(), "%comp%")); + ASSERT_EQUALS(false, Token::Match(noComp.front(), "%comp%")); } void matchStr() const { SimpleTokenList noStr1("abc"); - ASSERT_EQUALS(false, Token::Match(noStr1.tokens(), "%str%")); + ASSERT_EQUALS(false, Token::Match(noStr1.front(), "%str%")); SimpleTokenList noStr2("'a'"); - ASSERT_EQUALS(false, Token::Match(noStr2.tokens(), "%str%")); + ASSERT_EQUALS(false, Token::Match(noStr2.front(), "%str%")); SimpleTokenList str("\"abc\""); - ASSERT_EQUALS(true, Token::Match(str.tokens(), "%str%")); + ASSERT_EQUALS(true, Token::Match(str.front(), "%str%")); // Empty string SimpleTokenList emptyStr("\"\""); - ASSERT_EQUALS(true, Token::Match(emptyStr.tokens(), "%str%")); + ASSERT_EQUALS(true, Token::Match(emptyStr.front(), "%str%")); } void matchVarid() { @@ -679,76 +679,76 @@ class TestToken : public TestFixture { void matchNumeric() const { SimpleTokenList nonNumeric("abc"); - ASSERT_EQUALS(false, Token::Match(nonNumeric.tokens(), "%num%")); + ASSERT_EQUALS(false, Token::Match(nonNumeric.front(), "%num%")); SimpleTokenList msLiteral("5ms"); // #11438 - ASSERT_EQUALS(false, Token::Match(msLiteral.tokens(), "%num%")); + ASSERT_EQUALS(false, Token::Match(msLiteral.front(), "%num%")); SimpleTokenList sLiteral("3s"); - ASSERT_EQUALS(false, Token::Match(sLiteral.tokens(), "%num%")); + ASSERT_EQUALS(false, Token::Match(sLiteral.front(), "%num%")); SimpleTokenList octal("0123"); - ASSERT_EQUALS(true, Token::Match(octal.tokens(), "%num%")); + ASSERT_EQUALS(true, Token::Match(octal.front(), "%num%")); SimpleTokenList decimal("4567"); - ASSERT_EQUALS(true, Token::Match(decimal.tokens(), "%num%")); + ASSERT_EQUALS(true, Token::Match(decimal.front(), "%num%")); SimpleTokenList hexadecimal("0xDEADBEEF"); - ASSERT_EQUALS(true, Token::Match(hexadecimal.tokens(), "%num%")); + ASSERT_EQUALS(true, Token::Match(hexadecimal.front(), "%num%")); SimpleTokenList floatingPoint("0.0f"); - ASSERT_EQUALS(true, Token::Match(floatingPoint.tokens(), "%num%")); + ASSERT_EQUALS(true, Token::Match(floatingPoint.front(), "%num%")); SimpleTokenList signedLong("0L"); - ASSERT_EQUALS(true, Token::Match(signedLong.tokens(), "%num%")); + ASSERT_EQUALS(true, Token::Match(signedLong.front(), "%num%")); SimpleTokenList negativeSignedLong("-0L"); - ASSERT_EQUALS(true, Token::Match(negativeSignedLong.tokens(), "- %num%")); + ASSERT_EQUALS(true, Token::Match(negativeSignedLong.front(), "- %num%")); SimpleTokenList positiveSignedLong("+0L"); - ASSERT_EQUALS(true, Token::Match(positiveSignedLong.tokens(), "+ %num%")); + ASSERT_EQUALS(true, Token::Match(positiveSignedLong.front(), "+ %num%")); SimpleTokenList unsignedInt("0U"); - ASSERT_EQUALS(true, Token::Match(unsignedInt.tokens(), "%num%")); + ASSERT_EQUALS(true, Token::Match(unsignedInt.front(), "%num%")); SimpleTokenList unsignedLong("0UL"); - ASSERT_EQUALS(true, Token::Match(unsignedLong.tokens(), "%num%")); + ASSERT_EQUALS(true, Token::Match(unsignedLong.front(), "%num%")); SimpleTokenList unsignedLongLong("0ULL"); - ASSERT_EQUALS(true, Token::Match(unsignedLongLong.tokens(), "%num%")); + ASSERT_EQUALS(true, Token::Match(unsignedLongLong.front(), "%num%")); SimpleTokenList positive("+666"); - ASSERT_EQUALS(true, Token::Match(positive.tokens(), "+ %num%")); + ASSERT_EQUALS(true, Token::Match(positive.front(), "+ %num%")); SimpleTokenList negative("-42"); - ASSERT_EQUALS(true, Token::Match(negative.tokens(), "- %num%")); + ASSERT_EQUALS(true, Token::Match(negative.front(), "- %num%")); SimpleTokenList negativeNull("-.0"); - ASSERT_EQUALS(true, Token::Match(negativeNull.tokens(), "- %num%")); + ASSERT_EQUALS(true, Token::Match(negativeNull.front(), "- %num%")); SimpleTokenList positiveNull("+.0"); - ASSERT_EQUALS(true, Token::Match(positiveNull.tokens(), "+ %num%")); + ASSERT_EQUALS(true, Token::Match(positiveNull.front(), "+ %num%")); } void matchBoolean() const { SimpleTokenList yes("YES"); - ASSERT_EQUALS(false, Token::Match(yes.tokens(), "%bool%")); + ASSERT_EQUALS(false, Token::Match(yes.front(), "%bool%")); SimpleTokenList positive("true"); - ASSERT_EQUALS(true, Token::Match(positive.tokens(), "%bool%")); + ASSERT_EQUALS(true, Token::Match(positive.front(), "%bool%")); SimpleTokenList negative("false"); - ASSERT_EQUALS(true, Token::Match(negative.tokens(), "%bool%")); + ASSERT_EQUALS(true, Token::Match(negative.front(), "%bool%")); } void matchOr() { SimpleTokenList bitwiseOr(";|;"); // cppcheck-suppress simplePatternError - this is intentional - ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "; %or%")); - ASSERT_EQUALS(true, Token::Match(bitwiseOr.tokens(), "; %op%")); + ASSERT_EQUALS(true, Token::Match(bitwiseOr.front(), "; %or%")); + ASSERT_EQUALS(true, Token::Match(bitwiseOr.front(), "; %op%")); // cppcheck-suppress simplePatternError - this is intentional - ASSERT_EQUALS(false, Token::Match(bitwiseOr.tokens(), "; %oror%")); + ASSERT_EQUALS(false, Token::Match(bitwiseOr.front(), "; %oror%")); SimpleTokenizer bitwiseOrAssignment(*this, ";|=;"); // cppcheck-suppress simplePatternError - this is intentional @@ -759,17 +759,17 @@ class TestToken : public TestFixture { SimpleTokenList logicalOr(";||;"); // cppcheck-suppress simplePatternError - this is intentional - ASSERT_EQUALS(false, Token::Match(logicalOr.tokens(), "; %or%")); - ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "; %op%")); + ASSERT_EQUALS(false, Token::Match(logicalOr.front(), "; %or%")); + ASSERT_EQUALS(true, Token::Match(logicalOr.front(), "; %op%")); // cppcheck-suppress simplePatternError - this is intentional - ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "; %oror%")); - ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "; &&|%oror%")); - ASSERT_EQUALS(true, Token::Match(logicalOr.tokens(), "; %oror%|&&")); + ASSERT_EQUALS(true, Token::Match(logicalOr.front(), "; %oror%")); + ASSERT_EQUALS(true, Token::Match(logicalOr.front(), "; &&|%oror%")); + ASSERT_EQUALS(true, Token::Match(logicalOr.front(), "; %oror%|&&")); SimpleTokenList logicalAnd(";&&;"); - ASSERT_EQUALS(true, Token::simpleMatch(logicalAnd.tokens(), "; &&")); - ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "; &&|%oror%")); - ASSERT_EQUALS(true, Token::Match(logicalAnd.tokens(), "; %oror%|&&")); + ASSERT_EQUALS(true, Token::simpleMatch(logicalAnd.front(), "; &&")); + ASSERT_EQUALS(true, Token::Match(logicalAnd.front(), "; &&|%oror%")); + ASSERT_EQUALS(true, Token::Match(logicalAnd.front(), "; %oror%|&&")); } static void append_vector(std::vector &dest, const std::vector &src) { From b9e616b4e63ae0bc173a9aa811833f779298aa48 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 5 Mar 2024 12:49:21 +0100 Subject: [PATCH 4/7] testrunner: more usage of `Simple*` helpers --- Makefile | 4 +-- test/helpers.h | 1 + test/testlibrary.cpp | 55 +++++++++++++++++------------------------ test/testtokenlist.cpp | 31 ++++++----------------- test/testtokenrange.cpp | 26 +++++++++---------- 5 files changed, 44 insertions(+), 73 deletions(-) diff --git a/Makefile b/Makefile index 314bf5c4e66..23a15c49e54 100644 --- a/Makefile +++ b/Makefile @@ -856,10 +856,10 @@ test/testtoken.o: test/testtoken.cpp lib/addoninfo.h lib/check.h lib/color.h lib test/testtokenize.o: test/testtokenize.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtokenize.cpp -test/testtokenlist.o: test/testtokenlist.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h +test/testtokenlist.o: test/testtokenlist.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtokenlist.cpp -test/testtokenrange.o: test/testtokenrange.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/tokenrange.h lib/utils.h lib/vfvalue.h test/fixture.h +test/testtokenrange.o: test/testtokenrange.cpp lib/addoninfo.h lib/check.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/tokenrange.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h $(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testtokenrange.cpp test/testtype.o: test/testtype.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/check.h lib/checktype.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/preprocessor.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h diff --git a/test/helpers.h b/test/helpers.h index 7c49020b634..3d0e61f6338 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -63,6 +63,7 @@ class SimpleTokenizer { class SimpleTokenList { public: + explicit SimpleTokenList(const char code[], bool cpp = true) { std::istringstream iss(code); diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index 5b34e00dc09..65eae71d42b 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -117,9 +117,8 @@ class TestLibrary : public TestFixture { " \n" ""; - TokenList tokenList(&settings); - std::istringstream istr("foo();"); - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "foo();"; + SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); Library library; @@ -140,16 +139,14 @@ class TestLibrary : public TestFixture { Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); { - TokenList tokenList(&settings); - std::istringstream istr("fred.foo(123);"); // <- wrong scope, not library function - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "fred.foo(123);"; // <- wrong scope, not library function + SimpleTokenList tokenList(code); ASSERT(library.isNotLibraryFunction(tokenList.front()->tokAt(2))); } { - TokenList tokenList(&settings); - std::istringstream istr("Fred::foo(123);"); // <- wrong scope, not library function - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "Fred::foo(123);"; // <- wrong scope, not library function + SimpleTokenList tokenList(code); ASSERT(library.isNotLibraryFunction(tokenList.front()->tokAt(2))); } @@ -232,9 +229,8 @@ class TestLibrary : public TestFixture { " \n" ""; - TokenList tokenList(&settings); - std::istringstream istr("Fred foo(123);"); // <- Variable declaration, not library function - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "Fred foo(123);"; // <- Variable declaration, not library function + SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); tokenList.front()->next()->varId(1); @@ -292,9 +288,8 @@ class TestLibrary : public TestFixture { ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); ASSERT_EQUALS(0, library.functions["foo"].argumentChecks[-1].notuninit); - TokenList tokenList(&settings); - std::istringstream istr("foo(a,b,c,d,e);"); - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "foo(a,b,c,d,e);"; + SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); ASSERT_EQUALS(false, library.isuninitargbad(tokenList.front(), 1)); @@ -317,9 +312,8 @@ class TestLibrary : public TestFixture { Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); - TokenList tokenList(&settings); - std::istringstream istr("foo(a,b,c,d);"); - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "foo(a,b,c,d);"; + SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); ASSERT(Library::ArgumentChecks::Direction::DIR_IN == library.getArgDirection(tokenList.front(), 1)); @@ -349,9 +343,8 @@ class TestLibrary : public TestFixture { Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); - TokenList tokenList(&settings); - std::istringstream istr("foo(a,b,c,d,e,f,g,h,i,j,k);"); - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "foo(a,b,c,d,e,f,g,h,i,j,k);"; + SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); // 1- @@ -491,9 +484,8 @@ class TestLibrary : public TestFixture { Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); - TokenList tokenList(&settings); - std::istringstream istr("foo(a,b,c,d,e);"); - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "foo(a,b,c,d,e);"; + SimpleTokenList tokenList(code); tokenList.front()->next()->astOperand1(tokenList.front()); // arg1: type=strlen arg2 @@ -554,16 +546,14 @@ class TestLibrary : public TestFixture { ASSERT(library.functions.at("bar").argumentChecks.empty()); { - TokenList tokenList(&settings); - std::istringstream istr("Foo::foo();"); - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "Foo::foo();"; + SimpleTokenList tokenList(code); ASSERT(library.isnotnoreturn(tokenList.front()->tokAt(2))); } { - TokenList tokenList(&settings); - std::istringstream istr("bar();"); - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "bar();"; + SimpleTokenList tokenList(code); ASSERT(library.isnotnoreturn(tokenList.front())); } } @@ -635,9 +625,8 @@ class TestLibrary : public TestFixture { Library library; ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); - TokenList tokenList(&settings); - std::istringstream istr("a(); b();"); - tokenList.createTokens(istr, Standards::Language::CPP); + const char code[] = "a(); b();"; + SimpleTokenList tokenList(code); const Library::WarnInfo* a = library.getWarnInfo(tokenList.front()); const Library::WarnInfo* b = library.getWarnInfo(tokenList.front()->tokAt(4)); diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index e58dd7b7c6d..245f5360079 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -18,6 +18,7 @@ #include "settings.h" #include "fixture.h" +#include "helpers.h" #include "platform.h" #include "standards.h" #include "token.h" @@ -62,11 +63,7 @@ class TestTokenList : public TestFixture { errout.str(""); - // tokenize.. - TokenList tokenlist(&settings); - std::istringstream istr(code); - tokenlist.createTokens(istr, "a.cpp"); - + SimpleTokenList tokenlist(code); ASSERT(Token::simpleMatch(tokenlist.front(), "a + + 1 ; 1 + + b ;")); } @@ -75,9 +72,7 @@ class TestTokenList : public TestFixture { const char code[] = "for a int delete true"; { - TokenList tokenlist(&settings); - std::istringstream istr(code); - tokenlist.createTokens(istr, "a.c"); + SimpleTokenList tokenlist(code, false); ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); ASSERT_EQUALS(true, tokenlist.front()->isControlFlowKeyword()); @@ -93,9 +88,7 @@ class TestTokenList : public TestFixture { ASSERT_EQUALS(false, tokenlist.front()->tokAt(4)->isControlFlowKeyword()); } { - TokenList tokenlist(&settings); - std::istringstream istr(code); - tokenlist.createTokens(istr, "a.cpp"); + SimpleTokenList tokenlist(code); ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); ASSERT_EQUALS(true, tokenlist.front()->isControlFlowKeyword()); @@ -113,17 +106,13 @@ class TestTokenList : public TestFixture { { const char code2[] = "_Generic"; // C11 keyword - TokenList tokenlist(&settings); // default settings use latest standard - std::istringstream istr(code2); - tokenlist.createTokens(istr, "a.cpp"); + SimpleTokenList tokenlist(code2); // default settings use latest standard ASSERT_EQUALS(false, tokenlist.front()->isKeyword()); } { const char code2[] = "_Generic"; // C11 keyword - TokenList tokenlist(&settings); // default settings use latest standard - std::istringstream istr(code2); - tokenlist.createTokens(istr, "a.c"); + SimpleTokenList tokenlist(code2, false); // default settings use latest standard ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); } @@ -138,17 +127,13 @@ class TestTokenList : public TestFixture { { const char code2[] = "co_return"; // C++20 keyword - TokenList tokenlist(&settings); // default settings use latest standard - std::istringstream istr(code2); - tokenlist.createTokens(istr, "a.cpp"); + SimpleTokenList tokenlist(code2); // default settings use latest standard ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); } { const char code2[] = "co_return"; // C++20 keyword - TokenList tokenlist(&settings); // default settings use latest standard - std::istringstream istr(code2); - tokenlist.createTokens(istr, "a.c"); + SimpleTokenList tokenlist(code2, false); // default settings use latest standard ASSERT_EQUALS(false, tokenlist.front()->isKeyword()); } diff --git a/test/testtokenrange.cpp b/test/testtokenrange.cpp index dee15b918c6..a01c65628e2 100644 --- a/test/testtokenrange.cpp +++ b/test/testtokenrange.cpp @@ -18,6 +18,7 @@ #include "settings.h" #include "fixture.h" +#include "helpers.h" #include "token.h" #include "tokenize.h" #include "tokenlist.h" @@ -69,32 +70,28 @@ class TestTokenRange : public TestFixture { } void enumerationToEnd() const { - std::istringstream istr("void a(){} void main(){ if(true){a();} }"); - TokenList tokenList(&settingsDefault); - tokenList.createTokens(istr, "test.cpp"); + const char code[] = "void a(){} void main(){ if(true){a();} }"; + SimpleTokenList tokenList(code); ASSERT_EQUALS("", testTokenRange(ConstTokenRange{ tokenList.front(), nullptr }, tokenList.front(), nullptr)); } void untilHelperToEnd() const { - std::istringstream istr("void a(){} void main(){ if(true){a();} }"); - TokenList tokenList(&settingsDefault); - tokenList.createTokens(istr, "test.cpp"); + const char code[] = "void a(){} void main(){ if(true){a();} }"; + SimpleTokenList tokenList(code); ASSERT_EQUALS("", testTokenRange(tokenList.front()->until(nullptr), tokenList.front(), nullptr)); } void untilHelperPartWay() const { - std::istringstream istr("void a(){} void main(){ if(true){a();} }"); - TokenList tokenList(&settingsDefault); - tokenList.createTokens(istr, "test.cpp"); + const char code[] = "void a(){} void main(){ if(true){a();} }"; + SimpleTokenList tokenList(code); const Token* start = tokenList.front()->tokAt(4); const Token* end = start->tokAt(8); ASSERT_EQUALS("", testTokenRange(start->until(end), start, end)); } void partialEnumeration() const { - std::istringstream istr("void a(){} void main(){ if(true){a();} }"); - TokenList tokenList(&settingsDefault); - tokenList.createTokens(istr, "test.cpp"); + const char code[] = "void a(){} void main(){ if(true){a();} }"; + SimpleTokenList tokenList(code); const Token* start = tokenList.front()->tokAt(4); const Token* end = tokenList.front()->tokAt(10); ASSERT_EQUALS("", testTokenRange(ConstTokenRange{ start, end }, start, end)); @@ -116,9 +113,8 @@ class TestTokenRange : public TestFixture { } void exampleAlgorithms() const { - std::istringstream istr("void a(){} void main(){ if(true){a();} }"); - TokenList tokenList(&settingsDefault); - tokenList.createTokens(istr, "test.cpp"); + const char code[] = "void a(){} void main(){ if(true){a();} }"; + SimpleTokenList tokenList(code); ConstTokenRange range{ tokenList.front(), nullptr }; ASSERT_EQUALS(true, std::all_of(range.begin(), range.end(), [](const Token*) { return true; From 6c37b31c41a386c8e1b53b942873f69bb996455e Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 5 Mar 2024 12:51:40 +0100 Subject: [PATCH 5/7] testrunner: made `Simple*` objects `const` if possible --- test/testlibrary.cpp | 26 +++---- test/testsymboldatabase.cpp | 2 +- test/testtoken.cpp | 146 ++++++++++++++++++------------------ test/testtokenlist.cpp | 14 ++-- test/testtokenrange.cpp | 10 +-- 5 files changed, 99 insertions(+), 99 deletions(-) diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index 65eae71d42b..01837ed1b16 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -140,13 +140,13 @@ class TestLibrary : public TestFixture { ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); { const char code[] = "fred.foo(123);"; // <- wrong scope, not library function - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); ASSERT(library.isNotLibraryFunction(tokenList.front()->tokAt(2))); } { const char code[] = "Fred::foo(123);"; // <- wrong scope, not library function - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); ASSERT(library.isNotLibraryFunction(tokenList.front()->tokAt(2))); } @@ -547,13 +547,13 @@ class TestLibrary : public TestFixture { { const char code[] = "Foo::foo();"; - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); ASSERT(library.isnotnoreturn(tokenList.front()->tokAt(2))); } { const char code[] = "bar();"; - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); ASSERT(library.isnotnoreturn(tokenList.front())); } } @@ -626,7 +626,7 @@ class TestLibrary : public TestFixture { ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); const char code[] = "a(); b();"; - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); const Library::WarnInfo* a = library.getWarnInfo(tokenList.front()); const Library::WarnInfo* b = library.getWarnInfo(tokenList.front()->tokAt(4)); @@ -860,7 +860,7 @@ class TestLibrary : public TestFixture { ASSERT_EQUALS(C.arrayLike_indexOp, true); { - SimpleTokenizer var(*this, "std::A a;"); + const SimpleTokenizer var(*this, "std::A a;"); ASSERT_EQUALS(&A, library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -869,14 +869,14 @@ class TestLibrary : public TestFixture { } { - SimpleTokenizer var(*this, "std::A::size_type a_s;"); + const SimpleTokenizer var(*this, "std::A::size_type a_s;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); } { - SimpleTokenizer var(*this, "std::A::iterator a_it;"); + const SimpleTokenizer var(*this, "std::A::iterator a_it;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT_EQUALS(&A, library.detectIterator(var.tokens())); bool isIterator; @@ -885,7 +885,7 @@ class TestLibrary : public TestFixture { } { - SimpleTokenizer var(*this, "std::B b;"); + const SimpleTokenizer var(*this, "std::B b;"); ASSERT_EQUALS(&B, library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); bool isIterator; @@ -894,14 +894,14 @@ class TestLibrary : public TestFixture { } { - SimpleTokenizer var(*this, "std::B::size_type b_s;"); + const SimpleTokenizer var(*this, "std::B::size_type b_s;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); } { - SimpleTokenizer var(*this, "std::B::iterator b_it;"); + const SimpleTokenizer var(*this, "std::B::iterator b_it;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT_EQUALS(&B, library.detectIterator(var.tokens())); bool isIterator; @@ -910,14 +910,14 @@ class TestLibrary : public TestFixture { } { - SimpleTokenizer var(*this, "C c;"); + const SimpleTokenizer var(*this, "C c;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); } { - SimpleTokenizer var(*this, "D d;"); + const SimpleTokenizer var(*this, "D d;"); ASSERT(!library.detectContainer(var.tokens())); ASSERT(!library.detectIterator(var.tokens())); ASSERT(!library.detectContainerOrIterator(var.tokens())); diff --git a/test/testsymboldatabase.cpp b/test/testsymboldatabase.cpp index 0ec998e5879..1328945d325 100644 --- a/test/testsymboldatabase.cpp +++ b/test/testsymboldatabase.cpp @@ -817,7 +817,7 @@ class TestSymbolDatabase : public TestFixture { } { reset(); - SimpleTokenizer constpointer(*this, "const int* p;"); + const SimpleTokenizer constpointer(*this, "const int* p;"); Variable v2(constpointer.tokens()->tokAt(3), constpointer.tokens()->next(), constpointer.tokens()->tokAt(2), 0, AccessControl::Public, nullptr, nullptr, &settings1); ASSERT(false == v2.isArray()); ASSERT(true == v2.isPointer()); diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 09aab594f9c..bd5b9f3b866 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -233,7 +233,7 @@ class TestToken : public TestFixture { void multiCompare2() const { // #3294 // Original pattern that failed: [[,(=<>+-*|&^] %num% [+-*/] %num% ]|,|)|;|=|%op% - SimpleTokenList toks("a == 1"); + const SimpleTokenList toks("a == 1"); ASSERT_EQUALS(true, Token::Match(toks.front(), "a =|%op%")); } @@ -242,28 +242,28 @@ class TestToken : public TestFixture { // Code snippet that failed: "return lv@86 |= rv@87 ;" // Note: Also test "reverse" alternative pattern, two different code paths to handle it - SimpleTokenList toks("return a |= b ;"); + const SimpleTokenList toks("return a |= b ;"); ASSERT_EQUALS(false, Token::Match(toks.front(), "return %name% xyz|%or% %name% ;")); ASSERT_EQUALS(false, Token::Match(toks.front(), "return %name% %or%|xyz %name% ;")); - SimpleTokenList toks2("return a | b ;"); + const SimpleTokenList toks2("return a | b ;"); ASSERT_EQUALS(true, Token::Match(toks2.front(), "return %name% xyz|%or% %name% ;")); ASSERT_EQUALS(true, Token::Match(toks2.front(), "return %name% %or%|xyz %name% ;")); - SimpleTokenList toks3("return a || b ;"); + const SimpleTokenList toks3("return a || b ;"); ASSERT_EQUALS(false, Token::Match(toks3.front(), "return %name% xyz|%or% %name% ;")); ASSERT_EQUALS(false, Token::Match(toks3.front(), "return %name% %or%|xyz %name% ;")); ASSERT_EQUALS(true, Token::Match(toks3.front(), "return %name% xyz|%oror% %name% ;")); ASSERT_EQUALS(true, Token::Match(toks3.front(), "return %name% %oror%|xyz %name% ;")); - SimpleTokenList toks4("a % b ;"); + const SimpleTokenList toks4("a % b ;"); ASSERT_EQUALS(true, Token::Match(toks4.front(), "%name% >>|<<|&|%or%|^|% %name% ;")); ASSERT_EQUALS(true, Token::Match(toks4.front(), "%name% %|>>|<<|&|%or%|^ %name% ;")); ASSERT_EQUALS(true, Token::Match(toks4.front(), "%name% >>|<<|&|%or%|%|^ %name% ;")); //%name%|%num% support - SimpleTokenList num("100"); + const SimpleTokenList num("100"); ASSERT_EQUALS(true, Token::Match(num.front(), "%num%|%name%")); ASSERT_EQUALS(true, Token::Match(num.front(), "%name%|%num%")); ASSERT_EQUALS(true, Token::Match(num.front(), "%name%|%num%|%bool%")); @@ -273,7 +273,7 @@ class TestToken : public TestFixture { ASSERT_EQUALS(false, Token::Match(num.front(), "%type%|%bool%|%char%")); ASSERT_EQUALS(true, Token::Match(num.front(), "%type%|%bool%|100")); - SimpleTokenList numparen("( 100 )"); + const SimpleTokenList numparen("( 100 )"); ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| %num%|%name% )|")); ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| %name%|%num% )|")); ASSERT_EQUALS(true, Token::Match(numparen.front(), "(| %name%|%num%|%bool% )|")); @@ -290,7 +290,7 @@ class TestToken : public TestFixture { } void multiCompare4() { - SimpleTokenizer var(*this, "std :: queue < int > foo ;"); + const SimpleTokenizer var(*this, "std :: queue < int > foo ;"); ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(3)->tokType()); ASSERT_EQUALS(Token::eBracket, var.tokens()->tokAt(5)->tokType()); @@ -546,17 +546,17 @@ class TestToken : public TestFixture { } void nextArgument() { - SimpleTokenizer example1(*this, "foo(1, 2, 3, 4);"); + const SimpleTokenizer example1(*this, "foo(1, 2, 3, 4);"); ASSERT_EQUALS(true, Token::simpleMatch(example1.tokens()->tokAt(2)->nextArgument(), "2 , 3")); ASSERT_EQUALS(true, Token::simpleMatch(example1.tokens()->tokAt(4)->nextArgument(), "3 , 4")); - SimpleTokenizer example2(*this, "foo();"); + const SimpleTokenizer example2(*this, "foo();"); ASSERT_EQUALS(true, example2.tokens()->tokAt(2)->nextArgument() == nullptr); - SimpleTokenizer example3(*this, "foo(bar(a, b), 2, 3);"); + const SimpleTokenizer example3(*this, "foo(bar(a, b), 2, 3);"); ASSERT_EQUALS(true, Token::simpleMatch(example3.tokens()->tokAt(2)->nextArgument(), "2 , 3")); - SimpleTokenizer example4(*this, "foo(x.i[1], \"\", 3);"); + const SimpleTokenizer example4(*this, "foo(x.i[1], \"\", 3);"); ASSERT_EQUALS(true, Token::simpleMatch(example4.tokens()->tokAt(2)->nextArgument(), "\"\" , 3")); } @@ -568,15 +568,15 @@ class TestToken : public TestFixture { void matchAny() const { - SimpleTokenList varBitOrVar("abc|def", true); + const SimpleTokenList varBitOrVar("abc|def", true); ASSERT_EQUALS(true, Token::Match(varBitOrVar.front(), "%name% %or% %name%")); - SimpleTokenList varLogOrVar("abc||def", true); + const SimpleTokenList varLogOrVar("abc||def", true); ASSERT_EQUALS(true, Token::Match(varLogOrVar.front(), "%name% %oror% %name%")); } void matchSingleChar() const { - SimpleTokenList singleChar("a", true); + const SimpleTokenList singleChar("a", true); ASSERT_EQUALS(true, Token::Match(singleChar.front(), "[a|bc]")); ASSERT_EQUALS(false, Token::Match(singleChar.front(), "[d|ef]")); @@ -587,81 +587,81 @@ class TestToken : public TestFixture { } void matchNothingOrAnyNotElse() const { - SimpleTokenList empty_String(""); + const SimpleTokenList empty_String(""); ASSERT_EQUALS(true, Token::Match(empty_String.front(), "!!else")); ASSERT_EQUALS(false, Token::Match(empty_String.front(), "!!else something")); - SimpleTokenList ifSemicolon("if ;"); + const SimpleTokenList ifSemicolon("if ;"); ASSERT_EQUALS(true, Token::Match(ifSemicolon.front(), "if ; !!else")); - SimpleTokenList ifSemicolonSomething("if ; something", true); + const SimpleTokenList ifSemicolonSomething("if ; something", true); ASSERT_EQUALS(true, Token::Match(ifSemicolonSomething.front(), "if ; !!else")); - SimpleTokenList justElse("else"); + const SimpleTokenList justElse("else"); ASSERT_EQUALS(false, Token::Match(justElse.front(), "!!else")); - SimpleTokenList ifSemicolonElse("if ; else"); + const SimpleTokenList ifSemicolonElse("if ; else"); ASSERT_EQUALS(false, Token::Match(ifSemicolonElse.front(), "if ; !!else")); } void matchType() { - SimpleTokenList type("abc"); + const SimpleTokenList type("abc"); ASSERT_EQUALS(true, Token::Match(type.front(), "%type%")); - SimpleTokenizer isVar(*this, "int a = 3 ;"); + const SimpleTokenizer isVar(*this, "int a = 3 ;"); ASSERT_EQUALS(true, Token::Match(isVar.tokens(), "%type%")); ASSERT_EQUALS(true, Token::Match(isVar.tokens(), "%type% %name%")); ASSERT_EQUALS(false, Token::Match(isVar.tokens(), "%type% %type%")); - SimpleTokenList noType1_cpp("delete"); + const SimpleTokenList noType1_cpp("delete"); ASSERT_EQUALS(false, Token::Match(noType1_cpp.front(), "%type%")); - SimpleTokenList noType1_c("delete", false); + const SimpleTokenList noType1_c("delete", false); ASSERT_EQUALS(true, Token::Match(noType1_c.front(), "%type%")); - SimpleTokenList noType2("void delete"); + const SimpleTokenList noType2("void delete"); ASSERT_EQUALS(false, Token::Match(noType2.front(), "!!foo %type%")); } void matchChar() const { - SimpleTokenList chr1("'a'"); + const SimpleTokenList chr1("'a'"); ASSERT_EQUALS(true, Token::Match(chr1.front(), "%char%")); - SimpleTokenList chr2("'1'"); + const SimpleTokenList chr2("'1'"); ASSERT_EQUALS(true, Token::Match(chr2.front(), "%char%")); - SimpleTokenList noChr("\"10\""); + const SimpleTokenList noChr("\"10\""); ASSERT_EQUALS(false, Token::Match(noChr.front(), "%char%")); } void matchCompOp() const { - SimpleTokenList comp1("<="); + const SimpleTokenList comp1("<="); ASSERT_EQUALS(true, Token::Match(comp1.front(), "%comp%")); - SimpleTokenList comp2(">"); + const SimpleTokenList comp2(">"); ASSERT_EQUALS(true, Token::Match(comp2.front(), "%comp%")); - SimpleTokenList noComp("="); + const SimpleTokenList noComp("="); ASSERT_EQUALS(false, Token::Match(noComp.front(), "%comp%")); } void matchStr() const { - SimpleTokenList noStr1("abc"); + const SimpleTokenList noStr1("abc"); ASSERT_EQUALS(false, Token::Match(noStr1.front(), "%str%")); - SimpleTokenList noStr2("'a'"); + const SimpleTokenList noStr2("'a'"); ASSERT_EQUALS(false, Token::Match(noStr2.front(), "%str%")); - SimpleTokenList str("\"abc\""); + const SimpleTokenList str("\"abc\""); ASSERT_EQUALS(true, Token::Match(str.front(), "%str%")); // Empty string - SimpleTokenList emptyStr("\"\""); + const SimpleTokenList emptyStr("\"\""); ASSERT_EQUALS(true, Token::Match(emptyStr.front(), "%str%")); } void matchVarid() { - SimpleTokenizer var(*this, "int a ; int b ;"); + const SimpleTokenizer var(*this, "int a ; int b ;"); // Varid == 0 should throw exception ASSERT_THROW((void)Token::Match(var.tokens(), "%type% %varid% ; %type% %name%", 0),InternalError); @@ -678,86 +678,86 @@ class TestToken : public TestFixture { } void matchNumeric() const { - SimpleTokenList nonNumeric("abc"); + const SimpleTokenList nonNumeric("abc"); ASSERT_EQUALS(false, Token::Match(nonNumeric.front(), "%num%")); - SimpleTokenList msLiteral("5ms"); // #11438 + const SimpleTokenList msLiteral("5ms"); // #11438 ASSERT_EQUALS(false, Token::Match(msLiteral.front(), "%num%")); - SimpleTokenList sLiteral("3s"); + const SimpleTokenList sLiteral("3s"); ASSERT_EQUALS(false, Token::Match(sLiteral.front(), "%num%")); - SimpleTokenList octal("0123"); + const SimpleTokenList octal("0123"); ASSERT_EQUALS(true, Token::Match(octal.front(), "%num%")); - SimpleTokenList decimal("4567"); + const SimpleTokenList decimal("4567"); ASSERT_EQUALS(true, Token::Match(decimal.front(), "%num%")); - SimpleTokenList hexadecimal("0xDEADBEEF"); + const SimpleTokenList hexadecimal("0xDEADBEEF"); ASSERT_EQUALS(true, Token::Match(hexadecimal.front(), "%num%")); - SimpleTokenList floatingPoint("0.0f"); + const SimpleTokenList floatingPoint("0.0f"); ASSERT_EQUALS(true, Token::Match(floatingPoint.front(), "%num%")); - SimpleTokenList signedLong("0L"); + const SimpleTokenList signedLong("0L"); ASSERT_EQUALS(true, Token::Match(signedLong.front(), "%num%")); - SimpleTokenList negativeSignedLong("-0L"); + const SimpleTokenList negativeSignedLong("-0L"); ASSERT_EQUALS(true, Token::Match(negativeSignedLong.front(), "- %num%")); - SimpleTokenList positiveSignedLong("+0L"); + const SimpleTokenList positiveSignedLong("+0L"); ASSERT_EQUALS(true, Token::Match(positiveSignedLong.front(), "+ %num%")); - SimpleTokenList unsignedInt("0U"); + const SimpleTokenList unsignedInt("0U"); ASSERT_EQUALS(true, Token::Match(unsignedInt.front(), "%num%")); - SimpleTokenList unsignedLong("0UL"); + const SimpleTokenList unsignedLong("0UL"); ASSERT_EQUALS(true, Token::Match(unsignedLong.front(), "%num%")); - SimpleTokenList unsignedLongLong("0ULL"); + const SimpleTokenList unsignedLongLong("0ULL"); ASSERT_EQUALS(true, Token::Match(unsignedLongLong.front(), "%num%")); - SimpleTokenList positive("+666"); + const SimpleTokenList positive("+666"); ASSERT_EQUALS(true, Token::Match(positive.front(), "+ %num%")); - SimpleTokenList negative("-42"); + const SimpleTokenList negative("-42"); ASSERT_EQUALS(true, Token::Match(negative.front(), "- %num%")); - SimpleTokenList negativeNull("-.0"); + const SimpleTokenList negativeNull("-.0"); ASSERT_EQUALS(true, Token::Match(negativeNull.front(), "- %num%")); - SimpleTokenList positiveNull("+.0"); + const SimpleTokenList positiveNull("+.0"); ASSERT_EQUALS(true, Token::Match(positiveNull.front(), "+ %num%")); } void matchBoolean() const { - SimpleTokenList yes("YES"); + const SimpleTokenList yes("YES"); ASSERT_EQUALS(false, Token::Match(yes.front(), "%bool%")); - SimpleTokenList positive("true"); + const SimpleTokenList positive("true"); ASSERT_EQUALS(true, Token::Match(positive.front(), "%bool%")); - SimpleTokenList negative("false"); + const SimpleTokenList negative("false"); ASSERT_EQUALS(true, Token::Match(negative.front(), "%bool%")); } void matchOr() { - SimpleTokenList bitwiseOr(";|;"); + const SimpleTokenList bitwiseOr(";|;"); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(true, Token::Match(bitwiseOr.front(), "; %or%")); ASSERT_EQUALS(true, Token::Match(bitwiseOr.front(), "; %op%")); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(bitwiseOr.front(), "; %oror%")); - SimpleTokenizer bitwiseOrAssignment(*this, ";|=;"); + const SimpleTokenizer bitwiseOrAssignment(*this, ";|=;"); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.tokens(), "; %or%")); ASSERT_EQUALS(true, Token::Match(bitwiseOrAssignment.tokens(), "; %op%")); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.tokens(), "; %oror%")); - SimpleTokenList logicalOr(";||;"); + const SimpleTokenList logicalOr(";||;"); // cppcheck-suppress simplePatternError - this is intentional ASSERT_EQUALS(false, Token::Match(logicalOr.front(), "; %or%")); ASSERT_EQUALS(true, Token::Match(logicalOr.front(), "; %op%")); @@ -766,7 +766,7 @@ class TestToken : public TestFixture { ASSERT_EQUALS(true, Token::Match(logicalOr.front(), "; &&|%oror%")); ASSERT_EQUALS(true, Token::Match(logicalOr.front(), "; %oror%|&&")); - SimpleTokenList logicalAnd(";&&;"); + const SimpleTokenList logicalAnd(";&&;"); ASSERT_EQUALS(true, Token::simpleMatch(logicalAnd.front(), "; &&")); ASSERT_EQUALS(true, Token::Match(logicalAnd.front(), "; &&|%oror%")); ASSERT_EQUALS(true, Token::Match(logicalAnd.front(), "; %oror%|&&")); @@ -1106,14 +1106,14 @@ class TestToken : public TestFixture { } void canFindMatchingBracketsNeedsOpen() { - SimpleTokenizer var(*this, "std::deque > intsets;"); + const SimpleTokenizer var(*this, "std::deque > intsets;"); const Token* const t = var.tokens()->findClosingBracket(); ASSERT(t == nullptr); } void canFindMatchingBracketsInnerPair() { - SimpleTokenizer var(*this, "std::deque > intsets;"); + const SimpleTokenizer var(*this, "std::deque > intsets;"); const Token * const t = var.tokens()->tokAt(7)->findClosingBracket(); ASSERT_EQUALS(">", t->str()); @@ -1121,7 +1121,7 @@ class TestToken : public TestFixture { } void canFindMatchingBracketsOuterPair() { - SimpleTokenizer var(*this, "std::deque > intsets;"); + const SimpleTokenizer var(*this, "std::deque > intsets;"); const Token* const t = var.tokens()->tokAt(3)->findClosingBracket(); ASSERT_EQUALS(">", t->str()); @@ -1129,7 +1129,7 @@ class TestToken : public TestFixture { } void canFindMatchingBracketsWithTooManyClosing() { - SimpleTokenizer var(*this, "X< 1>2 > x1;"); + const SimpleTokenizer var(*this, "X< 1>2 > x1;"); const Token* const t = var.tokens()->next()->findClosingBracket(); ASSERT_EQUALS(">", t->str()); @@ -1137,7 +1137,7 @@ class TestToken : public TestFixture { } void canFindMatchingBracketsWithTooManyOpening() { - SimpleTokenizer var(*this, "X < (2 < 1) > x1;"); + const SimpleTokenizer var(*this, "X < (2 < 1) > x1;"); const Token* t = var.tokens()->next()->findClosingBracket(); ASSERT(t != nullptr && t->str() == ">"); @@ -1147,38 +1147,38 @@ class TestToken : public TestFixture { } void findClosingBracket() { - SimpleTokenizer var(*this, "template struct S : public Fred> {}"); + const SimpleTokenizer var(*this, "template struct S : public Fred> {}"); const Token* const t = var.tokens()->next()->findClosingBracket(); ASSERT(Token::simpleMatch(t, "> struct")); } void findClosingBracket2() { - SimpleTokenizer var(*this, "const auto g = []() {};\n"); // #11275 + const SimpleTokenizer var(*this, "const auto g = []() {};\n"); // #11275 const Token* const t = Token::findsimplematch(var.tokens(), "<"); ASSERT(t && Token::simpleMatch(t->findClosingBracket(), ">")); } void expressionString() { - SimpleTokenizer var1(*this, "void f() { *((unsigned long long *)x) = 0; }"); + const SimpleTokenizer var1(*this, "void f() { *((unsigned long long *)x) = 0; }"); const Token *const tok1 = Token::findsimplematch(var1.tokens(), "*"); ASSERT_EQUALS("*((unsigned long long*)x)", tok1->expressionString()); - SimpleTokenizer var2(*this, "typedef unsigned long long u64; void f() { *((u64 *)x) = 0; }"); + const SimpleTokenizer var2(*this, "typedef unsigned long long u64; void f() { *((u64 *)x) = 0; }"); const Token *const tok2 = Token::findsimplematch(var2.tokens(), "*"); ASSERT_EQUALS("*((unsigned long long*)x)", tok2->expressionString()); - SimpleTokenizer data3(*this, "void f() { return (t){1,2}; }"); + const SimpleTokenizer data3(*this, "void f() { return (t){1,2}; }"); ASSERT_EQUALS("return(t){1,2}", data3.tokens()->tokAt(5)->expressionString()); - SimpleTokenizer data4(*this, "void f() { return L\"a\"; }"); + const SimpleTokenizer data4(*this, "void f() { return L\"a\"; }"); ASSERT_EQUALS("returnL\"a\"", data4.tokens()->tokAt(5)->expressionString()); - SimpleTokenizer data5(*this, "void f() { return U\"a\"; }"); + const SimpleTokenizer data5(*this, "void f() { return U\"a\"; }"); ASSERT_EQUALS("returnU\"a\"", data5.tokens()->tokAt(5)->expressionString()); - SimpleTokenizer data6(*this, "x = \"\\0\\x1\\x2\\x3\\x4\\x5\\x6\\x7\";"); + const SimpleTokenizer data6(*this, "x = \"\\0\\x1\\x2\\x3\\x4\\x5\\x6\\x7\";"); ASSERT_EQUALS("x=\"\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07\"", data6.tokens()->next()->expressionString()); } diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index 245f5360079..0a7239c2b21 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -63,7 +63,7 @@ class TestTokenList : public TestFixture { errout.str(""); - SimpleTokenList tokenlist(code); + const SimpleTokenList tokenlist(code); ASSERT(Token::simpleMatch(tokenlist.front(), "a + + 1 ; 1 + + b ;")); } @@ -72,7 +72,7 @@ class TestTokenList : public TestFixture { const char code[] = "for a int delete true"; { - SimpleTokenList tokenlist(code, false); + const SimpleTokenList tokenlist(code, false); ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); ASSERT_EQUALS(true, tokenlist.front()->isControlFlowKeyword()); @@ -88,7 +88,7 @@ class TestTokenList : public TestFixture { ASSERT_EQUALS(false, tokenlist.front()->tokAt(4)->isControlFlowKeyword()); } { - SimpleTokenList tokenlist(code); + const SimpleTokenList tokenlist(code); ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); ASSERT_EQUALS(true, tokenlist.front()->isControlFlowKeyword()); @@ -106,13 +106,13 @@ class TestTokenList : public TestFixture { { const char code2[] = "_Generic"; // C11 keyword - SimpleTokenList tokenlist(code2); // default settings use latest standard + const SimpleTokenList tokenlist(code2); // default settings use latest standard ASSERT_EQUALS(false, tokenlist.front()->isKeyword()); } { const char code2[] = "_Generic"; // C11 keyword - SimpleTokenList tokenlist(code2, false); // default settings use latest standard + const SimpleTokenList tokenlist(code2, false); // default settings use latest standard ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); } @@ -127,13 +127,13 @@ class TestTokenList : public TestFixture { { const char code2[] = "co_return"; // C++20 keyword - SimpleTokenList tokenlist(code2); // default settings use latest standard + const SimpleTokenList tokenlist(code2); // default settings use latest standard ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); } { const char code2[] = "co_return"; // C++20 keyword - SimpleTokenList tokenlist(code2, false); // default settings use latest standard + const SimpleTokenList tokenlist(code2, false); // default settings use latest standard ASSERT_EQUALS(false, tokenlist.front()->isKeyword()); } diff --git a/test/testtokenrange.cpp b/test/testtokenrange.cpp index a01c65628e2..4843591654b 100644 --- a/test/testtokenrange.cpp +++ b/test/testtokenrange.cpp @@ -71,19 +71,19 @@ class TestTokenRange : public TestFixture { void enumerationToEnd() const { const char code[] = "void a(){} void main(){ if(true){a();} }"; - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); ASSERT_EQUALS("", testTokenRange(ConstTokenRange{ tokenList.front(), nullptr }, tokenList.front(), nullptr)); } void untilHelperToEnd() const { const char code[] = "void a(){} void main(){ if(true){a();} }"; - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); ASSERT_EQUALS("", testTokenRange(tokenList.front()->until(nullptr), tokenList.front(), nullptr)); } void untilHelperPartWay() const { const char code[] = "void a(){} void main(){ if(true){a();} }"; - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); const Token* start = tokenList.front()->tokAt(4); const Token* end = start->tokAt(8); ASSERT_EQUALS("", testTokenRange(start->until(end), start, end)); @@ -91,7 +91,7 @@ class TestTokenRange : public TestFixture { void partialEnumeration() const { const char code[] = "void a(){} void main(){ if(true){a();} }"; - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); const Token* start = tokenList.front()->tokAt(4); const Token* end = tokenList.front()->tokAt(10); ASSERT_EQUALS("", testTokenRange(ConstTokenRange{ start, end }, start, end)); @@ -114,7 +114,7 @@ class TestTokenRange : public TestFixture { void exampleAlgorithms() const { const char code[] = "void a(){} void main(){ if(true){a();} }"; - SimpleTokenList tokenList(code); + const SimpleTokenList tokenList(code); ConstTokenRange range{ tokenList.front(), nullptr }; ASSERT_EQUALS(true, std::all_of(range.begin(), range.end(), [](const Token*) { return true; From 202ae05ea16ff289a241c0bff576a36b258e8c33 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 5 Mar 2024 12:56:16 +0100 Subject: [PATCH 6/7] testrunner: pass `Standards::Language` to `SimpleTokenList` --- test/helpers.h | 5 +++-- test/testtoken.cpp | 12 ++++++------ test/testtokenlist.cpp | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/test/helpers.h b/test/helpers.h index 3d0e61f6338..d134b6121d1 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -20,6 +20,7 @@ #define helpersH #include "settings.h" +#include "standards.h" #include "tokenize.h" #include "tokenlist.h" @@ -64,10 +65,10 @@ class SimpleTokenList { public: - explicit SimpleTokenList(const char code[], bool cpp = true) + explicit SimpleTokenList(const char code[], Standards::Language lang = Standards::Language::CPP) { std::istringstream iss(code); - if (!list.createTokens(iss, cpp ? "test.cpp" : "test.c")) + if (!list.createTokens(iss, lang)) throw std::runtime_error("creating tokens failed"); } diff --git a/test/testtoken.cpp b/test/testtoken.cpp index bd5b9f3b866..95126e4048c 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -561,22 +561,22 @@ class TestToken : public TestFixture { } void eraseTokens() const { - SimpleTokenList code("begin ; { this code will be removed } end", true); + SimpleTokenList code("begin ; { this code will be removed } end", Standards::Language::C); Token::eraseTokens(code.front()->next(), code.front()->tokAt(9)); ASSERT_EQUALS("begin ; end", code.front()->stringifyList(nullptr, false)); } void matchAny() const { - const SimpleTokenList varBitOrVar("abc|def", true); + const SimpleTokenList varBitOrVar("abc|def"); ASSERT_EQUALS(true, Token::Match(varBitOrVar.front(), "%name% %or% %name%")); - const SimpleTokenList varLogOrVar("abc||def", true); + const SimpleTokenList varLogOrVar("abc||def"); ASSERT_EQUALS(true, Token::Match(varLogOrVar.front(), "%name% %oror% %name%")); } void matchSingleChar() const { - const SimpleTokenList singleChar("a", true); + const SimpleTokenList singleChar("a"); ASSERT_EQUALS(true, Token::Match(singleChar.front(), "[a|bc]")); ASSERT_EQUALS(false, Token::Match(singleChar.front(), "[d|ef]")); @@ -594,7 +594,7 @@ class TestToken : public TestFixture { const SimpleTokenList ifSemicolon("if ;"); ASSERT_EQUALS(true, Token::Match(ifSemicolon.front(), "if ; !!else")); - const SimpleTokenList ifSemicolonSomething("if ; something", true); + const SimpleTokenList ifSemicolonSomething("if ; something"); ASSERT_EQUALS(true, Token::Match(ifSemicolonSomething.front(), "if ; !!else")); const SimpleTokenList justElse("else"); @@ -616,7 +616,7 @@ class TestToken : public TestFixture { const SimpleTokenList noType1_cpp("delete"); ASSERT_EQUALS(false, Token::Match(noType1_cpp.front(), "%type%")); - const SimpleTokenList noType1_c("delete", false); + const SimpleTokenList noType1_c("delete", Standards::Language::C); ASSERT_EQUALS(true, Token::Match(noType1_c.front(), "%type%")); const SimpleTokenList noType2("void delete"); diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index 0a7239c2b21..a482fb306c0 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -72,7 +72,7 @@ class TestTokenList : public TestFixture { const char code[] = "for a int delete true"; { - const SimpleTokenList tokenlist(code, false); + const SimpleTokenList tokenlist(code, Standards::Language::C); ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); ASSERT_EQUALS(true, tokenlist.front()->isControlFlowKeyword()); @@ -112,7 +112,7 @@ class TestTokenList : public TestFixture { { const char code2[] = "_Generic"; // C11 keyword - const SimpleTokenList tokenlist(code2, false); // default settings use latest standard + const SimpleTokenList tokenlist(code2, Standards::Language::C); // default settings use latest standard ASSERT_EQUALS(true, tokenlist.front()->isKeyword()); } @@ -133,7 +133,7 @@ class TestTokenList : public TestFixture { { const char code2[] = "co_return"; // C++20 keyword - const SimpleTokenList tokenlist(code2, false); // default settings use latest standard + const SimpleTokenList tokenlist(code2, Standards::Language::C); // default settings use latest standard ASSERT_EQUALS(false, tokenlist.front()->isKeyword()); } From 24cb9cd6b2809f63a7a207da108f36d617bc10d7 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 5 Mar 2024 13:07:13 +0100 Subject: [PATCH 7/7] testrunner: added missing `TokenList::createTokens()` checks --- test/testlibrary.cpp | 10 +++++----- test/testsimplifytemplate.cpp | 12 ++++++++---- test/testsimplifytypedef.cpp | 8 +++++--- test/testtokenlist.cpp | 4 ++-- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index 01837ed1b16..09f2a3a5e53 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -162,7 +162,7 @@ class TestLibrary : public TestFixture { TokenList tokenList(&settings); std::istringstream istr("foo();"); // <- too few arguments, not library function - tokenList.createTokens(istr, Standards::Language::CPP); + ASSERT(tokenList.createTokens(istr, Standards::Language::CPP)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); @@ -186,7 +186,7 @@ class TestLibrary : public TestFixture { { TokenList tokenList(&settings); std::istringstream istr("foo();"); // <- too few arguments, not library function - tokenList.createTokens(istr, Standards::Language::CPP); + ASSERT(tokenList.createTokens(istr, Standards::Language::CPP)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); @@ -195,7 +195,7 @@ class TestLibrary : public TestFixture { { TokenList tokenList(&settings); std::istringstream istr("foo(a);"); // <- library function - tokenList.createTokens(istr, Standards::Language::CPP); + ASSERT(tokenList.createTokens(istr, Standards::Language::CPP)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); @@ -204,7 +204,7 @@ class TestLibrary : public TestFixture { { TokenList tokenList(&settings); std::istringstream istr("foo(a, b);"); // <- library function - tokenList.createTokens(istr, Standards::Language::CPP); + ASSERT(tokenList.createTokens(istr, Standards::Language::CPP)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); @@ -213,7 +213,7 @@ class TestLibrary : public TestFixture { { TokenList tokenList(&settings); std::istringstream istr("foo(a, b, c);"); // <- too much arguments, not library function - tokenList.createTokens(istr, Standards::Language::CPP); + ASSERT(tokenList.createTokens(istr, Standards::Language::CPP)); Token::createMutualLinks(tokenList.front()->next(), tokenList.back()->previous()); tokenList.createAst(); diff --git a/test/testsimplifytemplate.cpp b/test/testsimplifytemplate.cpp index fe35d5791bb..6a0415cc7dc 100644 --- a/test/testsimplifytemplate.cpp +++ b/test/testsimplifytemplate.cpp @@ -5290,7 +5290,8 @@ class TestSimplifyTemplate : public TestFixture { Tokenizer tokenizer(settings, this); std::istringstream istr(code); - tokenizer.list.createTokens(istr, "test.cpp"); + if (!tokenizer.list.createTokens(istr, "test.cpp")) + return false; tokenizer.createLinks(); tokenizer.splitTemplateRightAngleBrackets(false); @@ -5357,7 +5358,8 @@ class TestSimplifyTemplate : public TestFixture { Tokenizer tokenizer(settings, this); std::istringstream istr(code); - tokenizer.list.createTokens(istr, "test.cpp"); + if (!tokenizer.list.createTokens(istr, "test.cpp")) + return false; tokenizer.createLinks(); tokenizer.splitTemplateRightAngleBrackets(false); @@ -5427,7 +5429,8 @@ class TestSimplifyTemplate : public TestFixture { Tokenizer tokenizer(settings, this); std::istringstream istr(code); - tokenizer.list.createTokens(istr, "test.cpp"); + if (!tokenizer.list.createTokens(istr, "test.cpp")) + return false; tokenizer.createLinks(); tokenizer.splitTemplateRightAngleBrackets(false); @@ -5456,7 +5459,8 @@ class TestSimplifyTemplate : public TestFixture { Tokenizer tokenizer(settings, this); std::istringstream istr(code); - tokenizer.list.createTokens(istr, "test.cpp"); + if (!tokenizer.list.createTokens(istr, "test.cpp")) + return false; tokenizer.createLinks(); tokenizer.splitTemplateRightAngleBrackets(false); diff --git a/test/testsimplifytypedef.cpp b/test/testsimplifytypedef.cpp index 37c76de4eaa..88109a1816d 100644 --- a/test/testsimplifytypedef.cpp +++ b/test/testsimplifytypedef.cpp @@ -255,7 +255,8 @@ class TestSimplifyTypedef : public TestFixture { Tokenizer tokenizer(settings1, this); std::istringstream istr(code); - tokenizer.list.createTokens(istr, Standards::Language::CPP); + if (!tokenizer.list.createTokens(istr, Standards::Language::CPP)) + return ""; tokenizer.createLinks(); tokenizer.simplifyTypedef(); @@ -296,7 +297,8 @@ class TestSimplifyTypedef : public TestFixture { Tokenizer tokenizer(settings1, this); std::istringstream istr(code); - tokenizer.list.createTokens(istr, "file.c"); + if (!tokenizer.list.createTokens(istr, "file.c")) + return ""; tokenizer.createLinks(); tokenizer.simplifyTypedef(); try { @@ -4157,7 +4159,7 @@ class TestSimplifyTypedef : public TestFixture { Tokenizer tokenizer(settings1, this); std::istringstream istr(code); - tokenizer.list.createTokens(istr, "file.c"); + ASSERT(tokenizer.list.createTokens(istr, "file.c")); tokenizer.createLinks(); tokenizer.simplifyTypedef(); diff --git a/test/testtokenlist.cpp b/test/testtokenlist.cpp index a482fb306c0..9e92f2b70e7 100644 --- a/test/testtokenlist.cpp +++ b/test/testtokenlist.cpp @@ -121,7 +121,7 @@ class TestTokenList : public TestFixture { const Settings s = settingsBuilder().c(Standards::C89).build(); TokenList tokenlist(&s); std::istringstream istr(code2); - tokenlist.createTokens(istr, "a.c"); + ASSERT(tokenlist.createTokens(istr, "a.c")); ASSERT_EQUALS(false, tokenlist.front()->isKeyword()); } @@ -142,7 +142,7 @@ class TestTokenList : public TestFixture { const Settings s = settingsBuilder().cpp(Standards::CPP03).build(); TokenList tokenlist(&s); std::istringstream istr(code2); - tokenlist.createTokens(istr, "a.cpp"); + ASSERT(tokenlist.createTokens(istr, "a.cpp")); ASSERT_EQUALS(false, tokenlist.front()->isKeyword()); } }