mirror of
https://github.com/drwetter/testssl.sh.git
synced 2025-12-10 09:14:00 +01:00
json and html unit tests more seamless
- html_file / json_file - file name comes in command, not earlier - Both a title - avoid fixed string for file names over and over
This commit is contained in:
@@ -11,8 +11,8 @@ use Text::Diff;
|
||||
my $tests = 0;
|
||||
my $prg="./testssl.sh";
|
||||
my $html="";
|
||||
my $htmlfile="tmp.html";
|
||||
my $check2run="--ip=one -4 --openssl /usr/bin/openssl --sneaky --ids-friendly --color 0 --htmlfile $htmlfile";
|
||||
my $html_file="";
|
||||
my $check2run="--ip=one -4 --openssl /usr/bin/openssl --sneaky --ids-friendly --color 0 --htmlfile";
|
||||
my $uri="github.com";
|
||||
my $out="";
|
||||
my $debughtml="";
|
||||
@@ -21,27 +21,27 @@ my $edited_html="";
|
||||
my $diff="";
|
||||
my $ip="";
|
||||
|
||||
die "Unable to open $prg" unless -f $prg;
|
||||
|
||||
printf "\n%s\n", "Doing HTML output checks";
|
||||
|
||||
# useful against "failed to flush stdout" messages
|
||||
STDOUT->autoflush(1);
|
||||
|
||||
die "Unable to open $prg" unless -f $prg;
|
||||
|
||||
# Provide proper start conditions
|
||||
unlink $htmlfile;
|
||||
$html_file="tmp.html";
|
||||
unlink $html_file;
|
||||
|
||||
# Title
|
||||
printf "\n%s\n", "Unit testing HTML output ...";
|
||||
|
||||
#1
|
||||
printf "%s\n", " .. running $prg against \"$uri\" to create HTML and terminal outputs (may take ~2 minutes)";
|
||||
# specify a TERM_WIDTH so that the two calls to testssl.sh don't create HTML files with different values of TERM_WIDTH
|
||||
$out = `TERM_WIDTH=120 $prg $check2run $uri`;
|
||||
$html = `cat $htmlfile`;
|
||||
$out = `TERM_WIDTH=120 $prg $check2run $html_file $uri`;
|
||||
$html = `cat $html_file`;
|
||||
# $edited_html will contain the HTML with formatting information removed in order to compare against terminal output
|
||||
# Start by removing the HTML header.
|
||||
$edited_html = `tail -n +11 $htmlfile`;
|
||||
unlink $htmlfile;
|
||||
$edited_html = `tail -n +11 $html_file`;
|
||||
unlink $html_file;
|
||||
|
||||
# Remove the HTML footer
|
||||
$edited_html =~ s/\n\<\/pre\>\n\<\/body\>\n\<\/html\>//;
|
||||
@@ -74,9 +74,9 @@ if ( $^O eq "darwin" ){
|
||||
#2
|
||||
printf "%s\n", " .. running again $prg against \"$uri\", now with --debug 4 to create HTML output (may take another ~2 minutes)";
|
||||
# Redirect stderr to /dev/null in order to avoid some unexplained "date: invalid date" error messages
|
||||
$out = `TERM_WIDTH=120 $prg $check2run --debug 4 $uri 2>/dev/null`;
|
||||
$debughtml = `cat $htmlfile`;
|
||||
unlink $htmlfile;
|
||||
$out = `TERM_WIDTH=120 $prg $check2run $html_file --debug 4 $uri 2>/dev/null`;
|
||||
$debughtml = `cat $html_file`;
|
||||
unlink $html_file;
|
||||
|
||||
# Remove date information from the Start and Done banners in the two HTML files, since they were created at different times
|
||||
$html =~ s/Start 2[0-9][0-9][0-9]-[0-3][0-9]-[0-3][0-9] [0-2][0-9]:[0-5][0-9]:[0-5][0-9]/Start XXXX-XX-XX XX:XX:XX/;
|
||||
@@ -116,10 +116,9 @@ ok($debughtml eq $html, "Checking if HTML file created with --debug 4 matches HT
|
||||
diag ("\n%s\n", "$diff");
|
||||
$tests++;
|
||||
|
||||
|
||||
printf "\n\n";
|
||||
done_testing($tests);
|
||||
printf "\n\n";
|
||||
|
||||
|
||||
# vim:ts=5:sw=5:expandtab
|
||||
# vim:ts=5:sw=5:expandtab
|
||||
|
||||
|
||||
Reference in New Issue
Block a user