nitc :: CmdTesting :: defaultinit
# Cmd that finds the nitunit command related to an `mentity`
class CmdTesting
super CmdEntityList
var command: nullable String is lazy do
var results = self.results
if results == null then return null
var tpl = new Template
tpl.add "nitunit"
for result in results do
var path = test_path(result)
if path == null then continue
tpl.add " {path}"
end
return tpl.write_to_string
end
redef fun init_results do
if results != null then return new CmdSuccess
var res = super
if not res isa CmdSuccess then return res
var mentity = self.mentity.as(not null)
var mentities = new Array[MEntity]
if not mentity isa MPackage then return new WarningNoTest(mentity)
for mgroup in mentity.collect_all_mgroups(filter) do
if mgroup.is_test then
mentities.add mgroup
continue
end
for mmodule in mgroup.collect_mmodules(filter) do
if mmodule.is_test then mentities.add mmodule
end
end
if mentities.is_empty then return new WarningNoTest(mentity)
self.results = mentities
return res
end
# Return the mentity path
#
# This method exists for the only purpose to be redefined by nitunit tests
# to avoid path diffs.
private fun test_path(mentity: MEntity): nullable String do
var file = mentity.location.file
if file == null then return null
var base_path = self.mentity.as(not null).location.file.as(not null).filename
return file.filename.replace(base_path, "")
end
end
src/doc/commands/commands_main.nit:131,1--185,3