package TestCUnittests; use base qw(AbstractDpkgTestCase); use File::Basename; sub new { my $self = shift->SUPER::new(@_); $self->{unittests_path} = 'c-unittests'; $self->{source_test_regex} = qr/\.c(test)?$/; # Make sure the compiled unittests are up-to-date my $r = system("make -C '$self->{unittests_path}' &>/dev/null"); $self->assert_equals(0, $r, "Compile C check unittests - try \"make -C '$self->{unittests_path}'\" if this test fails\n"); return $self; } # Runs a "check" C unittest and makes asserts for it sub wrap_check_unittest_output { my ($self, $check_unittest) = @_; my $output = `$check_unittest`; my ($file, $line, $result, $suite_name, $test_name, $comment); foreach my $output_line (split "\n", $output) { my @fields = split(/:/, $output_line); next if scalar @fields != 6; ($file, $line, $result, $suite_name, $test_name, $comment) = @fields; $self->assert_equals('P', $result, basename($check_unittest).":$line: $comment"); } } # Find all the C check unittests and executes them, wrapping their output to # "convert" to Test::Unit output format sub test_c_unittests { my $self = shift; my $path = $self->{unittests_path}; opendir TEST_DIR, $path; foreach my $input_file (readdir TEST_DIR) { next if $input_file =~ /^\./; next unless $input_file =~ $self->{source_test_regex}; my $unittest = "$path/$input_file"; $unittest =~ s/$self->{source_test_regex}//o; $self->wrap_check_unittest_output($unittest); } closedir TEST_DIR; } 1;