#!/usr/bin/perl use warnings; use strict; # Script to convert *.ctest files into proper, complete *.c files. # *.ctest files are unittest C files using the check library, but only with the # tests per se. This script adds all the declarations and functions needed to # build a complete, compilable C file. my $input_file = shift || die "I need an input file\n"; my $basename = $input_file; $basename =~ s/\.ctest$//go; open F, $input_file or die "Can't open $input_file"; my $contents = join("", ); close F; # Make a list of all the defined tests my @test_list = (); foreach my $test_name ($contents =~ /START_TEST\((.+)\)/g) { push @test_list, $test_name; } # Some variables to interpolate in the final output my $suite_name = ucfirst($basename); my $test_add_lines = join("", map { "tcase_add_test (tc_core, $_);\n" } @test_list); print < #include #include #include const char thisname[]= "$basename"; const char printforhelp[]= ""; /* Original file contents follows */ $contents /* End original file contents */ Suite *test_suite (void) { Suite *s = suite_create ("$suite_name"); TCase *tc_core = tcase_create ("Core"); suite_add_tcase (s, tc_core); $test_add_lines return s; } int main (void) { int nf; Suite *s = test_suite (); SRunner *sr = srunner_create (s); srunner_run_all (sr, CK_VERBOSE); nf = srunner_ntests_failed (sr); srunner_free (sr); return EXIT_SUCCESS; } EOF