Пример #1
0
        /// <inheritdoc />
        /// <summary>
        ///     Run the compiler test without attempting to build the result
        /// </summary>
        /// <param name="scratchDirectory">Unused. Caller is responsible for cleanup.</param>
        /// <param name="stdout">The output produced by the P compiler</param>
        /// <param name="stderr">The error output produced by the P compiler</param>
        /// <returns>0 if compilation successful, 1 if a Translation Exception is thrown, throws a
        ///     CompilerTestException if the compiler crashes.
        /// </returns>
        public int?RunTest(DirectoryInfo scratchDirectory, out string stdout, out string stderr)
        {
            Compiler             compiler     = new Compiler();
            StringWriter         stdoutWriter = new StringWriter();
            StringWriter         stderrWriter = new StringWriter();
            TestCaseOutputStream outputStream = new TestCaseOutputStream(stdoutWriter, stderrWriter);

            CompilationJob job = new CompilationJob(outputStream, scratchDirectory, compilerOutput, inputFiles, Path.GetFileNameWithoutExtension(inputFiles.First().FullName));

            try
            {
                compiler.Compile(job);
            }
            catch (TranslationException)
            {
                stdout = stdoutWriter.ToString().Trim();
                stderr = stderrWriter.ToString().Trim();
                return(1);
            }
            catch (Exception exception)
            {
                job.Output.WriteMessage(exception.Message, SeverityKind.Error);
                throw new CompilerTestException(TestCaseError.TranslationFailed, exception.Message);
            }
            stdout = stdoutWriter.ToString().Trim();
            stderr = stderrWriter.ToString().Trim();
            return(0);
        }
Пример #2
0
        /// <inheritdoc />
        /// <summary>
        ///     Run the compiler test without attempting to build the result
        /// </summary>
        /// <param name="scratchDirectory">Unused. Caller is responsible for cleanup.</param>
        /// <param name="stdout">The output produced by the P compiler</param>
        /// <param name="stderr">The error output produced by the P compiler</param>
        /// <returns>Always returns 0, otherwise throws.</returns>
        public int?RunTest(DirectoryInfo scratchDirectory, out string stdout, out string stderr)
        {
            var compiler     = new Compiler();
            var stdoutWriter = new StringWriter();
            var stderrWriter = new StringWriter();
            var outputStream = new TestCaseOutputStream(stdoutWriter, stderrWriter);

            var job = new CompilationJob(outputStream, compilerOutput, inputFiles);

            try
            {
                compiler.Compile(job);
                stdout = stdoutWriter.ToString().Trim();
                stderr = stderrWriter.ToString().Trim();
            }
            catch (TranslationException exception)
            {
                job.Output.WriteMessage(exception.Message, SeverityKind.Error);
                throw new CompilerTestException(TestCaseError.TranslationFailed, exception.Message);
            }

            return(0);
        }