提交 bcf65153 编写于 作者: M Mark VanderVoord

Protect test runner generator against characters in strings that look like comments or functions

上级 915e3fb9
...@@ -91,7 +91,9 @@ class UnityTestRunnerGenerator ...@@ -91,7 +91,9 @@ class UnityTestRunnerGenerator
def find_tests(source) def find_tests(source)
tests_and_line_numbers = [] tests_and_line_numbers = []
source_scrubbed = source.gsub(/\/\/.*$/, '') # remove line comments source_scrubbed = source.clone
source_scrubbed = source_scrubbed.gsub(/"[^"]*"/, '') # remove things in strings
source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments
source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments
lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line lines = source_scrubbed.split(/(^\s*\#.*$) # Treat preprocessor directives as a logical line
| (;|\{|\}) /x) # Match ;, {, and } as end of lines | (;|\{|\}) /x) # Match ;, {, and } as end of lines
...@@ -329,7 +331,7 @@ class UnityTestRunnerGenerator ...@@ -329,7 +331,7 @@ class UnityTestRunnerGenerator
output.puts("#include #{inc.include?('<') ? inc : "\"#{inc.gsub('.h','')}.h\""}") output.puts("#include #{inc.include?('<') ? inc : "\"#{inc.gsub('.h','')}.h\""}")
end end
output.puts "\n" output.puts "\n"
tests.each do |test| tests.each do |test|
if ((test[:params].nil?) or (test[:params].empty?)) if ((test[:params].nil?) or (test[:params].empty?))
output.puts("void #{test[:test]}(void);") output.puts("void #{test[:test]}(void);")
else else
......
...@@ -35,6 +35,8 @@ extern void setUp(void); ...@@ -35,6 +35,8 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_TheFirstThingToTest(void); extern void test_TheFirstThingToTest(void);
extern void test_TheSecondThingToTest(void); extern void test_TheSecondThingToTest(void);
extern void test_TheThirdThingToTest(void);
extern void test_TheFourthThingToTest(void);
//=======Test Reset Option===== //=======Test Reset Option=====
...@@ -52,6 +54,8 @@ int main(void) ...@@ -52,6 +54,8 @@ int main(void)
UnityBegin("testdata/testsample.c"); UnityBegin("testdata/testsample.c");
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43);
RUN_TEST(test_TheThirdThingToTest, 53);
RUN_TEST(test_TheFourthThingToTest, 58);
return (UnityEnd()); return (UnityEnd());
} }
...@@ -31,6 +31,8 @@ extern void setUp(void); ...@@ -31,6 +31,8 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_TheFirstThingToTest(void); extern void test_TheFirstThingToTest(void);
extern void test_TheSecondThingToTest(void); extern void test_TheSecondThingToTest(void);
extern void test_TheThirdThingToTest(void);
extern void test_TheFourthThingToTest(void);
//=======Test Reset Option===== //=======Test Reset Option=====
...@@ -48,6 +50,8 @@ int main(void) ...@@ -48,6 +50,8 @@ int main(void)
UnityBegin("testdata/testsample.c"); UnityBegin("testdata/testsample.c");
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43);
RUN_TEST(test_TheThirdThingToTest, 53);
RUN_TEST(test_TheFourthThingToTest, 58);
return (UnityEnd()); return (UnityEnd());
} }
...@@ -29,6 +29,8 @@ extern void setUp(void); ...@@ -29,6 +29,8 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_TheFirstThingToTest(void); extern void test_TheFirstThingToTest(void);
extern void test_TheSecondThingToTest(void); extern void test_TheSecondThingToTest(void);
extern void test_TheThirdThingToTest(void);
extern void test_TheFourthThingToTest(void);
//=======Test Reset Option===== //=======Test Reset Option=====
...@@ -46,6 +48,8 @@ int main(void) ...@@ -46,6 +48,8 @@ int main(void)
UnityBegin("testdata/testsample.c"); UnityBegin("testdata/testsample.c");
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43);
RUN_TEST(test_TheThirdThingToTest, 53);
RUN_TEST(test_TheFourthThingToTest, 58);
return (UnityEnd()); return (UnityEnd());
} }
/* AUTOGENERATED FILE. DO NOT EDIT. */ /* AUTOGENERATED FILE. DO NOT EDIT. */
#ifndef __B_U_I_L_D__T_E_S_T_S_A_M_P_L_E___H_E_A_D_1__H_ #ifndef _TESTSAMPLE_HEAD1_H
#define __B_U_I_L_D__T_E_S_T_S_A_M_P_L_E___H_E_A_D_1__H_ #define _TESTSAMPLE_HEAD1_H
#include "unity.h"
#include "funky.h" #include "funky.h"
#include "stanky.h" #include "stanky.h"
#include <setjmp.h> #include <setjmp.h>
void test_TheFirstThingToTest(); void test_TheFirstThingToTest(void);
void test_TheSecondThingToTest(); void test_TheSecondThingToTest(void);
void test_TheThirdThingToTest(void);
void test_TheFourthThingToTest(void);
#endif #endif
/* AUTOGENERATED FILE. DO NOT EDIT. */ /* AUTOGENERATED FILE. DO NOT EDIT. */
#ifndef __B_U_I_L_D__T_E_S_T_S_A_M_P_L_E___M_O_C_K___H_E_A_D_1__H_ #ifndef _TESTSAMPLE_MOCK_HEAD1_H
#define __B_U_I_L_D__T_E_S_T_S_A_M_P_L_E___M_O_C_K___H_E_A_D_1__H_ #define _TESTSAMPLE_MOCK_HEAD1_H
#include "unity.h"
#include "cmock.h"
#include "funky.h" #include "funky.h"
#include <setjmp.h> #include <setjmp.h>
void test_TheFirstThingToTest(); void test_TheFirstThingToTest(void);
void test_TheSecondThingToTest(); void test_TheSecondThingToTest(void);
#endif #endif
...@@ -41,6 +41,8 @@ extern void setUp(void); ...@@ -41,6 +41,8 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_TheFirstThingToTest(void); extern void test_TheFirstThingToTest(void);
extern void test_TheSecondThingToTest(void); extern void test_TheSecondThingToTest(void);
extern void test_TheThirdThingToTest(void);
extern void test_TheFourthThingToTest(void);
//=======Test Reset Option===== //=======Test Reset Option=====
...@@ -58,6 +60,8 @@ int main(void) ...@@ -58,6 +60,8 @@ int main(void)
UnityBegin("testdata/testsample.c"); UnityBegin("testdata/testsample.c");
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43);
RUN_TEST(test_TheThirdThingToTest, 53);
RUN_TEST(test_TheFourthThingToTest, 58);
return (UnityEnd()); return (UnityEnd());
} }
...@@ -31,6 +31,8 @@ extern void setUp(void); ...@@ -31,6 +31,8 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_TheFirstThingToTest(void); extern void test_TheFirstThingToTest(void);
extern void test_TheSecondThingToTest(void); extern void test_TheSecondThingToTest(void);
extern void test_TheThirdThingToTest(void);
extern void test_TheFourthThingToTest(void);
//=======Suite Setup===== //=======Suite Setup=====
...@@ -61,6 +63,8 @@ int main(void) ...@@ -61,6 +63,8 @@ int main(void)
UnityBegin("testdata/testsample.c"); UnityBegin("testdata/testsample.c");
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43);
RUN_TEST(test_TheThirdThingToTest, 53);
RUN_TEST(test_TheFourthThingToTest, 58);
return suite_teardown(UnityEnd()); return suite_teardown(UnityEnd());
} }
...@@ -32,6 +32,8 @@ extern void setUp(void); ...@@ -32,6 +32,8 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_TheFirstThingToTest(void); extern void test_TheFirstThingToTest(void);
extern void test_TheSecondThingToTest(void); extern void test_TheSecondThingToTest(void);
extern void test_TheThirdThingToTest(void);
extern void test_TheFourthThingToTest(void);
//=======Test Reset Option===== //=======Test Reset Option=====
...@@ -49,6 +51,8 @@ int main(void) ...@@ -49,6 +51,8 @@ int main(void)
UnityBegin("testdata/testsample.c"); UnityBegin("testdata/testsample.c");
RUN_TEST(test_TheFirstThingToTest, 21, RUN_TEST_NO_ARGS); RUN_TEST(test_TheFirstThingToTest, 21, RUN_TEST_NO_ARGS);
RUN_TEST(test_TheSecondThingToTest, 43, RUN_TEST_NO_ARGS); RUN_TEST(test_TheSecondThingToTest, 43, RUN_TEST_NO_ARGS);
RUN_TEST(test_TheThirdThingToTest, 53, RUN_TEST_NO_ARGS);
RUN_TEST(test_TheFourthThingToTest, 58, RUN_TEST_NO_ARGS);
return (UnityEnd()); return (UnityEnd());
} }
...@@ -41,6 +41,8 @@ extern void setUp(void); ...@@ -41,6 +41,8 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_TheFirstThingToTest(void); extern void test_TheFirstThingToTest(void);
extern void test_TheSecondThingToTest(void); extern void test_TheSecondThingToTest(void);
extern void test_TheThirdThingToTest(void);
extern void test_TheFourthThingToTest(void);
//=======Test Reset Option===== //=======Test Reset Option=====
...@@ -58,6 +60,8 @@ int main(void) ...@@ -58,6 +60,8 @@ int main(void)
UnityBegin("testdata/testsample.c"); UnityBegin("testdata/testsample.c");
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43);
RUN_TEST(test_TheThirdThingToTest, 53);
RUN_TEST(test_TheFourthThingToTest, 58);
return (UnityEnd()); return (UnityEnd());
} }
...@@ -31,6 +31,8 @@ extern void setUp(void); ...@@ -31,6 +31,8 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_TheFirstThingToTest(void); extern void test_TheFirstThingToTest(void);
extern void test_TheSecondThingToTest(void); extern void test_TheSecondThingToTest(void);
extern void test_TheThirdThingToTest(void);
extern void test_TheFourthThingToTest(void);
//=======Suite Setup===== //=======Suite Setup=====
...@@ -61,6 +63,8 @@ int main(void) ...@@ -61,6 +63,8 @@ int main(void)
UnityBegin("testdata/testsample.c"); UnityBegin("testdata/testsample.c");
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43);
RUN_TEST(test_TheThirdThingToTest, 53);
RUN_TEST(test_TheFourthThingToTest, 58);
return suite_teardown(UnityEnd()); return suite_teardown(UnityEnd());
} }
...@@ -38,6 +38,8 @@ extern void setUp(void); ...@@ -38,6 +38,8 @@ extern void setUp(void);
extern void tearDown(void); extern void tearDown(void);
extern void test_TheFirstThingToTest(void); extern void test_TheFirstThingToTest(void);
extern void test_TheSecondThingToTest(void); extern void test_TheSecondThingToTest(void);
extern void test_TheThirdThingToTest(void);
extern void test_TheFourthThingToTest(void);
//=======Suite Setup===== //=======Suite Setup=====
...@@ -62,6 +64,8 @@ int main(void) ...@@ -62,6 +64,8 @@ int main(void)
UnityBegin("testdata/testsample.c"); UnityBegin("testdata/testsample.c");
RUN_TEST(test_TheFirstThingToTest, 21); RUN_TEST(test_TheFirstThingToTest, 21);
RUN_TEST(test_TheSecondThingToTest, 43); RUN_TEST(test_TheSecondThingToTest, 43);
RUN_TEST(test_TheThirdThingToTest, 53);
RUN_TEST(test_TheFourthThingToTest, 58);
return (UnityEnd()); return (UnityEnd());
} }
...@@ -35,15 +35,32 @@ void test_ShouldBeIgnored(void) ...@@ -35,15 +35,32 @@ void test_ShouldBeIgnored(void)
//void test_ShouldAlsoNotBeTested(void) //void test_ShouldAlsoNotBeTested(void)
//{ //{
// Call_An_Expect(); // Call_An_Expect();
// //
// CallAFunction(); // CallAFunction();
// test_CallAFunctionThatLooksLikeATest(); // test_CallAFunctionThatLooksLikeATest();
//} //}
void test_TheSecondThingToTest(void) void test_TheSecondThingToTest(void)
{ {
uint8_t* crazyString = "GET / HTTP/1.1\r\nHost: 127.0.0.1:8081\r\nConnection: keep-alive\r\nCache-Control: no-cache\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36\r\nPostman-Token: 768c7149-c3fb-f704-71a2-63918d9195b2\r\nAccept: */*\r\nAccept-Encoding: gzip, deflate, sdch\r\nAccept-Language: en-GB,en-US;q=0.8,en;q=0.6\r\n\r\n";
Call_An_Expect();
CallAFunction();
test_CallAFunctionThatLooksLikeATest();
}
void test_TheThirdThingToTest(void)
{
CallAFunction();
}
void test_TheFourthThingToTest(void)
{
uint8_t* anotherString = "GET / HTTP/1.1\r\nHost: 127.0.0.1:8081\r\nConnection: keep-alive\r\nCache-Control: no-cache\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36\r\nPostman-Token: 768c7149-c3fb-f704-71a2-63918d9195b2\r\nAccept: */*\r\nAccept-Encoding: gzip, deflate, sdch\r\nAccept-Language: en-GB,en-US;q=0.8,en;q=0.6\r\n\r\n";
Call_An_Expect(); Call_An_Expect();
CallAFunction(); CallAFunction();
test_CallAFunctionThatLooksLikeATest(); test_CallAFunctionThatLooksLikeATest();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册