11-- ==============================================================
22-- =
33-- = Test suite for LuaPreprocess
4- -- = Note: The command line program tests expect the OS to be Windows!
54-- =
65-- ==============================================================
76
@@ -72,19 +71,15 @@ local function assertCodeOutput(codeOut, codeExpected, message)
7271 end
7372end
7473
75- -- command = createCommand( program, argumentsString )
76- local function createCommand (program , argsStr )
74+ -- command = createCommand( program, rest )
75+ local function createCommand (program , rest )
7776 return program :find (" " , 1 , true )
78- and ' ""' .. program .. ' " ' .. argsStr .. ' "'
79- or program .. ' ' .. argsStr
77+ and ' ""' .. program .. ' " ' .. rest .. ' "'
78+ or program .. ' ' .. rest
8079end
8180
82- -- runCommand( command )
83- -- runCommand( program, argumentsString )
84- -- runCommandToFail( command )
85- -- runCommandToFail( program, argumentsString )
86- local function _runCommand (program , argsStr , expectSuccess )
87- local cmd = not argsStr and program or createCommand (program , argsStr )
81+ local function _runCommand (program , rest , expectSuccess )
82+ local cmd = createCommand (program , rest )
8883 print (" Running command: " .. cmd )
8984
9085 if jit or _VERSION >= " Lua 5.2" then
@@ -99,11 +94,18 @@ local function _runCommand(program, argsStr, expectSuccess)
9994 else error (" Command succeeded unexpectedly: " .. cmd , 2 ) end
10095 end
10196end
102- local function runCommand (program , argsStr )
103- _runCommand (program , argsStr , true )
97+ local function runCommand (program , rest )
98+ _runCommand (program , rest , true )
10499end
105- local function runCommandToFail (program , argsStr )
106- _runCommand (program , argsStr , false )
100+ local function runCommandToFail (program , rest )
101+ _runCommand (program , rest , false )
102+ end
103+ local function runCommandAndSendData (luaExe , rest , dataStr )
104+ local cmd = createCommand (luaExe , rest )
105+ print (" Running command: " .. cmd )
106+ local handle = assert (io.popen (cmd , " w" ))
107+ handle :write (dataStr )
108+ handle :close ()
107109end
108110
109111local function requireNewTemp (moduleName )
@@ -793,10 +795,7 @@ doTest("Handler + multiple files", function()
793795end )
794796
795797doTest (" stdin and stdout" , function ()
796- local luaExeMaybeQuoted = luaExe :find (" " , 1 , true ) and ' "' .. luaExe .. ' "' or luaExe
797-
798- writeFile (" temp/generatedTest.lua2p" , [[ x = !(1+2) ]] )
799- runCommand ([[ TYPE temp\generatedTest.lua2p | ]] .. luaExeMaybeQuoted .. [[ preprocess-cl.lua - >temp\generatedTest.lua]] )
798+ runCommandAndSendData (luaExe , [[ preprocess-cl.lua - >temp\generatedTest.lua]] , [[ x = !(1+2) ]] )
800799 assertCodeOutput (readFile " temp/generatedTest.lua" , [[ x = 3]] )
801800end )
802801
0 commit comments