From 551497ef94f6239b109316d8fab32f0909b13f73 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 15 Mar 2014 14:42:42 -0300 Subject: Squashed 'mod/less/' content from commit 380edad git-subtree-dir: mod/less git-subtree-split: 380edadb3a5e524a8e6ef6df063b678f2f00516f --- vendors/lessphp/tests/test.php | 190 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 vendors/lessphp/tests/test.php (limited to 'vendors/lessphp/tests/test.php') diff --git a/vendors/lessphp/tests/test.php b/vendors/lessphp/tests/test.php new file mode 100644 index 000000000..629fe0153 --- /dev/null +++ b/vendors/lessphp/tests/test.php @@ -0,0 +1,190 @@ +#!/usr/bin/env php + 'inputs', + 'glob' => '*.less', +); + +$output = array( + 'dir' => 'outputs', + 'filename' => '%s.css', +); + + +$prefix = strtr(realpath(dirname(__FILE__)), '\\', '/'); +require $prefix.'/../lessc.inc.php'; + +$compiler = new lessc(); +$compiler->importDir = array($input['dir'].'/test-imports'); + +$fa = 'Fatal Error: '; +if (php_sapi_name() != 'cli') { + exit($fa.$argv[0].' must be run in the command line.'); +} + +$opts = getopt('hCd::g'); + +if ($opts === false || isset($opts['h'])) { + echo << 0 && $a{0} != '-') { + $searchString = $a; + break; + } +} + +$tests = array(); +$matches = glob($input['dir'].'/'.(!is_null($searchString) ? '*'.$searchString : '' ).$input['glob']); +if ($matches) { + foreach ($matches as $fname) { + extract(pathinfo($fname)); // for $filename, from php 5.2 + $tests[] = array( + 'in' => $fname, + 'out' => $output['dir'].'/'.sprintf($output['filename'], $filename), + ); + } +} + +$count = count($tests); +$compiling = isset($opts["C"]); +$continue_when_test_fails = isset($opts["g"]); +$showDiff = isset($opts["d"]); +if ($showDiff && !empty($opts["d"])) { + $difftool = $opts["d"]; +} + +echo ($compiling ? "Compiling" : "Running")." $count test".($count == 1 ? '' : 's').":\n"; + +function dump($msgs, $depth = 1, $prefix=" ") { + if (!is_array($msgs)) $msgs = array($msgs); + foreach ($msgs as $m) { + echo str_repeat($prefix, $depth).' - '.$m."\n"; + } +} + +$fail_prefix = " ** "; + +$fail_count = 0; +$i = 1; +foreach ($tests as $test) { + printf(" [Test %04d/%04d] %s -> %s\n", $i, $count, basename($test['in']), basename($test['out'])); + + try { + ob_start(); + $parsed = trim($compiler->parse(file_get_contents($test['in']))); + ob_end_clean(); + } catch (exception $e) { + dump(array( + "Failed to compile input, reason:", + $e->getMessage(), + "Aborting" + ), 1, $fail_prefix); + break; + } + + if ($compiling) { + file_put_contents($test['out'], $parsed); + } else { + if (!is_file($test['out'])) { + dump(array( + "Failed to find output file: $test[out]", + "Maybe you forgot to compile tests?", + "Aborting" + ), 1, $fail_prefix); + break; + } + $expected = trim(file_get_contents($test['out'])); + + // don't care about CRLF vs LF change (DOS/Win vs. UNIX): + $expected = trim(str_replace("\r\n", "\n", $expected)); + $parsed = trim(str_replace("\r\n", "\n", $parsed)); + + if ($expected != $parsed) { + $fail_count++; + if ($showDiff) { + dump("Failed:", 1, $fail_prefix); + $tmp = $test['out'].".tmp"; + file_put_contents($tmp, $parsed); + system($difftool.' '.$test['out'].' '.$tmp); + unlink($tmp); + + if (!$continue_when_test_fails) { + dump("Aborting"); + break; + } else { + echo "===========================================================================\n"; + } + } else { + dump("Failed, run with -d flag to view diff", 1, $fail_prefix); + } + } else { + dump("Passed"); + } + } + + $i++; +} + +exit($fail_count > 255 ? 255 : $fail_count); +?> -- cgit v1.2.3