]> git.gsnw.org Git - fping.git/commitdiff
tests for useful input file features
authorErik Auerswald <auerswal@unix-ag.uni-kl.de>
Fri, 24 Jan 2025 21:45:26 +0000 (22:45 +0100)
committerErik Auerswald <auerswal@unix-ag.uni-kl.de>
Sat, 8 Mar 2025 15:16:07 +0000 (16:16 +0100)
* whitespace in sufficiently short lines is skipped
* additional words after the target are ignored in sufficiently
  short lines
* whitespace-only (i.e., blank, but not empty) lines are skipped
* DOS-format text files, i.e., lines terminated with CRLF, work
* input need not be a correct POSIX text file, i.e., non-empty
  input does not need to end with LF

ci/test-06-options-f-h.pl

index 4229efe2cce45d18522fe1f3bae09927a811399b..b3f4b07f6a3bbb708419a35e6eb48a7e2c77515a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 
-use Test::Command tests => 146;
+use Test::Command tests => 161;
 use Test::More;
 use File::Temp;
 
@@ -10,14 +10,36 @@ use File::Temp;
 #               (ex. ../src/fping -g 192.168.1.0 192.168.1.255 or ../src/fping -g 192.168.1.0/24)
 #  -H n       Set the IP TTL value (Time To Live hops)
 
+# basic input file
 my $tmpfile = File::Temp->new();
 print $tmpfile "127.0.0.1\n127.0.0.2\n";
 close($tmpfile);
 
+# input file with comment, empty & blank lines, leading & trailing whitespace
 my $tmpfile2 = File::Temp->new();
-print $tmpfile2 "# comment\n127.0.0.1\n\n127.0.0.2\n";
+print $tmpfile2 "# comment\n 127.0.0.1\n\n\t127.0.0.2 \t\n   \n \t127.0.0.3\t \n";
 close($tmpfile2);
 
+# input file with CRLF line endings
+my $tmpfile3 = File::Temp->new();
+print $tmpfile3 " # comment \r\n 127.0.0.1\r\n\r\n127.0.0.2 \r\n   \r\n 127.0.0.3 \r\n";
+close($tmpfile3);
+
+# input file without trailing newline (i.e., not a POSIX text file)
+my $tmpfile4 = File::Temp->new();
+print $tmpfile4 "127.0.0.1\n127.0.0.2";
+close($tmpfile4);
+
+# input file with large amount of trailing whitespace
+my $tmpfile5 = File::Temp->new();
+print $tmpfile5 "127.0.0.1"." "x300 ."\n  127.0.0.2"." "x300 ."\r\n";
+close($tmpfile5);
+
+# input file with ignored words after the target
+my $tmpfile6 = File::Temp->new();
+print $tmpfile6 "127.0.0.1 # this is ignored\n127.0.0.2 this is ignored\n";
+close($tmpfile6);
+
 # fping without option (-> equivalent to 'fping -f -')
 {
 my $cmd = Test::Command->new(cmd => "cat ".$tmpfile->filename." | fping");
@@ -42,10 +64,42 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
 $cmd->stderr_is_eq("");
 }
 
-# fping -f file (with comment and empty line)
+# fping -f file (with comment, empty line, blank line, and spaces around IPs)
 {
 my $cmd = Test::Command->new(cmd => "fping -f ".$tmpfile2->filename);
 $cmd->exit_is_num(0);
+$cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n127.0.0.3 is alive\n");
+$cmd->stderr_is_eq("");
+}
+
+# fping -f file (with CRLF line endings)
+{
+my $cmd = Test::Command->new(cmd => "fping -f ".$tmpfile3->filename);
+$cmd->exit_is_num(0);
+$cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n127.0.0.3 is alive\n");
+$cmd->stderr_is_eq("");
+}
+
+# fping -f file (last "line" without NL -> not a POSIX text file)
+{
+my $cmd = Test::Command->new(cmd => "fping -f ".$tmpfile4->filename);
+$cmd->exit_is_num(0);
+$cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
+$cmd->stderr_is_eq("");
+}
+
+# fping -f file (lots of trailing whitespace)
+{
+my $cmd = Test::Command->new(cmd => "fping -f ".$tmpfile5->filename);
+$cmd->exit_is_num(0);
+$cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
+$cmd->stderr_is_eq("");
+}
+
+# fping -f file (trailing comments)
+{
+my $cmd = Test::Command->new(cmd => "fping -f ".$tmpfile6->filename);
+$cmd->exit_is_num(0);
 $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
 $cmd->stderr_is_eq("");
 }
@@ -58,6 +112,14 @@ $cmd->stdout_is_eq("");
 $cmd->stderr_like(qr{: fopen :});
 }
 
+# fping -f /dev/null (no imput)
+{
+my $cmd = Test::Command->new(cmd => "fping -f /dev/null");
+$cmd->exit_is_num(1);
+$cmd->stdout_is_eq("");
+$cmd->stderr_is_eq("");
+}
+
 # fping -g (error: no argument)
 {
 my $cmd = Test::Command->new(cmd => "fping -g");