From e6d85927ea69325e79fa4fd5cee0882e9ad3303f Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 8 May 2018 11:07:57 -0700 Subject: test-pandoc-utils.lua: remove problems with missing `/bin/false`. Previously it was assumed that the system would have `/bin/false` and `/bin/sed`, and these tests were skipped otherwise. On MacOS, these utilities are located in `/usr/bin`. Fixed by just using `sed` and `false` -- these should always be in the path. Removed the "skipping" behavior, replaced with a check for Windows. On Windowns, we use `echo` and `cd`, which should always exist. Not yet checked on Windows. --- test/lua/test-pandoc-utils.lua | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/test/lua/test-pandoc-utils.lua b/test/lua/test-pandoc-utils.lua index c732d2f85..000be1f7a 100644 --- a/test/lua/test-pandoc-utils.lua +++ b/test/lua/test-pandoc-utils.lua @@ -32,25 +32,34 @@ end function warn (...) io.stderr:write(...) end +function os_is_windows () + return package.config:sub(1,1) == '\\' +end + function test_pipe () - if not file_exists('/bin/sed') then - warn 'Did not find /bin/sed, skipping test' - return true + if os_is_windows() then + local pipe_result = pandoc.pipe('echo', {}, 'hi') + return pipe_result == 'hi\n' + else + local pipe_result = pandoc.pipe('sed', {'-e', 's/a/b/'}, 'abc') + return pipe_result == 'bbc\n' end - local pipe_result = pandoc.pipe('/bin/sed', {'-e', 's/a/b/'}, 'abc') - return pipe_result == 'bbc' end function test_failing_pipe () - if not file_exists('/bin/false') then - warn 'Did not find /bin/false, skipping test' - return true + if os_is_windows() then + local res, err = pcall(pandoc.pipe, 'cd', {}, 'NoNExistEnt') + return not res and + err.command == 'cd' and + err.error_code == 1 and + err.output == '' + else + local res, err = pcall(pandoc.pipe, 'false', {}, 'abc') + return not res and + err.command == 'false' and + err.error_code == 1 and + err.output == '' end - local res, err = pcall(pandoc.pipe, '/bin/false', {}, 'abc') - return not res and - err.command == '/bin/false' and - err.error_code == 1 and - err.output == '' end -- Read -- cgit v1.2.3