function test_php_syntax()
 {
     global $CFG;
     // See if we can run php from the command line:
     $this->phppath = 'php';
     if (!shell_exec($this->phppath . ' -v')) {
         // If not, we can't do anything.
         $this->fail('Cannot test PHP syntax because PHP is not on the path.');
         return;
     }
     $regexp = '/\\.(' . implode('|', $this->php_code_extensions) . ')$/';
     $ignore = array_map(array($this, 'prepend_dirroot'), $this->ignore_folders);
     recurseFolders($CFG->dirroot, array($this, 'syntax_check_file'), $regexp, false, $ignore);
 }
示例#2
0
/**
 * Recursively visit all the files in the source tree. Calls the callback
 * function with the pathname of each file found.
 *
 * @param $path the folder to start searching from.
 * @param $callback the function to call with the name of each file found.
 * @param $fileregexp a regexp used to filter the search (optional).
 * @param $exclude If true, pathnames that match the regexp will be ingored. If false,
 *     only files that match the regexp will be included. (default false).
 * @param array $ignorefolders will not go into any of these folders (optional).
 */
function recurseFolders($path, $callback, $fileregexp = '/.*/', $exclude = false, $ignorefolders = array()) {
    $files = scandir($path);

    foreach ($files as $file) {
        $filepath = $path .'/'. $file;
        if (strpos($file, '.') === 0) {
            /// Don't check hidden files.
            continue;
        } else if (is_dir($filepath)) {
            if (!in_array($filepath, $ignorefolders)) {
                recurseFolders($filepath, $callback, $fileregexp, $exclude, $ignorefolders);
            }
        } else if ($exclude xor preg_match($fileregexp, $filepath)) {
            call_user_func($callback, $filepath);
        }
    }
}
示例#3
0
 function test_dnc()
 {
     global $CFG;
     $regexp = '/\\.(' . implode('|', $this->extensions_to_ignore) . ')$/';
     $this->badstrings = array();
     $this->badstrings['DONOT' . 'COMMIT'] = 'DONOT' . 'COMMIT';
     // If we put the literal string here, it fails the test!
     $this->badstrings['trailing whitespace'] = "[\t ][\r\n]";
     foreach ($this->badstrings as $description => $ignored) {
         $this->allok[$description] = true;
     }
     recurseFolders($CFG->dirroot, array($this, 'search_file_for_dnc'), $regexp, true);
     foreach ($this->badstrings as $description => $ignored) {
         if ($this->allok[$description]) {
             $this->pass("No files contain {$description}.");
         }
     }
 }
示例#4
0
/**
 * Recursively visit all the files in the source tree. Calls the callback
 * function with the pathname of each file found. 
 * 
 * @param $path the folder to start searching from. 
 * @param $callback the function to call with the name of each file found.
 * @param $fileregexp a regexp used to filter the search (optional).
 * @param $exclude If true, pathnames that match the regexp will be ingored. If false, 
 *     only files that match the regexp will be included. (default false).
 * @param array $ignorefolders will not go into any of these folders (optional).
 */
function recurseFolders($path, $callback, $fileregexp = '/.*/', $exclude = false, $ignorefolders = array())
{
    $files = scandir($path);
    foreach ($files as $file) {
        $filepath = $path . '/' . $file;
        if ($file == '.' || $file == '..') {
            continue;
        } else {
            if (is_dir($filepath)) {
                if (!in_array($filepath, $ignorefolders)) {
                    recurseFolders($filepath, $callback, $fileregexp, $exclude, $ignorefolders);
                }
            } else {
                if ($exclude xor preg_match($fileregexp, $filepath)) {
                    call_user_func($callback, $filepath);
                }
            }
        }
    }
}
$PAGE->set_url('/lib/simpletest/todochecker.php');
$PAGE->set_context($context);
$PAGE->set_title('To-do checker');
$PAGE->set_heading('To-do checker');
$thirdparty = load_third_party_lib_list();
$extensionstotest = array('php');
$extensionsregex = '/\\.(?:' . implode('|', $extensionstotest) . ')$/';
$patterntofind = 'TO' . 'DO';
// Make it not match the regex.
$found = array();
echo $OUTPUT->header();
echo $OUTPUT->heading('To-do checker', 2);
echo $OUTPUT->box_start();
echo 'Checking code ...';
flush();
recurseFolders($CFG->dirroot, 'check_to_dos', $extensionsregex, false, array_keys($thirdparty));
echo ' done.';
echo $OUTPUT->box_end();
if (empty($found)) {
    echo '<p>No to-dos found.</p>';
} else {
    $total = 0;
    foreach ($found as $filepath => $matches) {
        $total += count($matches);
    }
    echo '<p>' . $total . ' to-dos found:</p><dl>';
    foreach ($found as $filepath => $matches) {
        echo '<dt>' . $filepath . ' <b>(' . count($matches) . ')</b></dt><dd><ul>';
        foreach ($matches as $lineno => $line) {
            $url = 'http://cvs.moodle.org/moodle/' . $filepath . '?view=annotate#l' . $lineno;
            $error = '';