blob: f712395ce0ab1ef7e47a2f8652220e73f6ea65a0 [file] [log] [blame]
Paul Bakker367dae42009-06-28 21:50:27 +00001#!/usr/bin/perl
2#
3
4use strict;
5
6my $suite_dir = shift or die "Missing suite directory";
7my $suite_name = shift or die "Missing suite name";
8my $test_file = $suite_name.".c";
9my $test_helper_file = $suite_dir."/helpers.function";
10my $test_case_file = $suite_dir."/".$suite_name.".function";
11my $test_data_file = $suite_dir."/".$suite_name.".data";
12
13open(TEST_DATA, "$test_data_file") or die "Opening test cases '$test_data_file': $!";
14
15my $line_separator = $/;
16undef $/;
17
18open(TEST_HELPERS, "$test_helper_file") or die "Opening test helpers '$test_helper_file': $!";
19my $test_helpers = <TEST_HELPERS>;
20close(TEST_HELPERS);
21
22open(TEST_CASES, "$test_case_file") or die "Opening test cases '$test_case_file': $!";
23my $test_cases = <TEST_CASES>;
24close(TEST_CASES);
25my ( $suite_header ) = $test_cases =~ /BEGIN_HEADER\n(.*?)\nEND_HEADER/s;
26
27$/ = $line_separator;
28
29open(TEST_FILE, ">$test_file") or die "Opening destination file '$test_file': $!";
30print TEST_FILE << "END";
31#include "fct.h"
32$suite_header
33
34$test_helpers
35
36FCT_BGN()
37{
38 FCT_SUITE_BGN($suite_name)
39 {
40END
41
42while (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
Paul Bakker7d8a1002009-07-10 22:36:06 +000053 # Carve the case name and variable values
54 #
Paul Bakker367dae42009-06-28 21:50:27 +000055 my ( $case, $var_value ) = $command_line =~ /^([\w_]+):(.*)$/;
56
Paul Bakker7d8a1002009-07-10 22:36:06 +000057 # Escape the escaped colons (Not really escaped now)
58 #
59 $var_value =~ s/\\:/{colon_sign}/g;
60
61 # Carve the case and variable definition
62 #
Paul Bakker367dae42009-06-28 21:50:27 +000063 my ( $var_def, $case_code ) = $test_cases =~ /BEGIN_CASE\n$case:([^\n]*)\n(.*?)\nEND_CASE/s;
64
65 my @var_def_arr = split(/:/, $var_def);
66 my @var_value_arr = split(/:/, $var_value);
67
68 while (@var_def_arr)
69 {
70 my $def = shift @var_def_arr;
71 my $val = shift @var_value_arr;
72
73 $case_code =~ s/\{$def\}/$val/g;
74 }
75 $case_code = "int ${test_name}_code_present = 0;\nTEST_ASSERT( ${test_name}_code_present == 1 );" if ($case_code =~ /^\s*$/);
76
Paul Bakker7d8a1002009-07-10 22:36:06 +000077 $case_code =~ s/{colon_sign}/:/g;
Paul Bakker367dae42009-06-28 21:50:27 +000078 $case_code =~ s/TEST_ASSERT/fct_chk/g;
79 $case_code =~ s/TEST_EQUALS/fct_chk/g;
80
81 $case_code =~ s/^/ /gm;
82
83
84 print TEST_FILE << "END";
85 FCT_TEST_BGN($test_name)
86$case_code
87 FCT_TEST_END();
88
89END
90}
91
92print TEST_FILE << "END";
93 }
94 FCT_SUITE_END();
95}
96FCT_END();
97END
98
99close(TEST_DATA);
100close(TEST_FILE);