| 1 | module CppUTestToUnityUtils |
| 2 | |
| 3 | def convert_test_filename_to_unity_filename(testpath) |
| 4 | testpath.sub(/tests\/(.*)\.cpp/, "unity/\\1.c") |
| 5 | end |
| 6 | |
| 7 | def convert_test_filename_to_unity_testrunner_filename(testpath) |
| 8 | testpath.sub(/tests\/(.*)\.cpp/, "unity/\\1_runner.c") |
| 9 | end |
| 10 | |
| 11 | def convert_one_liners(line, group) |
| 12 | line.sub!(/#include "CppUTest\/TestHarness.h\"/, "#include \"unity_fixture.h\"" ) |
| 13 | line.sub!(/FAIL\(/, 'TEST_FAIL(') |
| 14 | line.sub!(/CHECK\(/, "TEST_ASSERT_TRUE(") |
| 15 | line.sub!(/CHECK_TRUE\(/, "TEST_ASSERT_TRUE(") |
| 16 | line.sub!(/CHECK_FALSE\(/, "TEST_ASSERT_FALSE(") |
| 17 | line.sub!(/LONGS_EQUAL\(/, "TEST_ASSERT_EQUAL(") |
| 18 | line.sub!(/BYTES_EQUAL\(/, "TEST_ASSERT_EQUAL_HEX8(") |
| 19 | line.sub!(/STRCMP_EQUAL\(/, "TEST_ASSERT_EQUAL_STRING(") |
| 20 | line.sub!(/DOUBLES_EQUAL\(/, "TEST_ASSERT_FLOAT_WITHIN(") |
| 21 | line.sub!(/ POINTERS_EQUAL\(/, " TEST_ASSERT_POINTERS_EQUAL(") |
| 22 | line.sub!(/CHECK_EQUAL\(true,/, "TEST_ASSERT_TRUE(") |
| 23 | line.sub!(/CHECK_EQUAL\(false,/, "TEST_ASSERT_FALSE(") |
| 24 | line.sub!(/CHECK_EQUAL\(/, "TEST_ASSERT_EQUAL(") |
| 25 | #line.sub!(/static void setup\(/, "TEST_SETUP(" + group) |
| 26 | #line.sub!(/static void teardown\(/, "TEST_TEAR_DOWN(" + group) |
| 27 | end |
| 28 | |
| 29 | def convert_setup(lines, group) |
| 30 | lines.each do | line | |
| 31 | if line.sub!(/static void setup\(/, "TEST_SETUP(" + group) |
| 32 | return |
| 33 | end |
| 34 | end |
| 35 | end |
| 36 | |
| 37 | def convert_teardown(lines, group) |
| 38 | lines.each do | line | |
| 39 | if line.sub!(/static void teardown\(/, "TEST_TEAR_DOWN(" + group) |
| 40 | return |
| 41 | end |
| 42 | end |
| 43 | end |
| 44 | |
| 45 | def convert_macros(lines, groups) |
| 46 | groups.each do | group | |
| 47 | lines.each do | line | |
| 48 | convert_one_liners(line, group) |
| 49 | end |
| 50 | convert_setup(lines, group) |
| 51 | convert_teardown(lines, group) |
| 52 | end |
| 53 | end |
| 54 | |
| 55 | def get_test_group(lines) |
| 56 | @test_group = "None" |
| 57 | lines.each do | line | |
| 58 | if /TEST_GROUP/ =~ line |
| 59 | @test_group = line.split(/[()]/)[1] |
| 60 | end |
nothing calls this directly
no outgoing calls
no test coverage detected