Пример #1
0
function log_failure($test_name, $subject, $commands, $outs, $errs, $exits, $missing_dependency, $reason)
{
    $red = red_string();
    $reset = reset_string();
    // we have 1 or more outputs, only 1 error, and 1 or more commands, with the same number of error codes as commands
    $err_string = "";
    if (is_array($commands)) {
        if ($exits == "Not relevent") {
            $command_string = "";
            foreach ($commands as $command) {
                $command_string .= "{$red}Command:{$reset} {$command}\n";
            }
        } else {
            phc_assert(is_array($exits), "Expected array of return values");
            phc_assert(count($exits) == count($errs), "Expected same number of exits as exit codes");
            $command_string = "";
            $err_string = "";
            foreach ($exits as $i => $exit) {
                $command = $commands[$i];
                $err = $errs[$i];
                $command_string .= "{$red}Command {$i}{$reset} ({$exit}): {$command}\n";
                if ($err) {
                    $err_string .= "{$red}Error {$i}{$reset}: {$err}\n";
                }
            }
        }
    } else {
        $command_string = "{$red}Command{$reset} ({$exits}): {$commands}\n";
        if ($errs) {
            $err_string = "{$red}Error{$reset}: {$errs}\n";
        }
    }
    $reason_string = "Reason: {$reason}\n";
    $dependency_string = "";
    if ($missing_dependency) {
        $dependency_string = "NOTE: dependency {$missing_dependency} is missing. This may be the cause of this failure\n";
    }
    $header = "{$reason_string}{$dependency_string}{$command_string}{$err_string}";
    // ready the output information
    global $log_directory;
    $script_name = adjusted_name($subject);
    $filename = "{$log_directory}/{$test_name}/{$script_name}.log";
    $dirname = dirname($filename);
    if (!is_dir($dirname)) {
        @mkdir($dirname, 0755, true);
        phc_assert(is_dir($dirname), "directory not created");
    }
    if (!is_array($outs)) {
        $outs = array($outs);
    }
    $out_string = "";
    // create the stdout logs - but only if there is more than 1 log
    if (count($outs) > 1 && count(array_filter($outs, "strlen"))) {
        foreach ($outs as $i => $out) {
            $output_contents = "Command: {$commands[$i]}\n" . $out;
            file_put_contents("{$filename}.out.{$i}", $output_contents);
        }
    }
    // write to the main log file
    foreach ($outs as $i => $out) {
        if (strlen($out) > 1000) {
            $out = substr($out, 0, 1000) . "... [truncated]\n";
        }
        $out_string .= "{$red}Output {$i}{$reset}:\n{$out}\n";
    }
    // print the output
    file_put_contents($filename, $header);
    file_put_contents($filename, rtrim($out_string), FILE_APPEND);
    file_put_contents($filename, "\n", FILE_APPEND);
}
Пример #2
0
 function get_support_filename($subject)
 {
     global $support_dir;
     $script_name = adjusted_name($subject, 1);
     return "{$support_dir}/{$this->name}/{$script_name}.{$this->suffix}";
 }