doc/commands: term handles `commands_main`
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 2 May 2018 23:34:43 +0000 (19:34 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 10 May 2018 20:35:10 +0000 (16:35 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/term/term.nit
src/doc/term/tests/test_term.nit
src/doc/term/tests/test_term.sav/test_term_catalog_stats.res
src/doc/term/tests/test_term.sav/test_term_main_compile.res [new file with mode: 0644]
src/doc/term/tests/test_term.sav/test_term_mains.res [new file with mode: 0644]
src/doc/term/tests/test_term.sav/test_term_man_options.res [new file with mode: 0644]
src/doc/term/tests/test_term.sav/test_term_man_synopsis.res [new file with mode: 0644]
src/doc/term/tests/test_term.sav/test_term_testing.res [new file with mode: 0644]

index b88a340..58ad127 100644 (file)
@@ -452,3 +452,91 @@ redef class CmdContribFile
                print_file("Contributing rules from", no_color)
        end
 end
+
+# CmdMain
+
+redef class CmdMains
+       redef fun execute(no_color) do
+               var mentity = self.mentity.as(not null).full_name
+               if no_color == null or not no_color then mentity = mentity.blue.bold
+               print_list("Mains in `{mentity}`:", results, no_color)
+       end
+end
+
+redef class CmdMainCompile
+       redef fun execute(no_color) do
+               var mentity = self.mentity.as(not null).full_name
+               if no_color == null or not no_color then mentity = mentity.blue.bold
+               var title = "Compiling `{mentity}`:"
+
+               if no_color == null or not no_color then
+                       print title.bold
+               else
+                       print title
+               end
+
+               print ""
+               var command = self.command
+               if command != null then print command
+       end
+end
+
+redef class CmdTesting
+       redef fun execute(no_color) do
+               var mentity = self.mentity.as(not null).full_name
+               if no_color == null or not no_color then mentity = mentity.blue.bold
+               var title = "Testing `{mentity}`:"
+
+               if no_color == null or not no_color then
+                       print title.bold
+               else
+                       print title
+               end
+
+               print ""
+               var command = self.command
+               if command != null then print command
+       end
+end
+
+redef class CmdManSynopsis
+       redef fun execute(no_color) do
+               var mentity = self.mentity.as(not null).full_name
+               if no_color == null or not no_color then mentity = mentity.blue.bold
+               var title = "Synopsis for `{mentity}`:"
+
+               if no_color == null or not no_color then
+                       print title.bold
+               else
+                       print title
+               end
+
+               print ""
+               var synopsis = self.synopsis
+               if synopsis != null then print synopsis
+       end
+end
+
+redef class CmdManOptions
+       redef fun execute(no_color) do
+               var mentity = self.mentity.as(not null).full_name
+               if no_color == null or not no_color then mentity = mentity.blue.bold
+               var title = "Options for `{mentity}`:"
+
+               if no_color == null or not no_color then
+                       print title.bold
+               else
+                       print title
+               end
+
+               print ""
+               var options = self.options.as(not null)
+               for opt, desc in options do
+                       if no_color == null or not no_color then
+                               print " * {opt.blue.bold}: {desc}"
+                       else
+                               print " * {opt}: {desc}"
+                       end
+               end
+       end
+end
index e0d0e62..997037c 100644 (file)
@@ -15,6 +15,7 @@
 module test_term is test
 
 import term
+intrude import commands::commands_main
 import commands::test_commands_catalog
 
 # Nitunit test suite specific to commands
@@ -231,9 +232,53 @@ class TestTerm
                var parser = new CommandParser(test_view, test_builder, test_catalog)
                parser.execute("ini-license: test_prog", true)
        end
+
+       # CmdMain
+
+       fun test_term_mains is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               parser.execute("mains: test_prog", true)
+       end
+
+       fun test_term_main_compile is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               parser.execute("main-compile: test_prog::test_prog", true)
+       end
+
+       fun test_term_man_synopsis is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               parser.execute("main-run: test_prog::test_prog", true)
+       end
+
+       fun test_term_man_options is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               parser.execute("main-opts: test_prog::test_prog", true)
+       end
+
+       fun test_term_testing is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               parser.execute("testing: test_prog", true)
+       end
 end
 
 redef class nitc::Location
        # Avoid location diffs
        redef fun to_s do return "test_location"
 end
+
+# Avoid path diff
+redef class CmdMainCompile
+       redef fun test_path(file) do
+               if file == null then return null
+               return file.filename.basename
+       end
+end
+
+# Avoid path diff
+redef class CmdTesting
+       redef fun test_path(mentity) do
+               var file = mentity.location.file
+               if file == null then return null
+               return file.filename.basename
+       end
+end
index 3f34348..18f7bdc 100644 (file)
@@ -3,7 +3,7 @@ Catalog statistics:
  * 11 modules
  * 78 methods
  * 25 classes
- * 502 lines of code
+ * 503 lines of code
  * 6 contributors
  * 1 maintainers
  * 2 tags
diff --git a/src/doc/term/tests/test_term.sav/test_term_main_compile.res b/src/doc/term/tests/test_term.sav/test_term_main_compile.res
new file mode 100644 (file)
index 0000000..fdcc93b
--- /dev/null
@@ -0,0 +1,3 @@
+Compiling `test_prog::test_prog`:
+
+nitc test_prog.nit
diff --git a/src/doc/term/tests/test_term.sav/test_term_mains.res b/src/doc/term/tests/test_term.sav/test_term_mains.res
new file mode 100644 (file)
index 0000000..f72eff0
--- /dev/null
@@ -0,0 +1,7 @@
+Mains in `test_prog`:
+
+ + test_prog::test_prog
+   # A test program with a fake model to check model tools.
+   module test_prog
+   test_location
+
diff --git a/src/doc/term/tests/test_term.sav/test_term_man_options.res b/src/doc/term/tests/test_term.sav/test_term_man_options.res
new file mode 100644 (file)
index 0000000..71b984b
--- /dev/null
@@ -0,0 +1,4 @@
+Options for `test_prog::test_prog`:
+
+ * --opt1: Option 1.
+ * --opt2: Option 2.
diff --git a/src/doc/term/tests/test_term.sav/test_term_man_synopsis.res b/src/doc/term/tests/test_term.sav/test_term_man_synopsis.res
new file mode 100644 (file)
index 0000000..f58027d
--- /dev/null
@@ -0,0 +1,3 @@
+Synopsis for `test_prog::test_prog`:
+
+test_prog [*options*] ARGS...
diff --git a/src/doc/term/tests/test_term.sav/test_term_testing.res b/src/doc/term/tests/test_term.sav/test_term_testing.res
new file mode 100644 (file)
index 0000000..bef162c
--- /dev/null
@@ -0,0 +1,3 @@
+Testing `test_prog`:
+
+nitunit tests