doc/commands: parse `commands_main`
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 2 May 2018 23:18:04 +0000 (19:18 -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/commands/commands_parser.nit
src/doc/commands/tests/test_commands_parser.nit

index 7ae94e2..77fdd25 100644 (file)
@@ -22,6 +22,7 @@ import commands::commands_graph
 import commands::commands_usage
 import commands::commands_catalog
 import commands::commands_ini
+import commands::commands_main
 
 # Parse string commands to create DocQueries
 class CommandParser
@@ -42,6 +43,7 @@ class CommandParser
        "param", "return", "new", "call", "defs", "list", "random",
        "ini-desc", "ini-git", "ini-issues", "ini-maintainer", "ini-contributors", "ini-license",
        "license-file", "contrib-file", "license-content", "contrib-content", "git-clone",
+       "mains", "main-compile", "main-run", "main-opts", "testing",
        "catalog", "stats", "tags", "tag", "person", "contrib", "maintain"] is writable
 
        # List of commands usage and documentation
@@ -83,6 +85,12 @@ class CommandParser
                usage["contrib-file: <package>"] = "display the contrib file for the `package`"
                usage["contrib-content: <package>"] = "display the contrib file content for the `package`"
                usage["git-clone: <package>"] = "display the git clone command for the `package`"
+               # Main
+               usage["mains: <name>"] = "display the list of main methods for `name`"
+               usage["main-compile: <name>"] = "display the nitc command to compile `name`"
+               usage["main-run: <name>"] = "display the command to run `name`"
+               usage["main-opts: <name>"] = "display the command options for `name`"
+               usage["testing: <name>"] = "display the nitunit command to test `name`"
                return usage
        end
 
@@ -201,6 +209,12 @@ class CommandParser
                if name == "contrib-file" then return new CmdContribFile(view)
                if name == "contrib-content" then return new CmdContribFileContent(view)
                if name == "git-clone" then return new CmdIniCloneCommand(view)
+               # CmdMain
+               if name == "mains" then return new CmdMains(view)
+               if name == "main-compile" then return new CmdMainCompile(view)
+               if name == "main-run" then return new CmdManSynopsis(view)
+               if name == "main-opts" then return new CmdManOptions(view)
+               if name == "testing" then return new CmdTesting(view)
                # CmdCatalog
                var catalog = self.catalog
                if catalog != null then
index d59b445..e9f299c 100644 (file)
@@ -179,7 +179,7 @@ class TestCommandsParser
                var cmd = parser.parse("descendants: Object")
                assert cmd isa CmdDescendants
                assert parser.error == null
-               assert cmd.results.as(not null).length == 20
+               assert cmd.results.as(not null).length == 22
        end
 
        fun test_cmd_parser_descendants_without_children is test do
@@ -187,7 +187,7 @@ class TestCommandsParser
                var cmd = parser.parse("descendants: Object | children: false")
                assert cmd isa CmdDescendants
                assert parser.error == null
-               assert cmd.results.as(not null).length == 8
+               assert cmd.results.as(not null).length == 9
        end
 
        # CmdSearch
@@ -504,4 +504,63 @@ class TestCommandsParser
                assert content != null
                assert not content.is_empty
        end
+
+       # CmdMain
+
+       fun test_cmd_parser_mains is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("mains: test_prog")
+               assert cmd isa CmdMains
+               assert parser.error == null
+
+               var results = cmd.results
+               assert results != null
+               assert results.length == 1
+               assert results.first.full_name == "test_prog::test_prog"
+       end
+
+       fun test_cmd_parser_main_compile is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("main-compile: test_prog::test_prog")
+               assert cmd isa CmdMainCompile
+               assert parser.error == null
+
+               var command = cmd.command
+               assert command != null
+               assert command.has_prefix("nitc ")
+               assert command.has_suffix("test_prog.nit")
+       end
+
+       fun test_cmd_parser_testing is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("testing: test_prog")
+               assert cmd isa CmdTesting
+               assert parser.error == null
+
+               var command = cmd.command
+               assert command != null
+               assert command.has_prefix("nitunit ")
+               assert command.has_suffix("/tests")
+       end
+
+       fun test_cmd_man_synopsis is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("main-run: test_prog")
+               assert cmd isa CmdManSynopsis
+               assert parser.error == null
+
+               assert cmd.synopsis == "test_prog [*options*] ARGS..."
+       end
+
+       fun test_cmd_man_opions is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("main-opts: test_prog")
+               assert cmd isa CmdManOptions
+               assert parser.error == null
+
+               var options = cmd.options
+               assert options != null
+               assert options["--opt1"] == "Option 1."
+               assert options["--opt2"] == "Option 2."
+       end
 end