diff options
author | chai <chaifix@163.com> | 2021-10-30 11:32:16 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-10-30 11:32:16 +0800 |
commit | 42ec7286b2d36a9ba22925f816a17cb1cc2aa5ce (patch) | |
tree | 24bc7009457a8d7500f264e89946dc20d069294f /Data/Libraries/Penlight/tests/test-utils2.lua | |
parent | 164885fd98d48703bd771f802d79557b7db97431 (diff) |
+ Penlight
Diffstat (limited to 'Data/Libraries/Penlight/tests/test-utils2.lua')
-rw-r--r-- | Data/Libraries/Penlight/tests/test-utils2.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Data/Libraries/Penlight/tests/test-utils2.lua b/Data/Libraries/Penlight/tests/test-utils2.lua new file mode 100644 index 0000000..897da3e --- /dev/null +++ b/Data/Libraries/Penlight/tests/test-utils2.lua @@ -0,0 +1,53 @@ +local path = require 'pl.path' +local utils = require 'pl.utils' +local asserteq = require 'pl.test'.asserteq + +local echo_lineending = "\n" +if path.is_windows then + echo_lineending = " \n" +end + +local function test_executeex(cmd, expected_successful, expected_retcode, expected_stdout, expected_stderr) +--print("\n"..cmd) +--print(os.execute(cmd)) +--print(utils.executeex(cmd)) + local successful, retcode, stdout, stderr = utils.executeex(cmd) + asserteq(successful, expected_successful) + asserteq(retcode, expected_retcode) + asserteq(stdout, expected_stdout) + asserteq(stderr, expected_stderr) +end + +-- Check the return codes +if utils.is_windows then + test_executeex("exit", true, 0, "", "") + test_executeex("exit 0", true, 0, "", "") + test_executeex("exit 1", false, 1, "", "") + test_executeex("exit 13", false, 13, "", "") + test_executeex("exit 255", false, 255, "", "") + test_executeex("exit 256", false, 256, "", "") + test_executeex("exit 257", false, 257, "", "") + test_executeex("exit 3809", false, 3809, "", "") + test_executeex("exit -1", false, -1, "", "") + test_executeex("exit -13", false, -13, "", "") + test_executeex("exit -255", false, -255, "", "") + test_executeex("exit -256", false, -256, "", "") + test_executeex("exit -257", false, -257, "", "") + test_executeex("exit -3809", false, -3809, "", "") +else + test_executeex("exit", true, 0, "", "") + test_executeex("exit 0", true, 0, "", "") + test_executeex("exit 1", false, 1, "", "") + test_executeex("exit 13", false, 13, "", "") + test_executeex("exit 255", false, 255, "", "") + -- on posix anything other than 0-255 is undefined + test_executeex("exit 256", true, 0, "", "") + test_executeex("exit 257", false, 1, "", "") + test_executeex("exit 3809", false, 225, "", "") +end + +-- Check output strings +test_executeex("echo stdout", true, 0, "stdout" .. echo_lineending, "") +test_executeex("(echo stderr 1>&2)", true, 0, "", "stderr" .. echo_lineending) +test_executeex("(echo stdout && (echo stderr 1>&2))", true, 0, "stdout" .. echo_lineending, "stderr" .. echo_lineending) + |