mirror of
https://github.com/drwetter/testssl.sh.git
synced 2026-07-14 02:57:39 +02:00
5518ea9da8
Starting with a few simple patterns, like for checking for non-variables at left hand side like [[ LHS == $value ]]. The file is supposed be amended in the future. This fixes #3074 for 3.2
64 lines
1.4 KiB
Perl
64 lines
1.4 KiB
Perl
#!/usr/bin/env perl
|
|
|
|
# Basics: are there semantic errors which are easy to spot?
|
|
|
|
use strict;
|
|
use Test::More;
|
|
|
|
my $tests = 0;
|
|
my $prg="testssl.sh";
|
|
my $os="$^O";
|
|
|
|
if ( $os eq "darwin" ){
|
|
plan skip_all => 'No checks on MacOS';
|
|
}
|
|
|
|
#1
|
|
printf "\n%s\n", "Testing for missing vars at left hand side in double square brackets ...";
|
|
|
|
# I know this isn't nice but perl doesn't seem for this so great either
|
|
my @matches = `grep -n '\\[\\[ [[:alpha:]]' $prg`;
|
|
is(scalar(@matches), 0, "Checking bad '[[ LHS' patterns")
|
|
or diag(@matches);
|
|
$tests++;
|
|
|
|
# The following works only on GNU grep
|
|
|
|
#2
|
|
printf "\n%s\n", "Testing for backticks ...";
|
|
|
|
my @matches = qx(grep -nP '`[^`]*`' $prg);
|
|
is(scalar(@matches), 0, "Checking bad backtick patterns")
|
|
or diag(@matches);
|
|
$tests++;
|
|
|
|
#3
|
|
printf "\n%s\n", "Sourcing without checking the file exists #1 ...";
|
|
|
|
my @matches = qx(grep -nP '^\s*\.\s+\$' $prg);
|
|
is(scalar(@matches), 0, "Checking bad sourcing pattern #1")
|
|
or diag(@matches);
|
|
$tests++;
|
|
|
|
#4
|
|
printf "\n%s\n", "Sourcing without checking the file exists #2 ...";
|
|
|
|
my @matches = qx(grep -nP '^\s*source\s+\$' $prg);
|
|
is(scalar(@matches), 0, "Checking bad sourcing pattern #2")
|
|
or diag(@matches);
|
|
$tests++;
|
|
|
|
|
|
# We have three eval already, a) re-analyse + exempt them
|
|
#my @matches = qx(grep -nP '\beval\b' $prg);
|
|
|
|
|
|
# more would go here
|
|
|
|
printf "\n";
|
|
done_testing($tests);
|
|
|
|
|
|
# vim:ts=5:sw=5:expandtab
|
|
|