modified: src1/input.c
[GalaxyCodeBases.git] / c_cpp / lib / htslib / test / test-logging.pl
blob1040b0e47bca93fbb14cdc9beb9a256bf650837f
1 #!/usr/bin/env perl
3 # Copyright (C) 2017 Genome Research Ltd.
5 # Author: Anders Kaplan
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 # DEALINGS IN THE SOFTWARE.
25 use strict;
27 my $log_message_count = 0;
28 my $file_count = 0;
29 my $failure_count = 0;
31 sub check_log_message
33 my ($message, $filename, $line_num) = @_;
34 $log_message_count++;
36 unless ($message =~ /^\"([A-Z]|%s)/)
38 print "$filename line $line_num:\n";
39 print "Log message should begin with a capital letter: $message.\n";
40 $failure_count++;
43 if ($message =~ /\\n\"$/)
45 print "$filename line $line_num:\n";
46 print "Log message should NOT end with a newline: $message.\n";
47 $failure_count++;
50 if ($message =~ /\.\"$/)
52 print "$filename line $line_num:\n";
53 print "Log message should NOT end with a full stop: $message.\n";
54 $failure_count++;
58 sub check_file
60 my ($filename) = @_;
61 $file_count++;
63 open(my $fh, '<', $filename) or die "Could not open $filename.";
64 my $line_num = 1;
65 my $line = <$fh>;
66 while ($line)
68 if ($line =~ /hts_log_\w+\s*\(\s*(\"[^\"]*\")/)
70 unless ($line =~ /\\n\"\s*$/) # string constant continues on next line
72 check_log_message($1, $filename, $line_num);
76 $line_num++;
77 $line = <$fh>;
81 sub check_dir
83 my ($path) = @_;
84 foreach my $filename (glob("$path/*.c"))
86 check_file($filename);
90 check_dir("..");
91 check_dir("../cram");
93 print "$file_count files scanned\n";
94 print "$log_message_count log messages checked\n";
95 print "$failure_count errors found\n";
96 exit($failure_count > 0);