From 39bfc7e2eb20d84defa03ae9f519cd28d7329415 Mon Sep 17 00:00:00 2001 From: Andrew <49104171+carsonak@users.noreply.github.com> Date: Wed, 11 Dec 2024 15:06:00 +0300 Subject: [PATCH] Fixed logic bug in tauShouldDecomposeMacro --- tau/tau.h | 2 +- test/InternalTests/test.c | 36 ++++++++++++++++++++++++------------ test/InternalTests/test.cpp | 36 ++++++++++++++++++++++++------------ 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/tau/tau.h b/tau/tau.h index cc3caa2..3d35199 100644 --- a/tau/tau.h +++ b/tau/tau.h @@ -449,7 +449,7 @@ static inline int tauShouldDecomposeMacro(const char* const actual, const char* // number constants since according to the standard identifiers cannot begin with digits. // This accounts for number constants such as -44, 0xFA, 400000000UL, 0b0010(c++) and 1'000'123(c++). if(!isStringCmp) { - if (!tauIsNumberConstant(*actual)) + if (!tauIsNumberConstant(*actual) || !tauIsNumberConstant(*expected)) return 1; } // Inside a string comparison, we search for common expression tokens like the following: diff --git a/test/InternalTests/test.c b/test/InternalTests/test.c index 0b2d164..dcbdafe 100644 --- a/test/InternalTests/test.c +++ b/test/InternalTests/test.c @@ -261,66 +261,77 @@ TEST_F(MyTestF, c2) { TEST(test_tauShouldDecomposeMacro_numbers, decimals) { CHECK_EQ(123456789, 123456789); - CHECK_EQ(tauShouldDecomposeMacro("123456789", "123456789", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "123456789", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("123456789", "1", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, decimals_with_sign) { CHECK_EQ(-123456789, -123456789); - CHECK_EQ(tauShouldDecomposeMacro("-123456789", "-123456789", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("-123456789", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "-123456789", 0), 0); CHECK_EQ(+123456789, +123456789); - CHECK_EQ(tauShouldDecomposeMacro("+123456789", "+123456789", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("+123456789", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "+123456789", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, decimals_with_suffix) { CHECK_EQ(987654321012345678UL, 987654321012345678UL); - CHECK_EQ(tauShouldDecomposeMacro("987654321012345678UL", "987654321012345678UL", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("987654321012345678UL", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "987654321012345678UL", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, hexadecimals) { CHECK_EQ(0xFFFFFFFF, 0xFFFFFFFF); - CHECK_EQ(tauShouldDecomposeMacro("0xFFFFFFFF", "0xFFFFFFFF", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("0xFFFFFFFF", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "0xFFFFFFFF", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, octals) { CHECK_EQ(007, 007); - CHECK_EQ(tauShouldDecomposeMacro("007", "007", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "007", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("007", "1", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, floats) { CHECK_EQ(420.69, 420.69); - CHECK_EQ(tauShouldDecomposeMacro("420.69", "420.69", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("420.69", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "420.69", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, floats_only_fractional_part) { CHECK_EQ(.69, .69); - CHECK_EQ(tauShouldDecomposeMacro(".69", ".69", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro(".69", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", ".69", 0), 0); } TEST(test_tauShouldDecomposeMacro_c_identifiers, letters) { const int myVar = 1; CHECK_EQ(myVar, myVar); - CHECK_EQ(tauShouldDecomposeMacro("myVar", "myVar", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("myVar", "a", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("a", "myVar", 0), 1); } TEST(test_tauShouldDecomposeMacro_c_identifiers, letters_and_numbers) { const int v1 = 1; CHECK_EQ(v1, v1); - CHECK_EQ(tauShouldDecomposeMacro("v1", "v1", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("v1", "a", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("a", "v1", 0), 1); } TEST(test_tauShouldDecomposeMacro_c_identifiers, underscores_and_letters) { const int __myVar__ = 1; CHECK_EQ(__myVar__, __myVar__); - CHECK_EQ(tauShouldDecomposeMacro("__myVar__", "__myVar__", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("__myVar__", "a", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("a", "__myVar__", 0), 1); } TEST(test_tauShouldDecomposeMacro_c_identifiers, mixed) @@ -328,5 +339,6 @@ TEST(test_tauShouldDecomposeMacro_c_identifiers, mixed) #define MYMACRO_2024dec10 1 CHECK_EQ(MYMACRO_2024dec10, MYMACRO_2024dec10); #undef MYMACRO_2024dec10 - CHECK_EQ(tauShouldDecomposeMacro("MYMACRO_2024dec10", "MYMACRO_2024dec10", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("MYMACRO_2024dec10", "a", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("a", "MYMACRO_2024dec10", 0), 1); } diff --git a/test/InternalTests/test.cpp b/test/InternalTests/test.cpp index 3197be4..3e4e5cd 100644 --- a/test/InternalTests/test.cpp +++ b/test/InternalTests/test.cpp @@ -398,66 +398,77 @@ TEST_F(Stack, TestStackDetails) { TEST(test_tauShouldDecomposeMacro_numbers, decimals) { CHECK_EQ(123456789, 123456789); - CHECK_EQ(tauShouldDecomposeMacro("123456789", "123456789", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "123456789", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("123456789", "1", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, decimals_with_sign) { CHECK_EQ(-123456789, -123456789); - CHECK_EQ(tauShouldDecomposeMacro("-123456789", "-123456789", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("-123456789", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "-123456789", 0), 0); CHECK_EQ(+123456789, +123456789); - CHECK_EQ(tauShouldDecomposeMacro("+123456789", "+123456789", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("+123456789", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "+123456789", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, decimals_with_suffix) { CHECK_EQ(987654321012345678UL, 987654321012345678UL); - CHECK_EQ(tauShouldDecomposeMacro("987654321012345678UL", "987654321012345678UL", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("987654321012345678UL", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "987654321012345678UL", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, hexadecimals) { CHECK_EQ(0xFFFFFFFF, 0xFFFFFFFF); - CHECK_EQ(tauShouldDecomposeMacro("0xFFFFFFFF", "0xFFFFFFFF", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("0xFFFFFFFF", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "0xFFFFFFFF", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, octals) { CHECK_EQ(007, 007); - CHECK_EQ(tauShouldDecomposeMacro("007", "007", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "007", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("007", "1", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, floats) { CHECK_EQ(420.69, 420.69); - CHECK_EQ(tauShouldDecomposeMacro("420.69", "420.69", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("420.69", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", "420.69", 0), 0); } TEST(test_tauShouldDecomposeMacro_numbers, floats_only_fractional_part) { CHECK_EQ(.69, .69); - CHECK_EQ(tauShouldDecomposeMacro(".69", ".69", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro(".69", "1", 0), 0); + CHECK_EQ(tauShouldDecomposeMacro("1", ".69", 0), 0); } TEST(test_tauShouldDecomposeMacro_c_identifiers, letters) { const int myVar = 1; CHECK_EQ(myVar, myVar); - CHECK_EQ(tauShouldDecomposeMacro("myVar", "myVar", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("myVar", "a", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("a", "myVar", 0), 1); } TEST(test_tauShouldDecomposeMacro_c_identifiers, letters_and_numbers) { const int v1 = 1; CHECK_EQ(v1, v1); - CHECK_EQ(tauShouldDecomposeMacro("v1", "v1", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("v1", "a", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("a", "v1", 0), 1); } TEST(test_tauShouldDecomposeMacro_c_identifiers, underscores_and_letters) { const int __myVar__ = 1; CHECK_EQ(__myVar__, __myVar__); - CHECK_EQ(tauShouldDecomposeMacro("__myVar__", "__myVar__", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("__myVar__", "a", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("a", "__myVar__", 0), 1); } TEST(test_tauShouldDecomposeMacro_c_identifiers, mixed) @@ -465,5 +476,6 @@ TEST(test_tauShouldDecomposeMacro_c_identifiers, mixed) #define MYMACRO_2024dec10 1 CHECK_EQ(MYMACRO_2024dec10, MYMACRO_2024dec10); #undef MYMACRO_2024dec10 - CHECK_EQ(tauShouldDecomposeMacro("MYMACRO_2024dec10", "MYMACRO_2024dec10", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("MYMACRO_2024dec10", "a", 0), 1); + CHECK_EQ(tauShouldDecomposeMacro("a", "MYMACRO_2024dec10", 0), 1); }