Manuel Streuhofer 47be547cfa extend acceptance test to check for code style (#81)
* extend acceptance test to check for code style

* cleanup following own style guide
2016-12-21 19:30:28 +01:00

40 lines
939 B
Perl
Executable File

#!/usr/bin/env perl
use strict;
use warnings;
die "usage: $0 <file>\n" if (not @ARGV);
my $rc = 0;
my $file = shift;
open(my $fh, '<', $file) or die "Cannot open \`$file' for read: $!\n";
while (<$fh>) {
next if (/^\s*#/);
my $errors = 0;
# remove everything between single quotes
# this will remove too much in case of: echo "var='$var'"
# and thus miss an opportunity to complain later on
# also it mangles the input line irreversible
s/'[^']+'/'___'/g;
# highlight unbraced variables--
# unless properly backslash'ed
$errors += s/((?:^|[^\\]))(((\\\\)+)?\$\w)/$1\033[31m$2\033[0m/g;
# highlight single square brackets
$errors += s/((?:^|\s+))\[([^\[].+[^\]])\](\s*(;|&&|\|\|))/$1\033[31m\[\033[0m$2\033[31m\]\033[0m$3/g;
# highlight double equal sign
$errors += s/(\[\[.*)(==)(.*\]\])/$1\033[31m$2\033[0m$3/g;
next if (not $errors);
print "${file}[$.]: $_";
$rc = 1;
}
close($fh);
exit $rc;