#!/usr/bin/perl # This script adds standard comments to getInfo(), setUp(), and tearDown() # methods in a test file (reads from standard input, writes to standard output). $prev_comment = 0; $class = 'DrupalWebTestCase'; while ($line = <>) { $is_comment = 0; # See if this line is a comment - somewhat liberal matching to catch # cases /*, *, and */ (after optional whitespace). if ($line =~ /^(\s*\/\s+\*|\*)/) { $is_comment = 1; } # See if this line starts a class declaration. elsif ($line =~ /(\s+|^)class\s+.*extends\s+(\w+)/) { # See if it extends DrupalWebTestCase or DrupalUnitTestCase if ($1 =~ /UnitTest/) { $class = 'DrupalUnitTestCase'; } else { $class = 'DrupalWebTestCase'; } } # See if this line is a setUp, tearDown, or getInfo function, and add the # standard docblock if so. elsif (!$prev_comment && ($line =~ /function (setUp|tearDown|getInfo)/)) { print " /**\n"; # Note: Putting the :: into the first string made it not work right. print " * Overrides $class" . "::$1().\n"; print " */\n"; } # Print the line, no matter what print $line; $prev_comment = $is_comment; }