Ejemplo n.º 1
0
        public void PositiveExamples(IKjuExample example)
        {
            var diag = new Mock <IDiagnostics>();

            Compiler.RunOnInputReader(example.Program, diag.Object);
            MockDiagnostics.Verify(diag, example.ExpectedMagicStrings.ToArray());
        }
Ejemplo n.º 2
0
        public void NegativeExamples(IKjuExample example)
        {
            var diag = new Mock <IDiagnostics>();

            Assert.ThrowsException <CompilerException>(() => Compiler.RunOnInputReader(example.Program, diag.Object));

            MockDiagnostics.Verify(diag, example.ExpectedMagicStrings.ToArray());
        }
Ejemplo n.º 3
0
 public void NegativeDisabledExamples(IKjuExample example)
 {
     Assert.Inconclusive("unknown");
 }
Ejemplo n.º 4
0
        public void ExecutableExamples(IKjuExample example)
        {
            var options = new Program.Options
            {
                GenExe = true
            };
            var exeName = $"{TestsDirectory}/{example.SimpleName}";
            var query   = new CompilationQuery(example.Program, exeName);
            var diag    = new Mock <IDiagnostics>();

            Program.GenerateArtifacts(options, Compiler, query, diag.Object);
            var process = new System.Diagnostics.Process
            {
                StartInfo =
                {
                    FileName               = exeName,
                    Arguments              = string.Empty,
                    UseShellExecute        = false,
                    RedirectStandardInput  = true,
                    RedirectStandardOutput = true,
                    WindowStyle            = System.Diagnostics.ProcessWindowStyle.Hidden,
                    CreateNoWindow         = true
                }
            };

            process.Start();
            using (var writer = process.StandardInput)
            {
                writer.Write(example.Input);
            }

            if (!process.WaitForExit(example.Timeout))
            {
                process.Kill();
                if (example.Ends)
                {
                    Assert.Fail($"Process has not ended before timeout ({example.Timeout}).");
                }
            }
            else
            {
                var exitCode = process.ExitCode;
                if (!example.Ends)
                {
                    Assert.Fail($"Should not end but ended with exit code {exitCode}.");
                }

                Assert.AreEqual(
                    example.ExpectedExitCode,
                    exitCode,
                    $"Process returned with wrong exit code.");
            }

            var processOutput = process.StandardOutput.ReadToEnd();

            var outputCheckResult = example.OutputChecker.CheckOutput(processOutput);

            outputCheckResult.Notes.ForEach(Console.WriteLine);
            if (outputCheckResult is OutputCheckResult.Wrong)
            {
                Assert.Fail("Output is wrong.");
            }

            MockDiagnostics.Verify(diag, example.ExpectedMagicStrings.ToArray());
        }
Ejemplo n.º 5
0
 public void NotExecutableExamples(IKjuExample example)
 {
     Assert.Inconclusive("unknown");
 }