/** * main * * @access public * @return void */ public function main() { // Load options, and print help if appropriate $config = $this->getopts(array('file:' => 'f:', 'help' => 'h', 'output:' => 'o:')); if ($config['help']) { $this->out($this->help_string); return 0; } // Open input file $input = null; if (empty($config['file'])) { $this->err("-f / --file argument is required!"); return 1; } $input = fopen($config['file'], 'r'); if (!$input) { $this->err("Error reading input from {$config['file']}"); return 1; } // Verify contents of the file $contents = stream_get_contents($input); if (empty($contents)) { $this->err("Cannot parse empty data!"); return 1; } // Create a parser and parse the contents $parser = new PPP_Parser(); $parsed = $parser->parse($contents); // Push output to STDOUT or to file, if provided if (empty($config['output'])) { $this->out($parsed); return 0; } if (file_put_contents($config['output'], $parsed)) { return 0; } else { $this->err("Could not write to output file {$config['output']}"); return 1; } }
} } require 'source/ppp.php'; $parser = new PPP_Parser(); $samples = opendir($sample_dir = dirname(__FILE__) . '/samples'); $output = opendir($output_dir = dirname(__FILE__) . '/output'); $failures = 0; $lines = 0; while ($path = readdir($samples)) { if ($path[0] == '.') { continue; } list($name, $ext) = explode('.', $path); $cur_sample = file_get_contents($sample_dir . '/' . $path); $cur_output = file_get_contents($output_dir . '/' . $name . '.php'); $parsed = $parser->parse($cur_sample); $output_lines = explode("\n", $cur_output); $parsed_lines = explode("\n", $parsed); $line = 0; foreach ($parsed_lines as $p_line) { $lines++; $line++; $o_line = array_shift($output_lines); if (trim($p_line) != trim($o_line)) { $failures++; echocolor(">>>>> FAILURE!! #{$failures} <<<<<< \n", 'red'); echocolor($line, 'cyan'); echo '. ' . $p_line; echocolor("\n-------------\n", 'yellow'); echocolor($line, 'cyan'); echo '. ' . $o_line;