-
- # Execute a block
- fun test_block(ndoc: ADoc, tc: HTMLTag, block: Array[String])
- do
- toolcontext.modelbuilder.unit_entities += 1
-
- cpt += 1
- var file = "{prefix}{cpt}.nit"
-
- toolcontext.info("Execute {tc.attrs["name"]} in {file}", 1)
-
- var dir = file.dirname
- if dir != "" then dir.mkdir
- var f
- f = new OFStream.open(file)
- f.write("# GENERATED FILE\n")
- f.write("# Example extracted from a documentation\n")
- f.write("import {mmodule.name}\n")
- f.write("\n")
- for text in block do
- f.write(text)
- end
- f.close
-
- if toolcontext.opt_noact.value then return
-
- var nit_dir = toolcontext.nit_dir
- var nitg = "{nit_dir or else ""}/bin/nitg"
- if nit_dir == null or not nitg.file_exists then
- toolcontext.error(null, "Cannot find nitg. Set envvar NIT_DIR.")
- toolcontext.check_errors
- end
- var cmd = "{nitg} --ignore-visibility --no-color '{file}' -I {mmodule.location.file.filename.dirname} >'{file}.out1' 2>&1 </dev/null -o '{file}.bin'"
- var res = sys.system(cmd)
- var res2 = 0
- if res == 0 then
- res2 = sys.system("./{file}.bin >>'{file}.out1' 2>&1 </dev/null")
- end
-
- var msg
- f = new IFStream.open("{file}.out1")
- var n2
- n2 = new HTMLTag("system-err")
- tc.add n2
- msg = f.read_all
- f.close
-
- n2 = new HTMLTag("system-out")
- tc.add n2
- for text in block do n2.append(text)
-
-
- if res != 0 then
- var ne = new HTMLTag("failure")
- ne.attr("message", msg)
- tc.add ne
- toolcontext.warning(ndoc.location, "FAILURE: {tc.attrs["classname"]}.{tc.attrs["name"]} (in {file}): {msg}")
- toolcontext.modelbuilder.failed_entities += 1
- else if res2 != 0 then
- var ne = new HTMLTag("error")
- ne.attr("message", msg)
- tc.add ne
- toolcontext.warning(ndoc.location, "ERROR: {tc.attrs["classname"]}.{tc.attrs["name"]} (in {file}): {msg}")
- toolcontext.modelbuilder.failed_entities += 1
- end
- toolcontext.check_errors
-
- testsuite.add(tc)