From 3be5aa1a34f63f4e5e2b384098de2020a4c5b3bc Mon Sep 17 00:00:00 2001 From: erw7 Date: Fri, 18 Jan 2019 14:11:40 +0900 Subject: test/win: executable(), exepath() #9516 --- test/functional/eval/executable_spec.lua | 61 ++++++++++++++++++++++++++------ test/functional/eval/exepath_spec.lua | 14 ++++++++ 2 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 test/functional/eval/exepath_spec.lua (limited to 'test') diff --git a/test/functional/eval/executable_spec.lua b/test/functional/eval/executable_spec.lua index c931b47221..1055675c26 100644 --- a/test/functional/eval/executable_spec.lua +++ b/test/functional/eval/executable_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) -local eq, clear, call, iswin, write_file = - helpers.eq, helpers.clear, helpers.call, helpers.iswin, helpers.write_file +local eq, clear, call, iswin, write_file, command = + helpers.eq, helpers.clear, helpers.call, helpers.iswin, helpers.write_file, + helpers.command describe('executable()', function() before_each(clear) @@ -48,18 +49,17 @@ describe('executable()', function() end) it('not set', function() - local expected = iswin() and 1 or 0 - eq(expected, call('executable', 'Xtest_not_executable')) - eq(expected, call('executable', './Xtest_not_executable')) + eq(0, call('executable', 'Xtest_not_executable')) + eq(0, call('executable', './Xtest_not_executable')) end) it('set, unqualified and not in $PATH', function() - local expected = iswin() and 1 or 0 - eq(expected, call('executable', 'Xtest_executable')) + eq(0, call('executable', 'Xtest_executable')) end) it('set, qualified as a path', function() - eq(1, call('executable', './Xtest_executable')) + local expected = iswin() and 0 or 1 + eq(expected, call('executable', './Xtest_executable')) end) end) end) @@ -136,16 +136,18 @@ describe('executable() (Windows)', function() eq(1, call('executable', '.\\test_executable_zzz')) end) - it('returns 1 for any existing filename', function() + it('returns 1 for any existing filename, when a Unix-shell like \'shell\'', function() clear({env={PATHEXT=''}}) + command('set shell=sh') for _,ext in ipairs(exts) do eq(1, call('executable', 'test_executable_'..ext..'.'..ext)) end eq(1, call('executable', 'test_executable_zzz.zzz')) end) - it('returns 1 for any existing path (backslashes)', function() + it('returns 1 for any existing path, when a Unix-shell like \'shell\' (backslashes)', function() clear({env={PATHEXT=''}}) + command('set shell=bash.exe') for _,ext in ipairs(exts) do eq(1, call('executable', '.\\test_executable_'..ext..'.'..ext)) eq(1, call('executable', './test_executable_'..ext..'.'..ext)) @@ -153,4 +155,43 @@ describe('executable() (Windows)', function() eq(1, call('executable', '.\\test_executable_zzz.zzz')) eq(1, call('executable', './test_executable_zzz.zzz')) end) + + it('returns 1 for any existing filename, when $PATHEXT contain dot itself', function() + clear({env={PATHEXT='.;.zzz'}}) + command('set shell=sh') + for _,ext in ipairs(exts) do + eq(1, call('executable', 'test_executable_'..ext..'.'..ext)) + end + eq(1, call('executable', 'test_executable_zzz.zzz')) + clear({env={PATHEXT='.zzz;.'}}) + command('set shell=sh') + for _,ext in ipairs(exts) do + eq(1, call('executable', 'test_executable_'..ext..'.'..ext)) + end + eq(1, call('executable', 'test_executable_zzz.zzz')) + end) + + it('returns 1 for any existing path, when $PATHEXT contain dot itself (backslashes)', function() + clear({env={PATHEXT='.;.zzz'}}) + command('set shell=bash.exe') + for _,ext in ipairs(exts) do + eq(1, call('executable', '.\\test_executable_'..ext..'.'..ext)) + eq(1, call('executable', './test_executable_'..ext..'.'..ext)) + end + eq(1, call('executable', '.\\test_executable_zzz.zzz')) + eq(1, call('executable', './test_executable_zzz.zzz')) + end) + + it('ignore case of extension', function() + clear({env={PATHEXT='.ZZZ'}}) + eq(1, call('executable', 'test_executable_zzz.zzz')) + end) + + it('file is not found by relative path from $PATH', function() + clear({env={PATHEXT=''}}) + eq(0, call('executable', './System32/notepad.exe')) + eq(0, call('executable', '.\\System32\\notepad.exe')) + eq(0, call('executable', '../notepad.exe')) + eq(0, call('executable', '..\\notepad.exe')) + end) end) diff --git a/test/functional/eval/exepath_spec.lua b/test/functional/eval/exepath_spec.lua new file mode 100644 index 0000000000..50aa412867 --- /dev/null +++ b/test/functional/eval/exepath_spec.lua @@ -0,0 +1,14 @@ +local helpers = require('test.functional.helpers')(after_each) +local eq, clear, call, iswin = + helpers.eq, helpers.clear, helpers.call, helpers.iswin + +describe('exepath() (Windows)', function() + if not iswin() then return end -- N/A for Unix. + + it('append extension, even if omit extension', function() + local filename = 'cmd' + local pathext = '.exe' + clear({env={PATHEXT=pathext}}) + eq(call('exepath', filename..pathext), call('exepath', filename)) + end) +end) -- cgit From ece8d88b105d6c809648ad80280e7e3edb935410 Mon Sep 17 00:00:00 2001 From: erw7 Date: Mon, 1 Apr 2019 19:47:58 +0900 Subject: test/win: Remove unnecessary set shell --- test/functional/eval/executable_spec.lua | 3 --- 1 file changed, 3 deletions(-) (limited to 'test') diff --git a/test/functional/eval/executable_spec.lua b/test/functional/eval/executable_spec.lua index 1055675c26..efce0745ad 100644 --- a/test/functional/eval/executable_spec.lua +++ b/test/functional/eval/executable_spec.lua @@ -158,13 +158,11 @@ describe('executable() (Windows)', function() it('returns 1 for any existing filename, when $PATHEXT contain dot itself', function() clear({env={PATHEXT='.;.zzz'}}) - command('set shell=sh') for _,ext in ipairs(exts) do eq(1, call('executable', 'test_executable_'..ext..'.'..ext)) end eq(1, call('executable', 'test_executable_zzz.zzz')) clear({env={PATHEXT='.zzz;.'}}) - command('set shell=sh') for _,ext in ipairs(exts) do eq(1, call('executable', 'test_executable_'..ext..'.'..ext)) end @@ -173,7 +171,6 @@ describe('executable() (Windows)', function() it('returns 1 for any existing path, when $PATHEXT contain dot itself (backslashes)', function() clear({env={PATHEXT='.;.zzz'}}) - command('set shell=bash.exe') for _,ext in ipairs(exts) do eq(1, call('executable', '.\\test_executable_'..ext..'.'..ext)) eq(1, call('executable', './test_executable_'..ext..'.'..ext)) -- cgit From c7039fd0d3f6f5d7c8699fd88095e100f0754e59 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 1 Apr 2019 23:21:38 +0200 Subject: test: "$PATHEXT=::" --- test/functional/eval/executable_spec.lua | 19 +++++++++++++------ test/functional/eval/exepath_spec.lua | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/functional/eval/executable_spec.lua b/test/functional/eval/executable_spec.lua index efce0745ad..6a95128a4d 100644 --- a/test/functional/eval/executable_spec.lua +++ b/test/functional/eval/executable_spec.lua @@ -136,7 +136,14 @@ describe('executable() (Windows)', function() eq(1, call('executable', '.\\test_executable_zzz')) end) - it('returns 1 for any existing filename, when a Unix-shell like \'shell\'', function() + it("with weird $PATHEXT", function() + clear({env={PATHEXT=';'}}) + eq(0, call('executable', '.\\test_executable_zzz')) + clear({env={PATHEXT=';;;.zzz;;'}}) + eq(1, call('executable', '.\\test_executable_zzz')) + end) + + it("unqualified filename, Unix-style 'shell'", function() clear({env={PATHEXT=''}}) command('set shell=sh') for _,ext in ipairs(exts) do @@ -145,7 +152,7 @@ describe('executable() (Windows)', function() eq(1, call('executable', 'test_executable_zzz.zzz')) end) - it('returns 1 for any existing path, when a Unix-shell like \'shell\' (backslashes)', function() + it("relative path, Unix-style 'shell' (backslashes)", function() clear({env={PATHEXT=''}}) command('set shell=bash.exe') for _,ext in ipairs(exts) do @@ -156,7 +163,7 @@ describe('executable() (Windows)', function() eq(1, call('executable', './test_executable_zzz.zzz')) end) - it('returns 1 for any existing filename, when $PATHEXT contain dot itself', function() + it('unqualified filename, $PATHEXT contains dot', function() clear({env={PATHEXT='.;.zzz'}}) for _,ext in ipairs(exts) do eq(1, call('executable', 'test_executable_'..ext..'.'..ext)) @@ -169,7 +176,7 @@ describe('executable() (Windows)', function() eq(1, call('executable', 'test_executable_zzz.zzz')) end) - it('returns 1 for any existing path, when $PATHEXT contain dot itself (backslashes)', function() + it('relative path, $PATHEXT contains dot (backslashes)', function() clear({env={PATHEXT='.;.zzz'}}) for _,ext in ipairs(exts) do eq(1, call('executable', '.\\test_executable_'..ext..'.'..ext)) @@ -179,12 +186,12 @@ describe('executable() (Windows)', function() eq(1, call('executable', './test_executable_zzz.zzz')) end) - it('ignore case of extension', function() + it('ignores case of extension', function() clear({env={PATHEXT='.ZZZ'}}) eq(1, call('executable', 'test_executable_zzz.zzz')) end) - it('file is not found by relative path from $PATH', function() + it('relative path does not search $PATH', function() clear({env={PATHEXT=''}}) eq(0, call('executable', './System32/notepad.exe')) eq(0, call('executable', '.\\System32\\notepad.exe')) diff --git a/test/functional/eval/exepath_spec.lua b/test/functional/eval/exepath_spec.lua index 50aa412867..10a11aeacc 100644 --- a/test/functional/eval/exepath_spec.lua +++ b/test/functional/eval/exepath_spec.lua @@ -5,7 +5,7 @@ local eq, clear, call, iswin = describe('exepath() (Windows)', function() if not iswin() then return end -- N/A for Unix. - it('append extension, even if omit extension', function() + it('append extension if omitted', function() local filename = 'cmd' local pathext = '.exe' clear({env={PATHEXT=pathext}}) -- cgit