/// <summary>Test that multiple conf arguments can be used.</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestConfWithMultipleOpts()
        {
            string[] args = new string[2];
            args[0] = "--conf=foo";
            args[1] = "--conf=bar";
            GenericOptionsParser g = new GenericOptionsParser(args);

            Assert.Equal("1st conf param is incorrect", "foo", g.GetCommandLine
                             ().GetOptionValues("conf")[0]);
            Assert.Equal("2st conf param is incorrect", "bar", g.GetCommandLine
                             ().GetOptionValues("conf")[1]);
        }
Example #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestGenericOptionsParser()
        {
            GenericOptionsParser parser = new GenericOptionsParser(new Configuration(), new string
                                                                   [] { "-jt" });

            Assert.Equal(0, parser.GetRemainingArgs().Length);
            //  test if -D accepts -Dx=y=z
            parser = new GenericOptionsParser(new Configuration(), new string[] { "-Dx=y=z" }
                                              );
            Assert.Equal("Options parser gets entire ='s expresion", "y=z"
                         , parser.GetConfiguration().Get("x"));
        }
Example #3
0
        /// <summary>
        /// Runs the given <code>Tool</code> by
        /// <see cref="Tool.Run(string[])"/>
        /// , after
        /// parsing with the given generic arguments. Uses the given
        /// <code>Configuration</code>, or builds one if null.
        /// Sets the <code>Tool</code>'s configuration with the possibly modified
        /// version of the <code>conf</code>.
        /// </summary>
        /// <param name="conf"><code>Configuration</code> for the <code>Tool</code>.</param>
        /// <param name="tool"><code>Tool</code> to run.</param>
        /// <param name="args">command-line arguments to the tool.</param>
        /// <returns>
        /// exit code of the
        /// <see cref="Tool.Run(string[])"/>
        /// method.
        /// </returns>
        /// <exception cref="System.Exception"/>
        public static int Run(Configuration conf, Tool tool, string[] args)
        {
            if (conf == null)
            {
                conf = new Configuration();
            }
            GenericOptionsParser parser = new GenericOptionsParser(conf, args);

            //set the configuration back, so that Tool can configure itself
            tool.SetConf(conf);
            //get the args w/o generic hadoop args
            string[] toolArgs = parser.GetRemainingArgs();
            return(tool.Run(toolArgs));
        }
        /// <summary>Test that options passed to the constructor are used.</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestCreateWithOptions()
        {
            // Create new option newOpt
            Option  opt  = OptionBuilder.Create("newOpt");
            Options opts = new Options();

            opts.AddOption(opt);
            // Check newOpt is actually used to parse the args
            string[] args = new string[2];
            args[0] = "--newOpt";
            args[1] = "7";
            GenericOptionsParser g = new GenericOptionsParser(opts, args);

            Assert.Equal("New option was ignored", "7", g.GetCommandLine()
                         .GetOptionValues("newOpt")[0]);
        }
        /// <exception cref="System.Exception"/>
        private void AssertDOptionParsing(string[] args, IDictionary <string, string> expectedMap
                                          , string[] expectedRemainingArgs)
        {
            foreach (KeyValuePair <string, string> entry in expectedMap)
            {
                NUnit.Framework.Assert.IsNull(conf.Get(entry.Key));
            }
            Configuration        conf   = new Configuration();
            GenericOptionsParser parser = new GenericOptionsParser(conf, args);

            string[] remainingArgs = parser.GetRemainingArgs();
            foreach (KeyValuePair <string, string> entry_1 in expectedMap)
            {
                Assert.Equal(entry_1.Value, conf.Get(entry_1.Key));
            }
            Assert.AssertArrayEquals(Arrays.ToString(remainingArgs) + Arrays.ToString(expectedRemainingArgs
                                                                                      ), expectedRemainingArgs, remainingArgs);
        }
        /// <summary>Test passing null as args.</summary>
        /// <remarks>
        /// Test passing null as args. Some classes still call
        /// Tool interface from java passing null.
        /// </remarks>
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestNullArgs()
        {
            GenericOptionsParser parser = new GenericOptionsParser(conf, null);

            parser.GetRemainingArgs();
        }
Example #7
0
 /// <summary>Prints generic command-line argurments and usage information.</summary>
 /// <param name="out">stream to write usage information to.</param>
 public static void PrintGenericCommandUsage(TextWriter @out)
 {
     GenericOptionsParser.PrintGenericCommandUsage(@out);
 }