Used for docunits simple block of code (without modules, classes, functions etc.)
In case of success, the docunits are compiled and the caller can call execute_simple_docunit
.
In case of compilation error, the docunits are let uncompiled.
The caller should fallbacks to test_single_docunit
to
# Compiles multiples doc-units in a shared program.
# Used for docunits simple block of code (without modules, classes, functions etc.)
#
# In case of success, the docunits are compiled and the caller can call `execute_simple_docunit`.
#
# In case of compilation error, the docunits are let uncompiled.
# The caller should fallbacks to `test_single_docunit` to
# * locate exactly the compilation problem in the problematic docunit.
# * permit the execution of the other docunits that may be correct.
fun compile_simple_docunits(dus: Array[DocUnit])
do
if dus.is_empty then return
var file = "{prefix}-0.nit"
toolcontext.info("Compile {dus.length} simple(s) doc-unit(s) in {file}", 1)
var dir = file.dirname
if dir != "" then dir.mkdir
var f
f = create_unitfile(file)
var i = 0
for du in dus do
i += 1
f.write("fun run_{i} do\n")
f.write("# {du.full_name}\n")
f.write(du.block)
f.write("end\n")
end
f.write("var a = args.first.to_i\n")
for j in [1..i] do
f.write("if a == {j} then run_{j}\n")
end
f.close
if toolcontext.opt_noact.value then return
var res = compile_unitfile(file)
if res != 0 then
# Compilation error.
# They should be generated and compiled independently
return
end
# Compilation was a success.
# Store what need to be executed for each one.
i = 0
for du in dus do
i += 1
du.test_file = file
du.test_arg = i
du.is_compiled = true
end
end
src/testing/testing_doc.nit:150,2--204,4