public void Test_BuildFileOption() { string filename = "file1.ha"; string baseDirectory = TempDir.Create(Path.Combine(TempDirName, "foo")); string build1FileName = TempFile.CreateWithContents("<project/>", Path.Combine(baseDirectory, filename)); string oldCurrDir = Environment.CurrentDirectory; Environment.CurrentDirectory = baseDirectory; using (ConsoleCapture c = new ConsoleCapture()) { bool errors = false; try { //check filename only, should be resolvable via currentdirectory Assert.IsTrue(0 == ConsoleDriver.Main(new string[] { "-buildfile:" + filename }), "Using filepath failed"); //check absolute Assert.IsTrue(0 == ConsoleDriver.Main(new string[] { @"-buildfile:" + build1FileName }), "Using absolute filepath failed"); //check relative path, should be resolvable via currentdirectory Assert.IsTrue(0 == ConsoleDriver.Main(new string[] { string.Format("-buildfile:.{0}{1}", Path.DirectorySeparatorChar, filename) }), "Using relative filepath failed #1"); //check relative path, should be resolvable via currentdirectory Assert.IsTrue(0 == ConsoleDriver.Main(new string[] { string.Format("-buildfile:..{0}foo{0}{1}", Path.DirectorySeparatorChar, filename) }), "Using relative filepath failed #2"); } catch (Exception e) { e.ToString(); errors = true; throw; } finally { string results = c.Close(); if (errors) { System.Console.Write(results); } } } Environment.CurrentDirectory = oldCurrDir; }
public void Test_MissingNameForNameValuePair() { string[] args = { "-D:test=", "-D:test=" }; string result = null; using (ConsoleCapture c = new ConsoleCapture()) { ConsoleDriver.Main(args); result = c.Close(); } // using a regular expression to check for correct error message string expression = @"Duplicate property named 'test' for command-line argument 'D'."; Match match = Regex.Match(result, expression); Assert.IsTrue(match.Success, "Argument did not cause an error: " + result); }
public void Test_MissingValueForNameValuePair() { string[] args = { "-D:test", "-D:test" }; string result = null; using (ConsoleCapture c = new ConsoleCapture()) { ConsoleDriver.Main(args); result = c.Close(); } // using a regular expression to check for correct error message string expression = @"Expected name\/value pair \(<name>=<value>\)."; Match match = Regex.Match(result, expression); Assert.IsTrue(match.Success, "Argument did not cause an error: " + result); }
public void Test_DuplicateCollectionValue() { string[] args = { "-listener:test", "-listener:test" }; string result = null; using (ConsoleCapture c = new ConsoleCapture()) { ConsoleDriver.Main(args); result = c.Close(); } // using a regular expression to check for correct error message string expression = @"Duplicate value 'test' for command-line argument '-listener'."; Match match = Regex.Match(result, expression); Assert.IsTrue(match.Success, "Argument did not cause an error: " + result); }
public void Test_UnknownArgument() { string[] args = { "-asdf", "-help", "-verbose" }; string result = null; using (ConsoleCapture c = new ConsoleCapture()) { ConsoleDriver.Main(args); result = c.Close(); } // using a regular expression to check for correct error message string expression = @"Unknown argument '-asdf'"; Match match = Regex.Match(result, expression); Assert.IsTrue(match.Success, "Argument did not cause an error: " + result); }
public void Test_DefineProperty() { string buildFileContents = @"<?xml version='1.0' ?> <project name='Test' default='test' basedir='.'> <target name='test'> <property name='project.name' value='Foo.Bar' overwrite='false' /> <echo message='project.name = ${project.name}'/> </target> </project>"; // write build file to temp file string buildFileName = CreateTempFile("buildfile.xml", buildFileContents); Assert.IsTrue(File.Exists(buildFileName), buildFileName + " does not exist."); string[] args = { "-D:project.name=MyCompany.MyProject", String.Format("-buildfile:{0}", buildFileName), }; string result = null; using (ConsoleCapture c = new ConsoleCapture()) { ConsoleDriver.Main(args); result = c.Close(); } // regular expression to look for expected output string expression = @"project.name = MyCompany.MyProject"; Match match = Regex.Match(result, expression); Assert.IsTrue(match.Success, "Property 'project.name' appears to have been overridden by <property> task." + Environment.NewLine + result); // delete the build file File.Delete(buildFileName); Assert.IsFalse(File.Exists(buildFileName), buildFileName + " exists."); }
public void Test_ShowHelp() { string[] args = { "-help" }; string result = null; using (ConsoleCapture c = new ConsoleCapture()) { ConsoleDriver.Main(args); result = c.Close(); } // using a regular expression look for a plausible version number and valid copyright date string expression = @"^NAnt (?<infoMajor>[0-9]+).(?<infoMinor>[0-9]+) " + @"\(Build (?<buildMajor>[0-9]+).(?<buildMinor>[0-9]+).(?<buildBuild>[0-9]+).(?<buildRevision>[0-9]+); " + @"(?<configuration>.*); (?<releasedate>.*)\)" + ".*\n" + @"Copyright \(C\) 2001-(?<year>20[0-9][0-9]) Gerry Shaw"; Match match = Regex.Match(result, expression); Assert.IsTrue(match.Success, "Help text does not appear to be valid."); int infoMajor = Int32.Parse(match.Groups["infoMajor"].Value); int infoMinor = Int32.Parse(match.Groups["infoMinor"].Value); int buildMajor = Int32.Parse(match.Groups["buildMajor"].Value); int buildMinor = Int32.Parse(match.Groups["buildMinor"].Value); int buildBuild = Int32.Parse(match.Groups["buildBuild"].Value); int buildRevision = Int32.Parse(match.Groups["buildRevision"].Value); int year = Int32.Parse(match.Groups["year"].Value); Assert.IsTrue(infoMajor >= 0, "Version numbers must be positive."); Assert.IsTrue(infoMinor >= 0, "Version numbers must be positive."); Assert.IsTrue(buildMajor >= 0, "Version numbers must be positive."); Assert.IsTrue(buildMinor >= 0, "Version numbers must be positive."); Assert.IsTrue(buildBuild >= 0, "Version numbers must be positive."); Assert.IsTrue(buildRevision >= 0, "Version numbers must be positive."); Assert.IsTrue(year <= DateTime.Now.Year, "Copyright year should be equal or less than current year."); }