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.
This commit is contained in:
John MacFarlane
2018-05-08 11:07:57 -07:00
parent 40603dd4cd
commit e6d85927ea
+22 -13
View File
@@ -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