Skip to content

Commit d3ab43b

Browse files
terryburtonclaude
andcommitted
tests: Hold each REQUIRES line to what its resource needs
A standalone program is made from an encoder by embedding the resources its REQUIRES line names, in order, before it (the build/standalone targets, libpostscriptbarcode's emit_required_resources), so a line that omits a resource, or lists one before something it needs, gives a program that fails when run, as MaxiCode's did for want of render. tests/test_requires checks every source file: each name listed is a resource, listed once and not itself; everything the body loads with findresource is listed; what a listed resource requires is listed too; and each listed resource comes after what it requires. It needs no build, so it runs first. Against the tree before the preceding fixes it reported the four resources those fixed, MaxiCode included. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01P51a75ubvkJAfhEwpZRwcn
1 parent 2c63165 commit d3ab43b

3 files changed

Lines changed: 87 additions & 1 deletion

File tree

‎tests/run_tests‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
# Barcode Writer in Pure PostScript
44
# https://bwipp.terryburton.co.uk
55
#
6-
# Copyright (c) 2004-2024 Terry Burton
6+
# Copyright (c) 2004-2026 Terry Burton
77

88
set -e
99
set -u
1010
set -o pipefail
1111

1212
TESTDIR=$(dirname "$0")
1313

14+
"$TESTDIR"/test_requires/run
1415
"$TESTDIR"/ps_tests/run
1516
"$TESTDIR"/test_monolithic/run
1617
"$TESTDIR"/test_monolithic_package/run
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/perl
2+
3+
# Barcode Writer in Pure PostScript
4+
# https://bwipp.terryburton.co.uk
5+
#
6+
# Copyright (c) 2026 Terry Burton
7+
#
8+
# Hold each resource's REQUIRES line to what the resource needs. A consumer
9+
# makes a standalone program from an encoder by embedding the resources its
10+
# REQUIRES line names, in that order, followed by the encoder (the
11+
# build/standalone targets, libpostscriptbarcode's emit_required_resources),
12+
# so the line must name every resource needed, however indirectly, and each
13+
# before the resources that need it.
14+
#
15+
# For every source file:
16+
# - each name listed is a resource, listed once, and not the resource itself
17+
# - each resource the body loads with findresource is listed
18+
# - the list is closed: what a listed resource requires is listed too
19+
# - a listed resource comes after everything it requires
20+
21+
use strict;
22+
use warnings;
23+
use lib 'build';
24+
use BWIPP qw(parse_source);
25+
26+
my (%requires, %loads);
27+
for my $file (sort glob 'src/*.ps.src') {
28+
open(my $fh, '<', $file) || die "Unable to open $file";
29+
my $src = join('', <$fh>);
30+
close($fh);
31+
my $res = parse_source($src);
32+
$requires{$res->{name}} = [ split ' ', $res->{requires} ];
33+
$loads{$res->{name}} = [ $res->{body} =~ m{/([\w-]+) dup /uk\.co\.terryburton\.bwipp findresource}g ];
34+
}
35+
36+
my @problems;
37+
for my $name (sort keys %requires) {
38+
my @req = @{ $requires{$name} };
39+
my %pos;
40+
for my $i (0 .. $#req) {
41+
my $r = $req[$i];
42+
push @problems, "$name: lists $r, which is not a resource" unless exists $requires{$r};
43+
push @problems, "$name: lists $r more than once" if exists $pos{$r};
44+
push @problems, "$name: lists itself" if $r eq $name;
45+
$pos{$r} //= $i;
46+
}
47+
for my $l (@{ $loads{$name} }) {
48+
push @problems, "$name: loads $l but does not list it" unless exists $pos{$l};
49+
}
50+
for my $r (grep { exists $requires{$_} } @req) {
51+
for my $rr (@{ $requires{$r} }) {
52+
if (!exists $pos{$rr}) {
53+
push @problems, "$name: lists $r, which requires $rr, but does not list $rr";
54+
} elsif ($pos{$rr} > $pos{$r}) {
55+
push @problems, "$name: lists $rr after $r, which requires it";
56+
}
57+
}
58+
}
59+
}
60+
61+
print "$_\n" for @problems;
62+
exit(@problems ? 1 : 0);

‎tests/test_requires/run‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Barcode Writer in Pure PostScript
4+
# https://bwipp.terryburton.co.uk
5+
#
6+
# Copyright (c) 2026 Terry Burton
7+
8+
set -e
9+
set -u
10+
set -o pipefail
11+
12+
TEST=$(dirname "$0")
13+
14+
echo -n "Running $TEST: "
15+
16+
if problems=$(perl "$TEST/check_requires.pl"); then
17+
echo "PASS"
18+
exit 0
19+
else
20+
echo "FAIL"
21+
echo "$problems"
22+
exit 1
23+
fi

0 commit comments

Comments
 (0)