From 0e33622304c9c3b49f41c6d81c61176b8f248a7f Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 20 Dec 2020 16:12:43 +0100 Subject: add umlauf sanity checker --- bin/sanity-check | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 bin/sanity-check (limited to 'bin') diff --git a/bin/sanity-check b/bin/sanity-check new file mode 100755 index 0000000..3e6957e --- /dev/null +++ b/bin/sanity-check @@ -0,0 +1,51 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use 5.020; +use utf8; + +use File::Slurp qw(read_file); +use JSON; + +sub show_usage { + my ($exit_code) = @_; + + say STDERR "Usage: sanity-check "; + + exit $exit_code; +} + +binmode( STDOUT, ':encoding(utf-8)' ); + +if ( @ARGV < 1 ) { + show_usage(1); +} + +my ($file) = @ARGV; + +my $file_content = read_file($file); +my $json = JSON->new->utf8->decode($file_content); + +my $map = $json->{train}; + +for my $train_number ( sort { $a <=> $b } keys %{$map} ) { + for my $cycle_from ( @{ $map->{$train_number}{cycle}{from} // [] } ) { + if ( not exists $map->{$cycle_from} ) { + printf( + "%s %d references unknown train %d\n", + $map->{$train_number}{raw}, + $train_number, $cycle_from + ); + } + } + for my $cycle_to ( @{ $map->{$train_number}{cycle}{to} // [] } ) { + if ( not exists $map->{$cycle_to} ) { + printf( + "%s %d references unknown train %d\n", + $map->{$train_number}{raw}, + $train_number, $cycle_to + ); + } + } +} -- cgit v1.2.3