@@ -1334,6 +1334,55 @@ def verify_number(expected, expression, output)
13341334 $generate_test_runner_tests += 1
13351335end
13361336
1337+ should 'FindTestsLineNumbersWhenNameStartsTheLine' do
1338+ # The return type may sit on its own line, leaving the test name at column 0.
1339+ # The line search must still find the definition (and must not scan to the end
1340+ # of the file for every test, which is what made large files slow).
1341+ source = "#include \" unity.h\" \n " \
1342+ "\n " \
1343+ "void\n " \
1344+ "test_FirstAtColumnZero(void)\n " \
1345+ "{\n " \
1346+ "}\n " \
1347+ "\n " \
1348+ "void\n " \
1349+ "test_SecondAtColumnZero(void)\n " \
1350+ "{\n " \
1351+ "}\n "
1352+ found = UnityTestRunnerGenerator . new ( { } ) . find_tests ( source ) . map { |t | [ t [ :test ] , t [ :line_number ] ] }
1353+ expected = [ [ 'test_FirstAtColumnZero' , 4 ] , [ 'test_SecondAtColumnZero' , 9 ] ]
1354+ if found == expected
1355+ report 'Runner_FindTestsLineNumbersWhenNameStartsTheLine:PASS'
1356+ else
1357+ report " FAIL: expected #{ expected . inspect } , got #{ found . inspect } "
1358+ report 'Runner_FindTestsLineNumbersWhenNameStartsTheLine:FAIL'
1359+ $generate_test_runner_failures += 1
1360+ end
1361+ $generate_test_runner_tests += 1
1362+ end
1363+
1364+ should 'FindTestsLineNumbersWhenOneNameIsAPrefixOfAnother' do
1365+ # Issue #288: test_my_function must not be located inside
1366+ # test_my_function_invalid_behavior, which is defined first.
1367+ source = "void test_my_function_invalid_behavior(void)\n " \
1368+ "{\n " \
1369+ "}\n " \
1370+ "\n " \
1371+ "void test_my_function(void)\n " \
1372+ "{\n " \
1373+ "}\n "
1374+ found = UnityTestRunnerGenerator . new ( { } ) . find_tests ( source ) . map { |t | [ t [ :test ] , t [ :line_number ] ] }
1375+ expected = [ [ 'test_my_function_invalid_behavior' , 1 ] , [ 'test_my_function' , 5 ] ]
1376+ if found == expected
1377+ report 'Runner_FindTestsLineNumbersWhenOneNameIsAPrefixOfAnother:PASS'
1378+ else
1379+ report " FAIL: expected #{ expected . inspect } , got #{ found . inspect } "
1380+ report 'Runner_FindTestsLineNumbersWhenOneNameIsAPrefixOfAnother:FAIL'
1381+ $generate_test_runner_failures += 1
1382+ end
1383+ $generate_test_runner_tests += 1
1384+ end
1385+
13371386RUNNER_TESTS . each do |testset |
13381387 basename = File . basename ( testset [ :testfile ] , C_EXTENSION )
13391388 testset_name = "Runner_#{ basename } _#{ testset [ :name ] } "
0 commit comments