PDA

View Full Version : Quick script tester


pww
01-20-2009, 05:54 PM
A friend asked me today how to quickly test pieces of script code. He said he's rebuilding a ~600 MB installer tens of times to test minor changes in script code.

It's really simple, but may be useful for someone.
In the On Startup script of an empty project, put a code like this



-- ################## LUA SCRIPT TESTER ############
if _CommandLineArgs ~= nil and Table.Count(_CommandLineArgs) > 0 then
if File.DoesExist(_CommandLineArgs[1]) then
testFile = _CommandLineArgs[1];
else
Dialog.Message("Error", "Invalid argument:" .. _CommandLineArgs[1], MB_OK, MB_ICONEXCLAMATION);
Application.Exit();
end;
else
testFile = _SourceFolder .. "\\test.lua";
end;

if File.DoesExist(testFile) then
require(testFile);
else
Dialog.Message("Error", "File not found:" .. testFile, MB_OK, MB_ICONEXCLAMATION);
end
Application.Exit();
-- ##################################################



and build the project (it does not need to have screens, uninstaller etc.)
Name the generated exe LuaScriptTester.exe or alike

Then you can use this .exe to quickly test pieces of SF script code outside SF, without the need to build a setup etc. - it will read and execute script code from a text file.
If you pass a full local file path to it as an argument, it will execute the script code in the file (if the path contains spaces, it should be enclosed in double "..." quotes). This way you can test code you write in editors like UltraEdit.
If there are no arguments supplied, it will execute the code in the file test.lua, located in the same folder where the exe is.

Of course this can't be used for testing just any code, like code related to screens in your projects etc. - for this you have to build a setup and test it.
But for stuff like testing registry or file reads/writes and many others, or just to see how some script action works, it may be useful.