diff options
author | tailor <cygnus@janrain.com> | 2006-01-04 21:14:56 +0000 |
---|---|---|
committer | tailor <cygnus@janrain.com> | 2006-01-04 21:14:56 +0000 |
commit | dbfa1aa3a72715e35e12e7ce1b053bee33328a62 (patch) | |
tree | bf4e39ff5e19789c84dc462882430674e8c805d9 /admin | |
parent | c48833eccc670a2c8d4367beb56a60b9193124c1 (diff) | |
download | php-openid-dbfa1aa3a72715e35e12e7ce1b053bee33328a62.zip php-openid-dbfa1aa3a72715e35e12e7ce1b053bee33328a62.tar.gz php-openid-dbfa1aa3a72715e35e12e7ce1b053bee33328a62.tar.bz2 |
[project @ Added long line check script to admin/]
Diffstat (limited to 'admin')
-rw-r--r-- | admin/longlines.pl | 46 | ||||
-rw-r--r-- | admin/nolonglines | 17 | ||||
-rw-r--r-- | admin/runtests | 6 |
3 files changed, 68 insertions, 1 deletions
diff --git a/admin/longlines.pl b/admin/longlines.pl new file mode 100644 index 0000000..6ce65e8 --- /dev/null +++ b/admin/longlines.pl @@ -0,0 +1,46 @@ +#!/usr/bin/env perl -w + +use strict; + +my $filename = $ARGV[0]; + +if (!$filename) { + print "Usage: longlines.pl <filename> [length]\n"; + exit(1); +} + +# Set a default maximum line length. +my $max_length = $ARGV[1] || 80; + +my @lines = (); +my $line_num = 0; + +open(HANDLE, "<", $filename) or die "Cannot open $filename\n"; + +# Read the file and track the lines with length > $max_length. +while (<HANDLE>) { + $line_num++; + # Subtract one because the newline doesn't count toward the + # length. + if (length($_) - 1 > $max_length) { + push @lines, $line_num; + } +} + +# If more than five long lines were found, truncate to five and +# indicate that others were present, too. +if (@lines > 5) { + @lines = @lines[0..4]; + push @lines, "and others"; +} + +# If any long lines were found, notify and exit(1); otherwise, +# exit(0). +if (@lines) { + print $filename." (line".((@lines > 1) ? "s" : "")." ". + join(", ", @lines)." exceed".((@lines == 1) ? "s" : ""). + " length $max_length)\n"; + exit(1); +} else { + exit(0); +} diff --git a/admin/nolonglines b/admin/nolonglines new file mode 100644 index 0000000..20b4336 --- /dev/null +++ b/admin/nolonglines @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +files_with_long_lines=$(find Net Tests -name \*.php | + xargs -l1 wc -L | + awk '$1 > 80 { print $2 }' | + xargs -l1 -I FILENAME /usr/bin/env perl admin/longlines.pl FILENAME 80) + +if [ "$files_with_long_lines" ] + then + cat <<EOF 1>&2 +Found lines > 80 characters in: + +$files_with_long_lines +EOF + exit 1 +fi + diff --git a/admin/runtests b/admin/runtests index e6b036c..0a65226 100644 --- a/admin/runtests +++ b/admin/runtests @@ -4,11 +4,15 @@ test_tabs () { /usr/bin/env bash $(dirname "$0")/notabs } +test_longlines () { + /usr/bin/env bash $(dirname "$0")/nolonglines +} + test_php () { /usr/bin/env php texttest.php } -tests="tabs php" +tests="tabs longlines php" failures= for test_name in $tests |