Esempio n. 1
0
        /// <summary>
        /// Parses the run directive. It is used to a command to be run in the test case.
        /// </summary>
        /// RUN has the syntax:
        /// <example>//RUN: "command" arguments</example>
        /// <returns>
        /// The concrete run directive.
        /// </returns>
        internal TestCaseDirective ParseRunDirective()
        {
            Token tok = lexer.Lex();

            if (tok.Kind != Token.Kinds.Colon)
            {
                return(null);
            }
            tok = lexer.Lex();
            if (tok.Kind != Token.Kinds.Quote)
            {
                return(null);
            }

            TestCaseDirective runDir = new TestCaseDirective(TestCaseDirective.Kinds.Run);

            string command = lexer.LexUntil('"');

            lexer.Lex(); // Lex the closing quote.

            string arguments = "";

            // Expand the command if known:
            if (command[0] == '@')
            {
                if (command == "@ILASM@")
                {
                    command = BuildInformation.BuildInfo.ILASMCompiler;
                    // Set up the output file in the current (build) folder.
                    arguments = " /OUTPUT:" + Path.GetFileNameWithoutExtension(filename) + ".dll";
                }
                else if (command == "@CSC@")
                {
                    command = BuildInformation.BuildInfo.CSCCompiler;
                    // Set up the output file in the current (build) folder.
                    arguments = " /OUT:" + Path.GetFileNameWithoutExtension(filename) + ".dll";
                }
            }

            runDir.Command = command;

            arguments += lexer.LexUntil('\n'); // Practically EOF in our case.
            // Expand arguments if known:
            arguments        = arguments.Replace("@TEST_CASE@", filename);
            arguments        = arguments.Replace("@CMAKE_LIBRARY_OUTPUT_DIR@", BuildInformation.BuildInfo.LibraryOutputDir);
            runDir.Arguments = arguments.TrimEnd('\r');

            return(runDir);
        }
Esempio n. 2
0
        /// <summary>
        /// Compiles the test case into an assembly. The default implementation uses ilasm. The
        /// subclasses may override it if neccessary.
        /// </summary>
        /// <returns>
        /// The compiled assembly.
        /// </returns>
        /// <param name='testCase'>
        /// The input source file.
        /// </param>
        protected virtual AssemblyDefinition CompileTestCase(string testCase)
        {
            string sourceFile = GetTestCaseFullPath(testCase);

            Assert.IsTrue(File.Exists(sourceFile), sourceFile + " not found!");
            string testCaseAssemblyName
                = Path.Combine(GetTestCasesBuildDir(), Path.GetFileNameWithoutExtension(sourceFile) + ".dll");

            TestCaseDirective runDir = directives.Find(d => d.Kind == TestCaseDirective.Kinds.Run);

            Assert.NotNull(runDir, "Are you missing RUN: directive?");

            Process p = new Process();

            p.StartInfo.Arguments              = runDir.Arguments;
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardInput  = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.FileName         = runDir.Command;
            p.StartInfo.WorkingDirectory = GetTestCasesBuildDir();
            // Log the invocation
            LogProcessInvocation(p, testCase);
            p.Start();
            string output = p.StandardOutput.ReadToEnd();
            string error  = p.StandardError.ReadToEnd();

            p.WaitForExit();
            Assert.AreEqual(0, p.ExitCode, output + error);

            var resolver = new DefaultAssemblyResolver();

            resolver.AddSearchDirectory(SolidOpt.BuildInformation.BuildInfo.LibraryOutputDir);
            ReaderParameters @params = new ReaderParameters();

            @params.AssemblyResolver = resolver;
            return(AssemblyDefinition.ReadAssembly(testCaseAssemblyName, @params));
        }
Esempio n. 3
0
        /// <summary>
        /// Parses the directives, specified in the test case result file.
        /// </summary>
        /// <returns>
        /// List of directives found.
        /// </returns>
        internal List <TestCaseDirective> ParseDirectives()
        {
            List <TestCaseDirective> directives = new List <TestCaseDirective>(1);
            Token tok;

            while (true)
            {
                tok = lexer.Lex();
                if (tok.Kind == Token.Kinds.EOF)
                {
                    break;
                }
                if (tok.Kind == Token.Kinds.Comment)
                {
                    tok = lexer.Lex();
                    if (tok.Kind == Token.Kinds.Ident)
                    {
                        TestCaseDirective dir = null;
                        if (tok.IdentName == "XFAIL")
                        {
                            dir = ParseXfailDirective();
                        }
                        else if (tok.IdentName == "RUN")
                        {
                            dir = ParseRunDirective();
                        }

                        if (dir != null)
                        {
                            directives.Add(dir);
                        }
                    }
                }
            }
            return(directives);
        }