55io.stdout :setvbuf (" no" )
66io.stderr :setvbuf (" no" )
77
8- local ppChunk = assert (loadfile " preprocess.lua" )
9- local results = {}
8+ local ppChunk = assert (loadfile " preprocess.lua" )
9+ local results = {}
10+ local luaExe = " lua"
11+ local enableInts = _VERSION >= " Lua 5.3"
12+
13+ for i = - 1 , - 1 / 0 , - 1 do
14+ if not arg [i ] then break end
15+ luaExe = arg [i ]
16+ end
17+
18+
1019
1120local function doTest (description , f , ...)
1221 print (" Running test: " .. description )
@@ -53,9 +62,27 @@ local function assertCodeOutput(codeOut, codeExpected, message)
5362 error (message or " Unexpected output: " .. codeOut , 2 )
5463 end
5564end
56- local function assertCmd (cmd )
57- local code = os.execute (cmd )
58- if code ~= 0 then error (" Command failed: " .. cmd , 2 ) end
65+
66+ local function runCommandRequired (program , argsStr )
67+ local cmd = (
68+ program :find (" " , 1 , true )
69+ and ' ""' .. program .. ' " ' .. argsStr .. ' "'
70+ or program .. ' ' .. argsStr
71+ )
72+
73+ print (" Running command: " .. cmd )
74+
75+ if jit or _VERSION >= " Lua 5.2" then
76+ local ok , termination , code = os.execute (cmd )
77+ if not (ok and termination == " exit" and code == 0 ) then
78+ error (" Command failed (termination=" .. tostring (termination ).. " , code=" .. tostring (code ).. " ): " .. cmd , 2 )
79+ end
80+ else
81+ local code = os.execute (cmd )
82+ if code ~= 0 then
83+ error (" Command failed (code=" .. code .. " ): " .. cmd , 2 )
84+ end
85+ end
5986end
6087
6188-- ==============================================================
@@ -145,7 +172,7 @@ doTest("Parsing extended preprocessor line", function()
145172 ]]
146173
147174 local luaOut = assert (pp .processString { code = luaIn })
148- assertCodeOutput (luaOut , [[ local z = 137]] )
175+ assertCodeOutput (luaOut , enableInts and [[ local z = 137.0 ]] or [[ local z = 137]] )
149176end )
150177
151178doTest (" Dual code" , function ()
@@ -161,7 +188,7 @@ doTest("Dual code", function()
161188 local luaOut = assert (pp .processString { code = [[
162189 !!local n, s = 5^5, "foo".."bar";
163190 ]] })
164- assertCodeOutput (luaOut , [[ local n, s = 3125, "foobar";]] )
191+ assertCodeOutput (luaOut , enableInts and [[ local n, s = 3125.0, "foobar"; ]] or [[ local n, s = 3125, "foobar";]] )
165192
166193 -- Invalid: Duplicate names.
167194 assert (not pp .processString { code = [[ !!x, y, x = 0 ]] })
@@ -691,7 +718,7 @@ doTest("Simple processing of single file", function()
691718 assert (writeFile (" local/generatedTest.lua2p" , [[
692719 !outputLua("math.floor(1.5)")
693720 ]] ))
694- assertCmd ( [[ lua ./ preprocess-cl.lua local/generatedTest.lua2p]] )
721+ runCommandRequired ( luaExe , [[ preprocess-cl.lua local/generatedTest.lua2p]] )
695722
696723 local luaOut = assert (readFile (" local/generatedTest.lua" ))
697724 assertCodeOutput (luaOut , [[ math.floor(1.5)]] )
@@ -701,7 +728,7 @@ doTest("Send data", function()
701728 assert (writeFile (" local/generatedTest.lua2p" , [[
702729 print(!(dataFromCommandLine))
703730 ]] ))
704- assertCmd ( [[ lua ./ preprocess-cl.lua --outputpaths --data="Hello, world!" local/generatedTest.lua2p local/generatedTest.lua]] )
731+ runCommandRequired ( luaExe , [[ preprocess-cl.lua --outputpaths --data="Hello, world!" local/generatedTest.lua2p local/generatedTest.lua]] )
705732
706733 local luaOut = assert (readFile (" local/generatedTest.lua" ))
707734 assertCodeOutput (luaOut , [[ print("Hello, world!")]] )
@@ -720,12 +747,12 @@ doTest("Handler + multiple files", function()
720747 assert (writeFile (" local/generatedTest1.lua2p" , " !!local x = one+2*3\n " ))
721748 assert (writeFile (" local/generatedTest2.lua2p" , " !!local y = one+2^10\n " ))
722749
723- assertCmd ( [[ lua ./ preprocess-cl.lua --handler=local/generatedHandler.lua local/generatedTest1.lua2p local/generatedTest2.lua2p]] )
750+ runCommandRequired ( luaExe , [[ preprocess-cl.lua --handler=local/generatedHandler.lua local/generatedTest1.lua2p local/generatedTest2.lua2p]] )
724751
725752 local luaOut = assert (readFile (" local/generatedTest1.lua" ))
726753 assertCodeOutput (luaOut , [[ print("foo");local x = 7]] )
727754 local luaOut = assert (readFile (" local/generatedTest2.lua" ))
728- assertCodeOutput (luaOut , [[ print("foo");local y = 1025]] )
755+ assertCodeOutput (luaOut , enableInts and [[ print("foo");local y = 1025.0 ]] or [[ print("foo");local y = 1025]] )
729756end )
730757
731758
0 commit comments