Пример #1
0
        public CompilerTestCase CreateTestCase(DirectoryInfo testDir)
        {
            FileInfo[] inputFiles = testDir.GetFiles("*.p");
            string     testName   = new Uri(Constants.TestDirectory + Path.DirectorySeparatorChar)
                                    .MakeRelativeUri(new Uri(testDir.FullName))
                                    .ToString();

            ICompilerTestRunner   runner;
            ITestResultsValidator validator;

            CompilerOutput output = CompilerOutput.C;

            runner = new CompileOnlyRunner(output, inputFiles);

            // TODO: validate information about the particular kind of compiler error
            bool isStaticError = testName.Contains("/StaticError/");

            validator = isStaticError
                ? (ITestResultsValidator) new StaticErrorValidator()
                : new CompileSuccessValidator();

            DirectoryInfo tempDirName =
                Directory.CreateDirectory(Path.Combine(testTempBaseDir.FullName, output.ToString(), testName));

            return(new CompilerTestCase(tempDirName, runner, validator));
        }
Пример #2
0
        /// <summary>
        /// Logs the build result.
        /// </summary>
        /// <param name="output">The result of the build.</param>
        public override void LogResult(CompilerOutput output)
        {
            if (Verbosity >= LoggerVerbosity.Quiet)
            {
                TextWriter w = output.Succeeded ? Console.Out : Console.Error;

                w.WriteLine(output.ToString());
            }
        }
Пример #3
0
 /// <summary>
 /// Logs the build result.
 /// </summary>
 /// <param name="output">The result of the build.</param>
 public override void LogResult(CompilerOutput output)
 {
     if (Verbosity >= LoggerVerbosity.Quiet)
     {
         if (output.Succeeded)
             Debug.WriteLine(output);
         else
             Debug.Fail("Build failed.", output.ToString());
     }
 }
Пример #4
0
        /// <summary>
        ///     Box a test case from the given directory and parsed Prt run configuration
        /// </summary>
        /// <param name="testDir">The directory containing P source files</param>
        /// <param name="output">The desired output language</param>
        /// <returns>The test case in a runnable state.</returns>
        public CompilerTestCase CreateTestCase(DirectoryInfo testDir, CompilerOutput output)
        {
            var inputFiles = testDir.GetFiles("*.p");
            var testName   = new Uri(Constants.TestDirectory + Path.DirectorySeparatorChar)
                             .MakeRelativeUri(new Uri(testDir.FullName))
                             .ToString();

            ICompilerTestRunner   runner;
            ITestResultsValidator validator;

            string expectedOutput;

            if (output.Equals(CompilerOutput.C))
            {
                var nativeFiles = testDir.GetFiles("*.c");
                runner         = new PrtRunner(inputFiles, nativeFiles);
                expectedOutput =
                    File.ReadAllText(Path.Combine(testDir.FullName, "Prt", Constants.CorrectOutputFileName));
            }
            else if (output.Equals(CompilerOutput.PSharp))
            {
                var nativeFiles = testDir.GetFiles("*.cs");
                runner = new PSharpRunner(inputFiles, nativeFiles);
                var prtGoldenOutputFile      = Path.Combine(testDir.FullName, "Prt", Constants.CorrectOutputFileName);
                var prtSharpGoldenOutputFile =
                    Path.Combine(testDir.FullName, "PrtSharp", Constants.CorrectOutputFileName);
                if (File.Exists(prtSharpGoldenOutputFile))
                {
                    expectedOutput = File.ReadAllText(prtSharpGoldenOutputFile);
                }
                else
                {
                    expectedOutput = File.ReadAllText(prtGoldenOutputFile);
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }

            // TODO: fix golden outputs for dynamic error assertions (79 tests)
            ParseExpectedOutput(expectedOutput, out var stdout, out var stderr, out var exitCode);
            if (testName.Contains("/DynamicError/") || output.Equals(CompilerOutput.PSharp))
            {
                stdout = null;
                stderr = null;
            }

            validator = new ExecutionOutputValidator(exitCode, stdout, stderr);

            var tempDirName =
                Directory.CreateDirectory(Path.Combine(testTempBaseDir.FullName, output.ToString(), testName));

            return(new CompilerTestCase(tempDirName, runner, validator));
        }
Пример #5
0
        /// <summary>
        ///     Box a test case from the given directory and parsed Prt run configuration
        /// </summary>
        /// <param name="testDir">The directory containing P source files</param>
        /// <param name="output">The desired output language</param>
        /// <returns>The test case in a runnable state.</returns>
        public CompilerTestCase CreateTestCase(DirectoryInfo testDir, CompilerOutput output)
        {
            FileInfo[] inputFiles = testDir.GetFiles("*.p");
            string     testName   = new Uri(Constants.TestDirectory + Path.DirectorySeparatorChar)
                                    .MakeRelativeUri(new Uri(testDir.FullName))
                                    .ToString();

            ICompilerTestRunner   runner;
            ITestResultsValidator validator;

            int expectedExitCode;

            if (testName.Contains("/DynamicError/") || testName.Contains("/DynamicErrorCoyoteRuntime/"))
            {
                expectedExitCode = 1;
            }
            else if (testName.Contains("/Correct/") || testName.Contains("/CorrectCoyoteRuntime/"))
            {
                expectedExitCode = 0;
            }
            else
            {
                throw new CompilerTestException(TestCaseError.UnrecognizedTestCaseType);
            }

            if (output.Equals(CompilerOutput.C))
            {
                FileInfo[] nativeFiles = testDir.GetFiles("*.c");
                runner = new PrtRunner(inputFiles, nativeFiles);
            }
            else if (output.Equals(CompilerOutput.Coyote))
            {
                FileInfo[] nativeFiles = testDir.GetFiles("*.cs");
                runner = new CoyoteRunner(inputFiles, nativeFiles);
            }
            else
            {
                throw new ArgumentOutOfRangeException();
            }

            validator = new ExecutionOutputValidator(expectedExitCode);

            DirectoryInfo tempDirName =
                Directory.CreateDirectory(Path.Combine(testTempBaseDir.FullName, output.ToString(), testName));

            return(new CompilerTestCase(tempDirName, runner, validator));
        }