示例#1
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));
        }
示例#2
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));
        }