Skip to content

Commit 83bc137

Browse files
committed
Update WurstScriptTest.java
1 parent cfc2606 commit 83bc137

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/WurstScriptTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,10 +473,11 @@ private void translateAndTestLua(String name, boolean executeProg, WurstGui gui,
473473
FileUtils.write(luaScript, luaFile);
474474

475475
// run with lua -l SimpleStatementTests_testIf1 -e 'main()'
476+
String luaExecutable = getLuaExecutable();
477+
checkLuaSyntax(luaExecutable, luaFile);
476478

477479
if (executeProg) {
478480
String line;
479-
String luaExecutable = getLuaExecutable();
480481
String[] args = {
481482
luaExecutable,
482483
"-l", luaFile.getPath().replace(".lua", ""),
@@ -520,6 +521,26 @@ private void translateAndTestLua(String name, boolean executeProg, WurstGui gui,
520521

521522
}
522523

524+
private void checkLuaSyntax(String luaExecutable, File luaFile) throws IOException {
525+
String[] args = {
526+
luaExecutable,
527+
"-e", "assert(loadfile(arg[1]))",
528+
luaFile.getPath()
529+
};
530+
Process p = Runtime.getRuntime().exec(args);
531+
532+
StringBuilder errors = new StringBuilder();
533+
String line;
534+
try (BufferedReader input = new BufferedReader(new InputStreamReader(p.getErrorStream()))) {
535+
while ((line = input.readLine()) != null) {
536+
errors.append(line).append("\n");
537+
}
538+
}
539+
if (errors.length() > 0) {
540+
throw new Error("Lua syntax check failed for " + luaFile.getName() + ":\n" + errors);
541+
}
542+
}
543+
523544
private String getLuaExecutable() {
524545
File bundledLuaWin = new File("src/test/resources/lua53.exe");
525546
if (bundledLuaWin.exists()) {

0 commit comments

Comments
 (0)