Exemplo n.º 1
0
        /* Function: TestFolder
         * Tests all the input files contained in this folder.  See <EngineInstanceManager.Start()> for how relative paths are handled.
         */
        public void TestFolder(Path testDataFolder, Path projectConfigFolder = default(Path))
        {
            TestList allTests = new TestList();

            engineInstanceManager = new EngineInstanceManager();
            engineInstanceManager.Start(testDataFolder, projectConfigFolder);

            // Store this so we can still use it for error messages after the engine is disposed of.
            Path inputFolder = engineInstanceManager.InputFolder;

            try
            {
                // Build a test for each input file we find
                string[] files = System.IO.Directory.GetFiles(inputFolder);

                foreach (string file in files)
                {
                    if (Test.IsInputFile(file))
                    {
                        Test test = Test.FromInputFile(file);

                        try
                        {
                            string[] input = System.IO.File.ReadAllLines(test.InputFile);
                            test.SetActualOutput(OutputOf(input));
                        }
                        catch (Exception e)
                        { test.TestException = e; }

                        test.Run();
                        allTests.Add(test);
                    }
                }
            }

            finally
            {
                engineInstanceManager.Dispose();
                engineInstanceManager = null;
            }


            if (allTests.Count == 0)
            {
                Assert.Fail("There were no tests found in " + inputFolder);
            }
            else if (allTests.Passed == false)
            {
                Assert.Fail(allTests.BuildFailureMessage());
            }
        }
Exemplo n.º 2
0
        /* Function: TestFolder
         *
         * Tests all the input files contained in this folder.  See <EngineInstanceManager.Start()> for how relative paths are handled.
         *
         * Unless you override <ExtractHTML()>, the output will be all the tags that match the passed tag name and, if specified, the
         * passed class name.
         */
        public void TestFolder(Path testDataFolder, Path projectConfigFolder, string tagName, string className = null,
                               bool reformatHTML = false, string outputTitle = null, string outputSubtitle = null)
        {
            TestList allTests = new TestList();

            engineInstanceManager = new EngineInstanceManager();
            engineInstanceManager.Start(testDataFolder, projectConfigFolder, true, outputTitle, outputSubtitle);

            // Store this so we can still use it for error messages after the engine is disposed of.
            Path inputFolder = engineInstanceManager.InputFolder;

            try
            {
                engineInstanceManager.Run();

                // Build a test for each input file we find
                string[] files = System.IO.Directory.GetFiles(inputFolder);

                foreach (string file in files)
                {
                    if (Test.IsInputFile(file))
                    {
                        Test test = Test.FromInputFile(file);

                        try
                        {
                            var fileInfo = EngineInstance.Files.FromPath(file);

                            if (fileInfo == null)
                            {
                                throw new Exception("Could not get file info of " + file);
                            }

                            Engine.Output.Components.HTMLTopicPages.File fileTopicPage =
                                new Engine.Output.Components.HTMLTopicPages.File(engineInstanceManager.HTMLBuilder, fileInfo.ID);

                            Path htmlFile = fileTopicPage.OutputFile;

                            string html = System.IO.File.ReadAllText(htmlFile);
                            html = ExtractHTML(html, tagName, className);

                            if (reformatHTML)
                            {
                                html = ReformatHTML(html);
                            }

                            test.SetActualOutput(html);
                        }
                        catch (Exception e)
                        { test.TestException = e; }

                        test.Run();
                        allTests.Add(test);
                    }
                }
            }

            finally
            {
                engineInstanceManager.Dispose();
                engineInstanceManager = null;
            }


            if (allTests.Count == 0)
            {
                Assert.Fail("There were no tests found in " + inputFolder);
            }
            else if (allTests.Passed == false)
            {
                Assert.Fail(allTests.BuildFailureMessage());
            }
        }
Exemplo n.º 3
0
        /* Function: TestFolder
         * Tests all the input files contained in this folder.  See <EngineInstanceManager.Start()> for how relative paths are handled.
         */
        public void TestFolder(Path testDataFolder, Path projectConfigFolder = default(Path))
        {
            TestList allTests = new TestList();

            engineInstanceManager = new EngineInstanceManager();
            engineInstanceManager.Start(testDataFolder, projectConfigFolder);

            // Store this so we can still use it for error messages after the engine is disposed of.
            Path inputFolder = engineInstanceManager.InputFolder;

            try
            {
                // Build a test for each input file we find
                string[] files = System.IO.Directory.GetFiles(inputFolder);

                foreach (string file in files)
                {
                    if (Test.IsInputFile(file))
                    {
                        Test test = Test.FromInputFile(file);

                        try
                        {
                            Language language = EngineInstance.Languages.FromExtension(test.InputFile.Extension);

                            if (language == null)
                            {
                                throw new Exception("Extension " + test.InputFile.Extension + " did not resolve to a language.");
                            }

                            string         code          = System.IO.File.ReadAllText(test.InputFile);
                            Tokenizer      tokenizedCode = new Tokenizer(code);
                            List <Element> codeElements  = language.GetCodeElements(tokenizedCode);

                            if (codeElements == null)
                            {
                                throw new Exception("GetCodeElements() returned null.");
                            }

                            test.SetActualOutput(OutputOf(codeElements));
                        }
                        catch (Exception e)
                        { test.TestException = e; }

                        test.Run();
                        allTests.Add(test);
                    }
                }
            }

            finally
            {
                engineInstanceManager.Dispose();
                engineInstanceManager = null;
            }


            if (allTests.Count == 0)
            {
                Assert.Fail("There were no tests found in " + inputFolder);
            }
            else if (allTests.Passed == false)
            {
                Assert.Fail(allTests.BuildFailureMessage());
            }
        }
Exemplo n.º 4
0
        /* Function: TestFolder
         * Tests all the input files contained in this folder.  See <EngineInstanceManager.Start()> for how relative paths are handled.
         */
        public void TestFolder(Path testDataFolder, Path projectConfigFolder = default(Path))
        {
            TestList  allTests            = new TestList();
            StringSet expectedOutputFiles = new StringSet();

            engineInstanceManager = new EngineInstanceManager();
            engineInstanceManager.Start(testDataFolder, projectConfigFolder);

            // Store this so we can still use it for error messages after the engine is disposed of.
            Path inputFolder = engineInstanceManager.InputFolder;

            try
            {
                engineInstanceManager.Run();


                // Iterate through classes to build output files.

                using (Engine.CodeDB.Accessor accessor = EngineInstance.CodeDB.GetAccessor())
                {
                    // Class IDs should be assigned sequentially.  It's not an ideal way to do this though.
                    int classID = 1;
                    accessor.GetReadOnlyLock();

                    try
                    {
                        for (;;)
                        {
                            List <Topic> classTopics = accessor.GetTopicsInClass(classID, Delegates.NeverCancel);
                            Engine.Output.Components.ClassView.MergeTopics(classTopics, engineInstanceManager.HTMLBuilder);

                            if (classTopics == null || classTopics.Count == 0)
                            {
                                break;
                            }

                            string testName       = classTopics[0].ClassString.Symbol.FormatWithSeparator(".");
                            Path   outputFilePath = Test.ActualOutputFileOf(testName, inputFolder);

                            Test test = Test.FromActualOutputFile(outputFilePath);
                            expectedOutputFiles.Add(test.ExpectedOutputFile);

                            try
                            {
                                test.SetActualOutput(OutputOf(classTopics));
                            }
                            catch (Exception e)
                            { test.TestException = e; }

                            test.Run();
                            allTests.Add(test);

                            classID++;
                        }
                    }
                    finally
                    { accessor.ReleaseLock(); }
                }


                // Now search for any expected output files that didn't have corresponding actual output files.

                string[] files = System.IO.Directory.GetFiles(inputFolder);

                foreach (string file in files)
                {
                    if (Test.IsExpectedOutputFile(file) && expectedOutputFiles.Contains(file) == false)
                    {
                        Test test = Test.FromExpectedOutputFile(file);
                        test.Run();
                        allTests.Add(test);

                        expectedOutputFiles.Add(file);
                    }
                }
            }

            finally
            {
                engineInstanceManager.Dispose();
                engineInstanceManager = null;
            }


            if (allTests.Count == 0)
            {
                Assert.Fail("There were no tests found in " + inputFolder);
            }
            else if (allTests.Passed == false)
            {
                Assert.Fail(allTests.BuildFailureMessage());
            }
        }
Exemplo n.º 5
0
        /* Function: TestFolder
         * Tests all the input files contained in this folder.  See <EngineInstanceManager.Start()> for how relative paths are handled.
         */
        public void TestFolder(Path testDataFolder, Path projectConfigFolder = default(Path), bool autoGroup = false)
        {
            TestList allTests = new TestList();

            engineInstanceManager = new EngineInstanceManager();
            engineInstanceManager.Start(testDataFolder, projectConfigFolder, autoGroup: autoGroup);

            // Store this so we can still use it for error messages after the engine is disposed of.
            Path inputFolder = engineInstanceManager.InputFolder;

            try
            {
                // Build a test for each input file we find
                string[] files = System.IO.Directory.GetFiles(inputFolder);

                foreach (string file in files)
                {
                    if (Test.IsInputFile(file))
                    {
                        Test test = Test.FromInputFile(file);

                        try
                        {
                            Language language = EngineInstance.Languages.FromExtension(test.InputFile.Extension);

                            if (language == null)
                            {
                                throw new Exception("Extension " + test.InputFile.Extension + " did not resolve to a language.");
                            }

                            IList <Topic> topics;
                            LinkSet       classParentLinks;
                            language.Parse(test.InputFile, -1, Engine.Delegates.NeverCancel, out topics, out classParentLinks);

                            test.SetActualOutput(OutputOf(topics));
                        }
                        catch (Exception e)
                        { test.TestException = e; }

                        test.Run();
                        allTests.Add(test);
                    }
                }
            }

            finally
            {
                engineInstanceManager.Dispose();
                engineInstanceManager = null;
            }


            if (allTests.Count == 0)
            {
                Assert.Fail("There were no tests found in " + inputFolder);
            }
            else if (allTests.Passed == false)
            {
                Assert.Fail(allTests.BuildFailureMessage());
            }
        }