Paul Bakker | 367dae4 | 2009-06-28 21:50:27 +0000 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | # |
| 3 | |
| 4 | use strict; |
| 5 | |
| 6 | my $suite_dir = shift or die "Missing suite directory"; |
| 7 | my $suite_name = shift or die "Missing suite name"; |
| 8 | my $test_file = $suite_name.".c"; |
| 9 | my $test_helper_file = $suite_dir."/helpers.function"; |
| 10 | my $test_case_file = $suite_dir."/".$suite_name.".function"; |
| 11 | my $test_data_file = $suite_dir."/".$suite_name.".data"; |
| 12 | |
| 13 | open(TEST_DATA, "$test_data_file") or die "Opening test cases '$test_data_file': $!"; |
| 14 | |
| 15 | my $line_separator = $/; |
| 16 | undef $/; |
| 17 | |
| 18 | open(TEST_HELPERS, "$test_helper_file") or die "Opening test helpers '$test_helper_file': $!"; |
| 19 | my $test_helpers = <TEST_HELPERS>; |
| 20 | close(TEST_HELPERS); |
| 21 | |
| 22 | open(TEST_CASES, "$test_case_file") or die "Opening test cases '$test_case_file': $!"; |
| 23 | my $test_cases = <TEST_CASES>; |
| 24 | close(TEST_CASES); |
| 25 | my ( $suite_header ) = $test_cases =~ /BEGIN_HEADER\n(.*?)\nEND_HEADER/s; |
| 26 | |
| 27 | $/ = $line_separator; |
| 28 | |
| 29 | open(TEST_FILE, ">$test_file") or die "Opening destination file '$test_file': $!"; |
| 30 | print TEST_FILE << "END"; |
| 31 | #include "fct.h" |
| 32 | $suite_header |
| 33 | |
| 34 | $test_helpers |
| 35 | |
| 36 | FCT_BGN() |
| 37 | { |
| 38 | FCT_SUITE_BGN($suite_name) |
| 39 | { |
| 40 | END |
| 41 | |
| 42 | while (my $line = <TEST_DATA>) |
| 43 | { |
| 44 | my $description = $line; |
| 45 | $line = <TEST_DATA>; |
| 46 | my $command_line = $line; |
| 47 | $line = <TEST_DATA>; |
| 48 | |
| 49 | my $test_name = $description; |
| 50 | $test_name =~ tr/A-Z \-/a-z__/; |
| 51 | $test_name =~ tr/a-z0-9_//cd; |
| 52 | |
| 53 | my ( $case, $var_value ) = $command_line =~ /^([\w_]+):(.*)$/; |
| 54 | |
| 55 | my ( $var_def, $case_code ) = $test_cases =~ /BEGIN_CASE\n$case:([^\n]*)\n(.*?)\nEND_CASE/s; |
| 56 | |
| 57 | my @var_def_arr = split(/:/, $var_def); |
| 58 | my @var_value_arr = split(/:/, $var_value); |
| 59 | |
| 60 | while (@var_def_arr) |
| 61 | { |
| 62 | my $def = shift @var_def_arr; |
| 63 | my $val = shift @var_value_arr; |
| 64 | |
| 65 | $case_code =~ s/\{$def\}/$val/g; |
| 66 | } |
| 67 | $case_code = "int ${test_name}_code_present = 0;\nTEST_ASSERT( ${test_name}_code_present == 1 );" if ($case_code =~ /^\s*$/); |
| 68 | |
| 69 | $case_code =~ s/TEST_ASSERT/fct_chk/g; |
| 70 | $case_code =~ s/TEST_EQUALS/fct_chk/g; |
| 71 | |
| 72 | $case_code =~ s/^/ /gm; |
| 73 | |
| 74 | |
| 75 | print TEST_FILE << "END"; |
| 76 | FCT_TEST_BGN($test_name) |
| 77 | $case_code |
| 78 | FCT_TEST_END(); |
| 79 | |
| 80 | END |
| 81 | } |
| 82 | |
| 83 | print TEST_FILE << "END"; |
| 84 | } |
| 85 | FCT_SUITE_END(); |
| 86 | } |
| 87 | FCT_END(); |
| 88 | END |
| 89 | |
| 90 | close(TEST_DATA); |
| 91 | close(TEST_FILE); |