]> sjero.net Git - wget/blob - tests/Testing.pm
[svn] Better explanation of last change to HTTP code in ChangeLog.
[wget] / tests / Testing.pm
1 #!/usr/bin/perl -w
2
3 use HTTPServer;
4
5 use strict;
6
7 package Testing;
8
9 sub Run_HTTP_Test {
10     
11     my ($urls, $cmdline, $expected_error_code, $expected_downloaded_files) = @_;
12     
13     my $pid = HTTPServer::run (%{$urls});
14
15     print "Spawned HTTP server with pid: $pid\n"; 
16
17     my $returned_error_code = system ($cmdline);
18
19     kill ('TERM', $pid);
20
21     print "Killed HTTP server\n";
22
23     $returned_error_code == $expected_error_code 
24         or die "Test failed: wrong code returned (was: $returned_error_code, expected: $expected_error_code)";
25
26     if (my $str = verify_download (%{$expected_downloaded_files})) {
27         die $str;
28     }
29
30     print "Test successful."
31 }
32
33
34 sub verify_download {
35     my (%expected_downloaded_files) = @_;
36        
37     # use slurp mode to read file content
38     my $old_input_record_separator = $/;
39     undef $/;
40     
41     while (my ($filename, $expected_content) = each %expected_downloaded_files) {
42         open (FILE, $filename) or return "Test failed: file $filename not downloaded";
43         
44         my $content = <FILE>;
45         $content eq $expected_content or return "Test failed: wrong content for file $filename";
46         
47         close (FILE);
48     } 
49     
50     $/ = $old_input_record_separator;
51
52     return "";
53 }
54
55 1;
56
57 # vim: et ts=4 sw=4
58