From 498bd155b08f5602153168e5fec086f4c1ec1e0c Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 7 Aug 2023 19:45:03 +0200 Subject: [PATCH] testrunner: adjusted several `Tokenizer` creations --- test/testlibrary.cpp | 12 ++++++------ test/testtokenize.cpp | 24 ++++++++++++------------ test/testtokenrange.cpp | 4 ++-- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/test/testlibrary.cpp b/test/testlibrary.cpp index ff444a7a57c9..d64c0f143a0d 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -568,7 +568,7 @@ class TestLibrary : public TestFixture { } } - void function_method() const { + void function_method() { constexpr char xmldata[] = "\n" "\n" " \n" @@ -581,21 +581,21 @@ class TestLibrary : public TestFixture { ASSERT_EQUALS(library.functions.size(), 1U); { - Tokenizer tokenizer(settings, nullptr); + Tokenizer tokenizer(settings, this); std::istringstream istr("CString str; str.Format();"); ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format"))); } { - Tokenizer tokenizer(settings, nullptr); + Tokenizer tokenizer(settings, this); std::istringstream istr("HardDrive hd; hd.Format();"); ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(!library.isnotnoreturn(Token::findsimplematch(tokenizer.tokens(), "Format"))); } } - void function_baseClassMethod() const { + void function_baseClassMethod() { constexpr char xmldata[] = "\n" "\n" " \n" @@ -607,14 +607,14 @@ class TestLibrary : public TestFixture { ASSERT(loadxmldata(library, xmldata, sizeof(xmldata))); { - Tokenizer tokenizer(settings, nullptr); + Tokenizer tokenizer(settings, this); std::istringstream istr("struct X : public Base { void dostuff() { f(0); } };"); ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1)); } { - Tokenizer tokenizer(settings, nullptr); + Tokenizer tokenizer(settings, this); std::istringstream istr("struct X : public Base { void dostuff() { f(1,2); } };"); ASSERT(tokenizer.tokenize(istr, "test.cpp")); ASSERT(!library.isnullargbad(Token::findsimplematch(tokenizer.tokens(), "f"),1)); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 94e273d72578..49202ecda135 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5948,9 +5948,9 @@ class TestTokenizer : public TestFixture { Z3 }; - std::string testAst(const char code[], AstStyle style = AstStyle::Simple) const { + std::string testAst(const char code[], AstStyle style = AstStyle::Simple) { // tokenize given code.. - Tokenizer tokenizer(settings0, nullptr); + Tokenizer tokenizer(settings0, this); std::istringstream istr(code); if (!tokenizer.list.createTokens(istr,"test.cpp")) return "ERROR"; @@ -5997,7 +5997,7 @@ class TestTokenizer : public TestFixture { return ret; } - void astexpr() const { // simple expressions with arithmetical ops + void astexpr() { // simple expressions with arithmetical ops ASSERT_EQUALS("12+3+", testAst("1+2+3")); ASSERT_EQUALS("12*3+", testAst("1*2+3")); ASSERT_EQUALS("123*+", testAst("1+2*3")); @@ -6259,7 +6259,7 @@ class TestTokenizer : public TestFixture { ASSERT_NO_THROW(tokenizeAndStringify(code)); } - void astnewdelete() const { + void astnewdelete() { ASSERT_EQUALS("aintnew=", testAst("a = new int;")); ASSERT_EQUALS("aint4[new=", testAst("a = new int[4];")); ASSERT_EQUALS("aFoobar(new=", testAst("a = new Foo(bar);")); @@ -6483,7 +6483,7 @@ class TestTokenizer : public TestFixture { "}\n")); } - void astbrackets() const { // [] + void astbrackets() { // [] ASSERT_EQUALS("a23+[4+", testAst("a[2+3]+4")); ASSERT_EQUALS("a1[0[", testAst("a[1][0]")); ASSERT_EQUALS("ab0[=", testAst("a=(b)[0];")); @@ -6491,7 +6491,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("ab0[1[=", testAst("a=b[0][1];")); } - void astvardecl() const { + void astvardecl() { // Variable declaration ASSERT_EQUALS("a1[\"\"=", testAst("char a[1]=\"\";")); ASSERT_EQUALS("charp*(3[char5[3[new=", testAst("char (*p)[3] = new char[5][3];")); @@ -6529,7 +6529,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("", testAst("void f(bool& var){}")); } - void astunaryop() const { // unary operators + void astunaryop() { // unary operators ASSERT_EQUALS("1a--+", testAst("1 + --a")); ASSERT_EQUALS("1a--+", testAst("1 + a--")); ASSERT_EQUALS("ab+!", testAst("!(a+b)")); @@ -6555,7 +6555,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("int0{1&return", testAst("int g() { return int{ 0 } & 1; }")); } - void astfunction() const { // function calls + void astfunction() { // function calls ASSERT_EQUALS("1f(+2+", testAst("1+f()+2")); ASSERT_EQUALS("1f2(+3+", testAst("1+f(2)+3")); ASSERT_EQUALS("1f23,(+4+", testAst("1+f(2,3)+4")); @@ -6619,7 +6619,7 @@ class TestTokenizer : public TestFixture { "}\n")); } - void astcast() const { + void astcast() { ASSERT_EQUALS("ac&(=", testAst("a = (long)&c;")); ASSERT_EQUALS("ac*(=", testAst("a = (Foo*)*c;")); ASSERT_EQUALS("ac-(=", testAst("a = (long)-c;")); @@ -6805,14 +6805,14 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("sf.{(i[{={", testAst("void g(int i) { S s{ .f = { [i]() {} } }; }")); } - void astcase() const { + void astcase() { ASSERT_EQUALS("0case", testAst("case 0:")); ASSERT_EQUALS("12+case", testAst("case 1+2:")); ASSERT_EQUALS("xyz:?case", testAst("case (x?y:z):")); ASSERT_EQUALS("switchx( 1case y++ 2case", testAst("switch(x){case 1:{++y;break;case 2:break;}}")); } - void astrefqualifier() const { + void astrefqualifier() { ASSERT_EQUALS("b(int.", testAst("class a { auto b() -> int&; };")); ASSERT_EQUALS("b(int.", testAst("class a { auto b() -> int&&; };")); ASSERT_EQUALS("b(", testAst("class a { void b() &&; };")); @@ -6823,7 +6823,7 @@ class TestTokenizer : public TestFixture { //Verify that returning a newly constructed object generates the correct AST even when the class name is scoped //Addresses https://trac.cppcheck.net/ticket/9700 - void astnewscoped() const { + void astnewscoped() { ASSERT_EQUALS("(return (new A))", testAst("return new A;", AstStyle::Z3)); ASSERT_EQUALS("(return (new (( A)))", testAst("return new A();", AstStyle::Z3)); ASSERT_EQUALS("(return (new (( A true)))", testAst("return new A(true);", AstStyle::Z3)); diff --git a/test/testtokenrange.cpp b/test/testtokenrange.cpp index dee15b918c64..51393e46331f 100644 --- a/test/testtokenrange.cpp +++ b/test/testtokenrange.cpp @@ -100,8 +100,8 @@ class TestTokenRange : public TestFixture { ASSERT_EQUALS("", testTokenRange(ConstTokenRange{ start, end }, start, end)); } - void scopeExample() const { - Tokenizer tokenizer(settingsDefault); + void scopeExample() { + Tokenizer tokenizer(settingsDefault, this); std::istringstream sample("void a(){} void main(){ if(true){a();} }"); ASSERT(tokenizer.tokenize(sample, "test.cpp"));