mirror of
https://github.com/aNNiMON/Own-Programming-Language-Tutorial.git
synced 2024-09-20 00:34:20 +03:00
167 lines
4.0 KiB
Scala
167 lines
4.0 KiB
Scala
/*
|
|
*
|
|
* Automatic run examples for testing.
|
|
* Have functions for special launch own scripts if need
|
|
*
|
|
*/
|
|
|
|
use ["date", "files", "robot", "std"]
|
|
|
|
DEBUG = true
|
|
EXAMPLES_DIR = "examples"
|
|
REPORT_PATH = "F:/report.txt"
|
|
EXEC_TEMPLATE = "cmd /U /C \"ownlang -f %s %s >> %s 2>&1\""
|
|
|
|
// Main list of examples. Contains predefined examples with custom executing params
|
|
listExamples = {
|
|
/* template
|
|
"program_name": {
|
|
"isRun": false,
|
|
"path": "" // relative path to program
|
|
"args": [], // additional args for run
|
|
"prelaunch": "", // pre-launch other application, e.g. start server
|
|
},
|
|
*/
|
|
"fx_basic_shapes.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"fx_event_handlers.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"fx_global_alpha.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"fx_image_negate.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"fx_image.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"fx_koch_snowflake.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"fx_rotation.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"okhttp_telegram_sendvoice.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"telegram_api.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"okhttp_imgur_upload.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"okhttp_websocket.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
"pipes_online.own": {
|
|
"isRun": false,
|
|
"path": ""
|
|
"args": [],
|
|
"prelaunch": "",
|
|
},
|
|
}
|
|
|
|
def debug(something) {
|
|
if !DEBUG return 0
|
|
|
|
println sprintf("[%s] %s", newDate(), something)
|
|
}
|
|
|
|
// Algorithm: get list of examples, filter and add to main list of examples
|
|
def readExamples() {
|
|
examplesDir = fopen(EXAMPLES_DIR, "")
|
|
dirs = listFiles(examplesDir)
|
|
|
|
for dir : dirs {
|
|
relativeDirPath = EXAMPLES_DIR + "/" + dir
|
|
subDir = fopen(relativeDirPath, "")
|
|
if (!isDirectory(subDir) || dir == "." || dir == "..") continue
|
|
files = listFiles(subDir)
|
|
for file : files {
|
|
if (indexOf(file, ".own") < 0 || dir == "." || dir == "..") {
|
|
debug(file + "not ownlang application or sub directory")
|
|
continue
|
|
}
|
|
if (arrayKeyExists(file, listExamples)) {
|
|
debug(file + " exists in main list")
|
|
continue
|
|
}
|
|
program = {
|
|
"isRun": true,
|
|
"path": relativeDirPath + "/" + file
|
|
"args": [],
|
|
"prelaunch": "",
|
|
}
|
|
listExamples[file] = program
|
|
}
|
|
}
|
|
return listExamples
|
|
}
|
|
|
|
readExamples()
|
|
|
|
// remove old report
|
|
if exists(REPORT_PATH) {
|
|
delete(REPORT_PATH)
|
|
}
|
|
|
|
// main task
|
|
for name, program : listExamples {
|
|
if !program.isRun {
|
|
println "Skip: " + name
|
|
continue
|
|
}
|
|
|
|
println "Executing: " + name
|
|
|
|
reportBeforeExec = sprintf("cmd /U /C \"echo %s\n >> %s", program.path, REPORT_PATH)
|
|
execProcessAndWait(reportBeforeExec)
|
|
|
|
if length(trim(program.prelaunch)) > 0 {
|
|
println "Pre-launch: " + program.pre-launch
|
|
execProcessAndWait(program.pre-launch)
|
|
}
|
|
|
|
execString = sprintf(EXEC_TEMPLATE, program.path, join(program.args, " "), REPORT_PATH)
|
|
debug(execString)
|
|
exitCode = execProcessAndWait(execString)
|
|
println "Exit code: " + exitCode
|
|
|
|
reportAfterExec = sprintf("cmd /U /C \"echo %s\n >> %s", "*"*19, REPORT_PATH)
|
|
execProcessAndWait(reportAfterExec)
|
|
} |