Files
interpres/scripts/docs-drift.pl
T
2026-09-22 21:15:07 +02:00

48 lines
2.2 KiB
Perl
Executable File

#!/usr/bin/env perl
# Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
# SPDX-License-Identifier: MIT
# docs-drift compares the toml-test suite counts the documentation names with
# the run this repository produces now. A corpus change moves the counts, and
# README.md and docs/ARCHITECTURE.md quote them; this is the check that keeps
# the quotation honest. Builtins only, and the toml-test binary on PATH.
use v5.40;
my $out = qx{toml-test test -decoder=bin/interpres-decode -encoder='bin/interpres-decode --encode' -toml=1.1 2>&1};
die "docs-drift: toml-test failed to run; build the adapter first (just build)\n"
if !defined $out || $out =~ /not found|No such file/;
# A red run is a failure to answer, not a drift: the counts it prints describe
# a suite that did not pass, and sending the maintainer to correct counts that
# are correct would be the wrong diagnosis.
die "docs-drift: the toml-test run failed; fix the suite before comparing counts\n"
if $? != 0;
my %live;
for my $kind (qw(valid invalid encoder)) {
my ($passed) = $out =~ /\b$kind tests:\s+(\d+) passed/;
die "docs-drift: could not read the $kind count from the toml-test output\n"
unless defined $passed;
my ($failed) = $out =~ /\b$kind tests:\s+\d+ passed, (\d+) failed/;
die "docs-drift: the $kind run has $failed failures; fix the suite first\n"
if defined $failed && $failed != 0;
$live{$kind} = $passed;
}
print "docs-drift: the suite now stands at $live{valid} valid, $live{invalid} invalid and $live{encoder} encoder cases\n";
my $drift = 0;
for my $file ('README.md', 'docs/ARCHITECTURE.md') {
open(my $fh, '<', $file) or die "docs-drift: cannot read $file: $!\n";
my $text = do { local $/; <$fh> };
close($fh);
while ($text =~ /(\d+)\s+(valid|invalid|encoder)/g) {
my ($quoted, $kind) = ($1, $2);
if ($quoted != $live{$kind}) {
print "docs-drift: $file quotes $quoted $kind cases, the suite says $live{$kind}\n";
$drift = 1;
}
}
}
die "docs-drift: the documentation has drifted from the suite\n" if $drift;
print "docs-drift: the documentation matches the suite\n";