mirror of
https://github.com/qpdf/qpdf.git
synced 2024-10-31 19:02:30 +00:00
62bf296a9c
Prevent my future self or other contributors from using assert in tests and then having that assert not do anything because of the NDEBUG macro.
63 lines
1.4 KiB
Perl
Executable File
63 lines
1.4 KiB
Perl
Executable File
#!/usr/bin/env perl
|
|
require 5.008;
|
|
use warnings;
|
|
use strict;
|
|
use File::Basename;
|
|
|
|
my $whoami = basename($0);
|
|
chdir(dirname($0)) or die;
|
|
|
|
my $errors = 0;
|
|
foreach my $file (glob('*/*.c'), glob('*/*.cc'),
|
|
glob('*/*/*.h'), glob('*/*/*.hh'))
|
|
{
|
|
my $assert_test = 0;
|
|
if ($file =~ m,^libqpdf/qpdf/assert_,)
|
|
{
|
|
next;
|
|
}
|
|
open(F, "<$file") or die;
|
|
my $first_include = undef;
|
|
while (<F>)
|
|
{
|
|
if (m,^\s*#\s*include <qpdf/assert_(.*?).h>,)
|
|
{
|
|
if ($1 eq 'test')
|
|
{
|
|
$assert_test = 1;
|
|
}
|
|
if (defined $first_include)
|
|
{
|
|
error("$file:$.: qpdf/assert header must be first");
|
|
}
|
|
}
|
|
if (m,^\s*#\s*include <(.*?)>,)
|
|
{
|
|
my $header = $1;
|
|
if (($header eq 'cassert') || ($header eq 'assert.h'))
|
|
{
|
|
error("$file:$.: assert.h and cassert are not allowed --" .
|
|
" use one of the qpdf/assert_ files instead");
|
|
}
|
|
$first_include = 1;
|
|
}
|
|
if ((! $assert_test) && (m/assert\(/))
|
|
{
|
|
error("$file:$.: call qpdf_assert_debug instead of assert");
|
|
}
|
|
}
|
|
close(F);
|
|
}
|
|
if ($errors)
|
|
{
|
|
die "$whoami: errors detected\n";
|
|
}
|
|
print "$whoami: no incorrect use of assert found\n";
|
|
|
|
sub error
|
|
{
|
|
my $msg = shift;
|
|
warn $msg, "\n";
|
|
$errors = 1;
|
|
}
|