Exemplo n.º 1
0
        public void Test(TestCaseConfig config, TextReader reader)
        {
            var dependencies = config.Runtime ? new[] { runtimeDependency } : Enumerable.Empty <PackageReferenceSyntax>();
            var package      = new PackageSyntax($"Adamant.Exploratory.Compiler.Tests.{config.TestName}", true, dependencies);
            var unit         = compiler.Parse(package, new SourceReader(config.FileName, reader));

            package = package.With(new[] { unit });
            if (package.Diagnostics.Count > 0)
            {
                Assert.Fail(ToString(package.Diagnostics));
            }
            var compiledPackage = compiler.Compile(package, Enumerable.Empty <Package>());

            if (compiledPackage.Diagnostics.Count > 0)
            {
                Assert.Fail(ToString(compiledPackage.Diagnostics));
            }

            var interpreter  = new AdamantInterpreter(compiledPackage);
            var entryPoint   = compiledPackage.EntryPoints.Single();
            var outputBuffer = new StringBuilder();
            var errorBuffer  = new StringBuilder();
            var exitCode     = interpreter.Invoke(entryPoint, new string[0], new StringWriter(outputBuffer), new StringWriter(errorBuffer));

            Assert.AreEqual(config.Result, exitCode, "Exit Code");
            if (config.VerifyConsoleOutput)
            {
                Assert.AreEqual(config.ExpectedConsoleOutput, outputBuffer.ToString());
            }
        }
        public void Test(TestCaseConfig config, TextReader reader)
        {
            var dependencies = config.Runtime ? new[] { runtimeDependency } : Enumerable.Empty<PackageReferenceSyntax>();
            var package = new PackageSyntax($"Adamant.Exploratory.Compiler.Tests.{config.TestName}", true, dependencies);
            var unit = compiler.Parse(package, new SourceReader(config.FileName, reader));
            package = package.With(new[] { unit });
            if(package.Diagnostics.Count > 0)
                Assert.Fail(ToString(package.Diagnostics));
            var compiledPackage = compiler.Compile(package, Enumerable.Empty<Package>());
            if(compiledPackage.Diagnostics.Count > 0)
                Assert.Fail(ToString(compiledPackage.Diagnostics));

            var interpreter = new AdamantInterpreter(compiledPackage);
            var entryPoint = compiledPackage.EntryPoints.Single();
            var outputBuffer = new StringBuilder();
            var errorBuffer = new StringBuilder();
            var exitCode = interpreter.Invoke(entryPoint, new string[0], new StringWriter(outputBuffer), new StringWriter(errorBuffer));
            Assert.AreEqual(config.Result, exitCode, "Exit Code");
            if(config.VerifyConsoleOutput)
                Assert.AreEqual(config.ExpectedConsoleOutput, outputBuffer.ToString());
        }