diff options
author | Nathan Gass | 2008-11-11 16:25:21 +0000 |
---|---|---|
committer | Nathan Gass | 2008-11-11 16:25:21 +0000 |
commit | d5a1eeaebeb6af8f2eef494b260a6cb742013fda (patch) | |
tree | 6a8271581e3b2db73aecc9c7f5c02946cc6f3372 | |
parent | a4016e0ab074ca7432b8a01929d29c4a5505b6d8 (diff) | |
download | itools-d5a1eeaebeb6af8f2eef494b260a6cb742013fda.tar.gz itools-d5a1eeaebeb6af8f2eef494b260a6cb742013fda.tar.bz2 itools-d5a1eeaebeb6af8f2eef494b260a6cb742013fda.zip |
some latin1 tests, debug it::exec
-rw-r--r-- | it.class | 7 | ||||
-rwxr-xr-x | tests/exec.t | 20 | ||||
-rwxr-xr-x | tests/getopt.t | 9 |
3 files changed, 31 insertions, 5 deletions
@@ -395,6 +395,9 @@ function exec(/* $cmd, $values1 = array(), ... */) foreach ($args as $arg) $values += (array)$arg; + #for escapeshellarg in it::_exec_quotevalue + $oldlocale = setlocale( LC_CTYPE, 0 ); + setlocale(LC_CTYPE, 'de_CH'); while (list($tag, $option, $key) = it::match('({(-?)(\w+)})', $cmd)) { $parts = array(); @@ -417,17 +420,19 @@ function exec(/* $cmd, $values1 = array(), ... */) $cmd = str_replace($tag, join(" ", $parts), $cmd); } + setlocale(LC_CTYPE, $oldlocale); $s = gettimeofday(); $result = EDC('noexec') ? "" : (string)shell_exec($cmd); $e = gettimeofday(); $msec= intval(($e['sec'] - $s['sec']) * 1000 + ($e['usec'] - $s['usec']) / 1000); - it::log('exec', "$msec\t$cmd"); + @it::log('exec', "$msec\t$cmd"); return $result; } +#fails with C locale!!! function _exec_quotevalue($value) { $result = strval($value); diff --git a/tests/exec.t b/tests/exec.t new file mode 100755 index 0000000..5e021cb --- /dev/null +++ b/tests/exec.t @@ -0,0 +1,20 @@ +#!/www/server/bin/php -qC +<?php + +# Tests for getopt in it.class + +require 'searchlib/search_test.class'; + +is(it::exec("echo gna"), "gna\n", "basic exec"); +is(it::exec("echo {arg}", 'arg' => 'gna'), "gna\n", "exec with argument"); + +foreach (array("", "C", "de_CH", "de_CH.utf8") as $locale) { + setlocale(LC_ALL, $locale); + $arg = "preüpost"; + if (it::match('utf8', $locale)) + $arg = utf8_encode($arg); + is(it::exec("echo " . $arg), $arg . "\n", "exec with umlaut (locale '$locale')"); + is(it::exec("echo {arg}", 'arg' => $arg), $arg . "\n", "exec with argument and umlaut (locale '$locale')"); +} + + diff --git a/tests/getopt.t b/tests/getopt.t index 2fbe322..54a5604 100755 --- a/tests/getopt.t +++ b/tests/getopt.t @@ -18,7 +18,8 @@ function getopt_ok($argv, $exp, $name) return is($got['argument'], $exp, $name); } -$testarg = "blah gnaber"; -getopt_ok(array('-a', $testarg), $testarg, "Short version"); -getopt_ok(array('--argument', $testarg), $testarg, "Long version with space"); -getopt_ok(array("--argument=$testarg"), $testarg, "Long version with equal"); +foreach (array("" => "blah gnaber", " (umlaute)" => "pre üäpost") as $variant => $testarg) { + getopt_ok(array('-a', $testarg), $testarg, "Short version" . $variant); + getopt_ok(array('--argument', $testarg), $testarg, "Long version with space" . $variant); + getopt_ok(array("--argument=$testarg"), $testarg, "Long version with equal" . $variant); +} |