-
- # used to generate distinct names
- var cpt = 0
-
- # The entry point for a new `ndoc` node
- # Fill the prepated `tc` (testcase) XTM node
- fun extract(ndoc: ADoc, tc: HTMLTag)
- do
- block.clear
-
- work(ndoc.to_mdoc)
-
- if block.is_empty then return
-
- toolcontext.modelbuilder.unit_entities += 1
-
- cpt += 1
- var file = "{prefix}{cpt}.nit"
-
- toolcontext.info("Execute {tc.attrs["classname"]}.{tc.attrs["name"]} in {file}", 2)
-
- 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")
- var modname = self.modname
- f.write("import {modname}\n")
- f.write("\n")
- for text in block do
- f.write(text)
- end
- f.close
-
- var nit_dir = toolcontext.nit_dir
- var nitg = "{nit_dir}/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 . >'{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)