From 1d0788aca7d922feea38e0f8a68e6553afd0c1ca 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 16caaa4f69cf..a1fe3f753442 100644 --- a/test/testlibrary.cpp +++ b/test/testlibrary.cpp @@ -567,7 +567,7 @@ class TestLibrary : public TestFixture { } } - void function_method() const { + void function_method() { const char xmldata[] = "\n" "\n" " \n" @@ -580,21 +580,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() { const char xmldata[] = "\n" "\n" " \n" @@ -606,14 +606,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 2e0972d07b88..6ec8ef6f403b 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -5904,9 +5904,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 tokenList(&settings0, nullptr); + Tokenizer tokenList(&settings0, this); std::istringstream istr(code); if (!tokenList.list.createTokens(istr,"test.cpp")) return "ERROR"; @@ -5953,7 +5953,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")); @@ -6214,7 +6214,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);")); @@ -6438,7 +6438,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];")); @@ -6446,7 +6446,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];")); @@ -6480,7 +6480,7 @@ class TestTokenizer : public TestFixture { ASSERT_EQUALS("i(j=", testAst("(int&)(i) = j;")); } - 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)")); @@ -6506,7 +6506,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")); @@ -6569,7 +6569,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;")); @@ -6742,14 +6742,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() &&; };")); @@ -6760,7 +6760,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 2598c832847d..61a9a842b858 100644 --- a/test/testtokenrange.cpp +++ b/test/testtokenrange.cpp @@ -100,9 +100,9 @@ class TestTokenRange : public TestFixture { ASSERT_EQUALS("", testTokenRange(ConstTokenRange{ start, end }, start, end)); } - void scopeExample() const { + void scopeExample() { const Settings settings; - Tokenizer tokenizer{ &settings, nullptr }; + Tokenizer tokenizer{ &settings, this }; std::istringstream sample("void a(){} void main(){ if(true){a();} }"); ASSERT(tokenizer.tokenize(sample, "test.cpp"));