Ejemplo n.º 1
0
        // false if no tests found.
        private static bool PostProcessTests(CommandLineArguments args, string outputDir)
        {
            //////////////////////////////////////////////////////////////////////
            // Determine directory where generated tests were written.

            DirectoryInfo resultsDir = new DirectoryInfo(outputDir);

            //////////////////////////////////////////////////////////////////////
            // Collect all tests generated.

            Collection <FileInfo> tests = TestCaseUtils.CollectFilesEndingWith(".cs", resultsDir);

            if (tests.Count == 0)
            {
                return(false);
            }

            Dictionary <TestCase.ExceptionDescription, Collection <FileInfo> > classifiedTests =
                TestCaseUtils.ClassifyTestsByMessage(tests);

            PrintStats(classifiedTests);

            //////////////////////////////////////////////////////////////////////
            // Create stats file.

            StatsManager.ComputeStats(resultsDir + "\\allstats.txt",
                                      TestCaseUtils.CollectFilesEndingWith(".stats.txt", resultsDir));

            //////////////////////////////////////////////////////////////////////
            // Create HTML index.

            //HtmlSummary.CreateIndexHtml(classifiedTests, resultsDir + "\\index.html", args.ToString());
            HtmlSummary.CreateIndexHtml2(classifiedTests, resultsDir + "\\index.html", args.ToString());

            Console.WriteLine();
            Console.WriteLine("Results written to " + resultsDir + ".");
            Console.WriteLine("You can browse the results by opening the file "
                              + System.Environment.NewLine
                              + "   " + resultsDir + "\\index.html");

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Main randoop entrypoint.
        /// </summary>
        static void Main(string[] args)
        {
            Console.WriteLine();
            Console.WriteLine("Randoop.NET: an API fuzzer for .Net. Version {0} (compiled {1}).",
                              Common.Enviroment.RandoopVersion, Common.Enviroment.RandoopCompileDate);

            if (args.Length == 0 || IsHelpCommand(args[0]))
            {
                Console.Error.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(1);
            }

            if (ContainsHelp(args))
            {
                Console.WriteLine(HelpScreen.Usagestring());
                System.Environment.Exit(0);
            }

            if (args[0].Equals("/about"))
            {
                WriteAboutMessageToConsole();
                System.Environment.Exit(0);
            }

            if (args[0].Equals("minimize"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.Minimize(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                Collection <FileInfo> oldTests = TestCaseUtils.CollectFilesEndingWith(".cs", args2);
                Console.WriteLine("Number of original tests: " + oldTests.Count);
                Collection <FileInfo> newTests = TestCaseUtils.Reduce(oldTests);
                Console.WriteLine("Number of reduced tests: " + newTests.Count);
                Dictionary <TestCase.ExceptionDescription, Collection <FileInfo> > classifiedTests =
                    TestCaseUtils.ClassifyTestsByMessage(newTests);
                PrintStats(classifiedTests);
                StringBuilder b = new StringBuilder();
                foreach (string s in args)
                {
                    b.Append(" " + s);
                }
                string htmlFileName = "reduced" + Path.GetRandomFileName() + ".html";
                HtmlSummary.CreateIndexHtml(classifiedTests, htmlFileName, b.ToString());
                OpenExplorer(htmlFileName);
                System.Environment.Exit(0);
            }

            if (args[0].Equals("reproduce"))
            {
                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);
                TestCaseUtils.ReproduceBehavior(TestCaseUtils.CollectFilesEndingWith(".cs", args2));
                System.Environment.Exit(0);
            }

            if (args[0].StartsWith("stats:"))
            {
                string statsResultsFileName = args[0].Substring("stats:".Length);

                string[] args2 = new string[args.Length - 1];
                Array.Copy(args, 1, args2, 0, args.Length - 1);

                StatsManager.ComputeStats(statsResultsFileName,
                                          TestCaseUtils.CollectFilesEndingWith(".stats.txt", args2));
                System.Environment.Exit(0);
            }

            GenerateTests(args);
        }