git.iko.soy/typeable/pandoc
on master help sign in
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.

commite6d85927ea69325e79fa4fd5cee0882e9ad3303f authorJohn MacFarlane <jgm@berkeley.edu> dateTue 8 May 2018, 11:07 (8 years ago) parent40603dd
1 file changed+22−13
test/lua/test-pandoc-utils.lua+22−13
test/lua/test-pandoc-utils.lua+22−13
@@ -32,25 +32,34 @@ end
3232
3333function warn (...) io.stderr:write(...) end
3434
35+function os_is_windows ()
36+ return package.config:sub(1,1) == '\\'
37+end
38+
3539function test_pipe ()
36− if not file_exists('/bin/sed') then
37− warn 'Did not find /bin/sed, skipping test'
38− return true
40+ if os_is_windows() then
41+ local pipe_result = pandoc.pipe('echo', {}, 'hi')
42+ return pipe_result == 'hi\n'
43+ else
44+ local pipe_result = pandoc.pipe('sed', {'-e', 's/a/b/'}, 'abc')
45+ return pipe_result == 'bbc\n'
3946 end
40− local pipe_result = pandoc.pipe('/bin/sed', {'-e', 's/a/b/'}, 'abc')
41− return pipe_result == 'bbc'
4247end
4348
4449function test_failing_pipe ()
45− if not file_exists('/bin/false') then
46− warn 'Did not find /bin/false, skipping test'
47− return true
50+ if os_is_windows() then
51+ local res, err = pcall(pandoc.pipe, 'cd', {}, 'NoNExistEnt')
52+ return not res and
53+ err.command == 'cd' and
54+ err.error_code == 1 and
55+ err.output == ''
56+ else
57+ local res, err = pcall(pandoc.pipe, 'false', {}, 'abc')
58+ return not res and
59+ err.command == 'false' and
60+ err.error_code == 1 and
61+ err.output == ''
4862 end
49− local res, err = pcall(pandoc.pipe, '/bin/false', {}, 'abc')
50− return not res and
51− err.command == '/bin/false' and
52− err.error_code == 1 and
53− err.output == ''
5463end
5564
5665-- Read