function generate_tests($file, $dest_path) { $content = file_get_contents($file); if (strpos($content, 'ZESK_TEST_SKIP')) { echo "# Skipping file {$file} because of ZESK_TEST_SKIP tag.\n"; return; } /* Strip away all extra lines */ $debug_parsing = zesk::getb('debug-parsing'); $content = str_replace("\r", "\n", $content); $content = str_replace("\n\n", "\n", $content); $iter = 0; $debug_parsing_path = path($dest_path, basename($file)); /* Strip away quoted strings (to eliminate stray {}) */ do { $old_content = $content; $content = preg_replace("/'[^'\n]*'/", "", $content); $content = preg_replace('/"[^"\\n]*"/', "", $content); } while ($content !== $old_content); if ($debug_parsing) { file_put_contents($debug_parsing_path . "." . $iter++, $content); } /* Strip away all // comments */ do { $old_content = $content; $content = preg_replace("|//[^\n]*\n|", "\n", $content); } while ($content !== $old_content); if ($debug_parsing) { file_put_contents($debug_parsing_path . "." . $iter++, $content); } /* Strip away all /* comments */ do { $old_content = $content; $content = preg_replace("|/\\*[^~]*?\\*/|m", "", $content); } while ($content !== $old_content); if ($debug_parsing) { file_put_contents($debug_parsing_path . "." . $iter++, $content); } /* Strip away all blocks */ do { $old_content = $content; $content = preg_replace('/\\{[^\\{\\}]*\\}/', "", $content); if ($debug_parsing) { file_put_contents($debug_parsing_path . "." . $iter++, $content); } } while ($content !== $old_content); $matches = false; if (preg_match_all('|function\\s+([A-Za-z_][A-Za-z_0-9]*)\\s*\\(([^\\)]*)\\)|', $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { $func = $match[1]; echo "### {$file} found {$func}\n"; $params = clean_function_parameters($match[2]); generate_function_tests($file, $dest_path, $func, $params); } } if (preg_match_all("/class\\s+([A-Za-z_][A-Za-z_0-9]*)\\s*/", $content, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { generate_class_tests($file, $dest_path, $match[1]); } } }
#!/usr/bin/env php <?php require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/zesk.inc'; Module::load('markdown'); cdn::add('/share/', '/share/', ZESK_ROOT . 'share/'); zesk::factory("Command_Markdown")->go();