Beispiel #1
0
        public void BuildManyFilesToStdOutShouldProduceExpectedErrors()
        {
            var invalidDataSets = DataSets.AllDataSets.Where(ds => ds.IsValid == false).ToList();

            var bicepFiles = invalidDataSets
                             .Select(ds => FileHelper.SaveResultFile(this.TestContext !, $"{ds.Name}_Bicep.bicep", ds.Bicep))
                             .ToList();

            invalidDataSets.Should().HaveCount(bicepFiles.Count);

            var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = new Program(@out, err);
                p.Run(new[] { "build", "--stdout" }.Concat(bicepFiles).ToArray()).Should().Be(1);
            });

            output.Should().Be("[]");
            error.Should().NotBeEmpty();

            var diagnosticsFromAllFiles = invalidDataSets
                                          .Zip(bicepFiles, (ds, file) => GetAllDiagnostics(ds.Bicep, file))
                                          .SelectMany(e => e);

            error.Should().ContainAll(diagnosticsFromAllFiles);
        }
Beispiel #2
0
        public void BuildManyFilesToStdOutShouldProduceExpectedTemplate()
        {
            var validDataSets = DataSets.AllDataSets.Where(ds => ds.IsValid).ToList();

            var bicepFiles = validDataSets
                             .Select(ds => FileHelper.SaveResultFile(this.TestContext !, Path.Combine(ds.Name, DataSet.TestFileMain), ds.Bicep))
                             .ToList();

            var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = new Program(@out, err);

                string[] args = new[] { "build", "--stdout" }.Concat(bicepFiles).ToArray();
                p.Run(args).Should().Be(0);
            });

            error.Should().BeEmpty();
            output.Should().NotBeEmpty();

            var actual   = JArray.Parse(output);
            var expected = new JArray(validDataSets.Select(ds => JToken.Parse(ds.Compiled !)));

            FileHelper.SaveResultFile(this.TestContext !, "Combined_Compiled_Actual.json", output);
            FileHelper.SaveResultFile(this.TestContext !, "Combined_Compiled_Expected.json", expected.ToString(Formatting.Indented));

            JsonAssert.AreEqual(expected, actual, this.TestContext !, "Combined_Compiled_Delta.json");
        }
Beispiel #3
0
        public void BuildManyFilesToStdOutShouldProduceExpectedTemplate()
        {
            var validDataSets     = DataSets.AllDataSets.Where(ds => ds.IsValid).ToList();
            var outputDirectories = validDataSets.ToDictionary(ds => ds, ds => ds.SaveFilesToTestDirectory(TestContext, ds.Name));

            var bicepFiles = outputDirectories.Values.Select(dir => Path.Combine(dir, DataSet.TestFileMain));

            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);

                string[] args = new[] { "build", "--stdout" }.Concat(bicepFiles).ToArray();
                return(p.Run(args));
            });

            using (new AssertionScope())
            {
                result.Should().Be(0);
                error.Should().BeEmpty();
                output.Should().NotBeEmpty();
            }

            var actual   = JArray.Parse(output);
            var expected = new JArray(validDataSets.Select(ds => JToken.Parse(ds.Compiled !)));

            FileHelper.SaveResultFile(this.TestContext, "Combined_Compiled_Actual.json", output);
            FileHelper.SaveResultFile(this.TestContext, "Combined_Compiled_Expected.json", expected.ToString(Formatting.Indented));

            JsonAssert.AreEqual(expected, actual, this.TestContext, "Combined_Compiled_Delta.json");
        }
Beispiel #4
0
        public void BuildSingleFileToStdOutShouldProduceExpectedTemplate(DataSet dataSet)
        {
            var outputDirectory = dataSet.SaveFilesToTestDirectory(TestContext);
            var bicepFilePath   = Path.Combine(outputDirectory, DataSet.TestFileMain);

            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);
                return(p.Run(new[] { "build", "--stdout", bicepFilePath }));
            });

            using (new AssertionScope())
            {
                result.Should().Be(0);
                output.Should().NotBeEmpty();
                AssertNoErrors(error, dataSet.Name);
            }

            var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled);

            File.Exists(compiledFilePath).Should().BeTrue();

            var actual = JToken.Parse(output);

            actual.Should().EqualWithJsonDiffOutput(
                TestContext,
                JToken.Parse(dataSet.Compiled !),
                expectedLocation: Path.Combine("src", "Bicep.Core.Samples", "Files", dataSet.Name, DataSet.TestFileMainCompiled),
                actualLocation: compiledFilePath);
        }
Beispiel #5
0
 protected static (string output, string error, int result) Bicep(params string[] args)
 {
     return(TextWriterHelper.InvokeWriterAction((@out, err) =>
     {
         return new Program(new InvocationContext(TestTypeHelper.CreateEmptyProvider(), @out, err, BicepTestConstants.DevAssemblyFileVersion)).Run(args);
     }));
 }
Beispiel #6
0
        public void BuildManyFilesShouldProduceExpectedTemplate()
        {
            var validDataSets = DataSets.AllDataSets.Where(ds => ds.IsValid).ToList();

            var bicepFiles = validDataSets
                             .Select(ds => FileHelper.SaveResultFile(this.TestContext !, Path.Combine(ds.Name, DataSet.TestFileMain), ds.Bicep))
                             .ToList();

            var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = new Program(@out, err);

                string[] args = "build".AsEnumerable().Concat(bicepFiles).ToArray();
                p.Run(args).Should().Be(0);
            });

            output.Should().BeEmpty();
            error.Should().BeEmpty();

            foreach (var dataSet in validDataSets)
            {
                var compiledFilePath = FileHelper.GetResultFilePath(this.TestContext !, Path.Combine(dataSet.Name, DataSet.TestFileMainCompiled));
                File.Exists(compiledFilePath).Should().BeTrue();

                var actual = JToken.Parse(File.ReadAllText(compiledFilePath));

                actual.Should().EqualWithJsonDiffOutput(
                    JToken.Parse(dataSet.Compiled !),
                    expectedLocation: Path.Combine("src", "Bicep.Core.Samples", dataSet.Name, DataSet.TestFileMainCompiled),
                    actualLocation: compiledFilePath);
            }
        }
Beispiel #7
0
        public void BicepHelpShouldPrintHelp()
        {
            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);
                return(p.Run(new[] { "--help" }));
            });

            result.Should().Be(0);
            error.Should().BeEmpty();

            output.Should().NotBeEmpty();
            output.Should().ContainAll(
                "build",
                "[options]",
                "<file>",
                ".bicep",
                "Arguments:",
                "Options:",
                "--outdir",
                "--outfile",
                "--stdout",
                "--version",
                "--help",
                "information",
                "version",
                "bicep",
                "usage");
        }
Beispiel #8
0
        public void BuildInvalidInputPathsToStdOutShouldProduceExpectedError(string badPath, string expectedErrorRegex)
        {
            var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = new Program(@out, err);
                p.Run(new[] { "build", "--stdout", badPath }).Should().Be(1);
            });

            output.Should().BeEmpty();
            error.Should().MatchRegex(expectedErrorRegex);
        }
Beispiel #9
0
        public void BuildInvalidInputPathsShouldProduceExpectedError(string badPath, string expectedErrorRegex)
        {
            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);
                return(p.Run(new[] { "build", badPath }));
            });

            result.Should().Be(1);
            output.Should().BeEmpty();
            error.Should().MatchRegex(expectedErrorRegex);
        }
Beispiel #10
0
        public void ZeroFilesToBuildShouldProduceError()
        {
            var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = new Program(@out, err);
                p.Run(new[] { "build" }).Should().Be(1);
            });

            output.Should().BeEmpty();

            error.Should().NotBeEmpty();
            error.Should().Be($"At least one file must be specified to the build command.{Environment.NewLine}");
        }
Beispiel #11
0
        public void BicepVersionShouldPrintVersionInformation()
        {
            var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = new Program(@out, err);
                p.Run(new[] { "--version" }).Should().Be(0);
            });

            error.Should().BeEmpty();

            output.Should().NotBeEmpty();
            output.Should().StartWith("Bicep CLI version");
        }
Beispiel #12
0
        public void WrongArgumentsShouldProduceError()
        {
            var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = new Program(@out, err);
                p.Run(new[] { "wrong", "fake", "broken" }).Should().Be(1);
            });

            output.Should().BeEmpty();

            error.Should().NotBeEmpty();
            error.Should().Be($"Unrecognized arguments 'wrong fake broken' specified. Use 'bicep --help' to view available options.{Environment.NewLine}");
        }
Beispiel #13
0
        public void WrongArgumentsShouldProduceError()
        {
            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);
                return(p.Run(new[] { "wrong", "fake", "broken" }));
            });

            result.Should().Be(1);
            output.Should().BeEmpty();

            error.Should().NotBeEmpty();
            error.Should().Be($"Unrecognized arguments \"wrong fake broken\" specified. Use \"bicep --help\" to view available options.{Environment.NewLine}");
        }
Beispiel #14
0
        public void ZeroFilesToBuildShouldProduceError()
        {
            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);
                return(p.Run(new[] { "build" }));
            });

            result.Should().Be(1);
            output.Should().BeEmpty();

            error.Should().NotBeEmpty();
            error.Should().Be($"The input file path was not specified{Environment.NewLine}");
        }
Beispiel #15
0
        private static (IEnumerable <string> outputLines, IEnumerable <string> errorLines, int result) ExecuteProgram(params string[] args)
        {
            var(output, error, result) = TextWriterHelper.InvokeWriterAction((outputWriter, errorWriter) =>
            {
                var program = new Program(TestTypeHelper.CreateEmptyProvider(), outputWriter, errorWriter, BicepTestConstants.DevAssemblyFileVersion);

                return(program.Run(args));
            });

            return(
                Regex.Split(output, "\r?\n").Where(x => x != ""),
                Regex.Split(error, "\r?\n").Where(x => x != ""),
                result);
        }
Beispiel #16
0
        private static (IEnumerable <string> outputLines, IEnumerable <string> errorLines, int result) ExecuteProgram(params string[] args)
        {
            var(output, error, result) = TextWriterHelper.InvokeWriterAction((outputWriter, errorWriter) =>
            {
                var program = new Program(TestResourceTypeProvider.Create(), outputWriter, errorWriter);

                return(program.Run(args));
            });

            return(
                Regex.Split(output, "\r?\n").Where(x => x != ""),
                Regex.Split(error, "\r?\n").Where(x => x != ""),
                result);
        }
Beispiel #17
0
        public void BuildSingleFileToStdOutShouldProduceExpectedErrors(DataSet dataSet)
        {
            string bicepFilePath = FileHelper.SaveResultFile(this.TestContext !, $"{dataSet.Name}_Bicep.bicep", dataSet.Bicep);

            var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = new Program(@out, err);
                p.Run(new[] { "build", "--stdout", bicepFilePath }).Should().Be(1);
            });

            output.Should().BeEmpty();
            error.Should().NotBeEmpty();

            var diagnostics = GetAllDiagnostics(dataSet.Bicep, bicepFilePath);

            error.Should().ContainAll(diagnostics);
        }
Beispiel #18
0
        public void Build_command_with_nonexistent_outdir_parameter()
        {
            var bicepPath = FileHelper.SaveResultFile(TestContext, "input.bicep", @"
output myOutput string = 'hello!'
            ");

            var outputFileDir = FileHelper.GetResultFilePath(TestContext, "outputdir");

            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);
                return(p.Run(new[] { "build", "--outdir", outputFileDir, bicepPath }));
            });

            result.Should().Be(1);
            output.Should().BeEmpty();
            error.Should().MatchRegex(@"The specified output directory "".*outputdir"" does not exist");
        }
Beispiel #19
0
        public void Build_command_with_outfile_parameter()
        {
            var bicepPath = FileHelper.SaveResultFile(TestContext, "input.bicep", @"
output myOutput string = 'hello!'
            ");

            var outputFilePath = FileHelper.GetResultFilePath(TestContext, "output.json");

            File.Exists(outputFilePath).Should().BeFalse();
            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);
                return(p.Run(new[] { "build", "--outfile", outputFilePath, bicepPath }));
            });

            File.Exists(outputFilePath).Should().BeTrue();
            result.Should().Be(0);
        }
Beispiel #20
0
        public void BuildSingleFileToStdOutShouldProduceExpectedErrors(DataSet dataSet)
        {
            var outputDirectory = dataSet.SaveFilesToTestDirectory(TestContext);
            var bicepFilePath   = Path.Combine(outputDirectory, DataSet.TestFileMain);

            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);
                return(p.Run(new[] { "build", "--stdout", bicepFilePath }));
            });

            result.Should().Be(1);
            output.Should().BeEmpty();
            error.Should().NotBeEmpty();

            var diagnostics = GetAllDiagnostics(bicepFilePath);

            error.Should().ContainAll(diagnostics);
        }
Beispiel #21
0
        public void LockedOutputFileShouldProduceExpectedError()
        {
            var inputFile  = FileHelper.SaveResultFile(this.TestContext !, "Empty.bicep", DataSets.Empty.Bicep);
            var outputFile = PathHelper.GetDefaultOutputPath(inputFile);

            // ReSharper disable once ConvertToUsingDeclaration
            using (new FileStream(outputFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
            {
                // keep the output stream open while we attempt to write to it
                // this should force an access denied error
                var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
                {
                    var p = new Program(@out, err);
                    p.Run(new[] { "build", inputFile }).Should().Be(1);
                });

                output.Should().BeEmpty();
                error.Should().Contain("Empty.json");
            }
        }
Beispiel #22
0
        public void BuildManyFilesToStdOutShouldProduceExpectedErrors()
        {
            var invalidDataSets   = DataSets.AllDataSets.Where(ds => !ds.IsValid).ToList();
            var outputDirectories = invalidDataSets.ToDictionary(ds => ds, ds => ds.SaveFilesToTestDirectory(TestContext, ds.Name));

            var bicepFiles = outputDirectories.Values.Select(dir => Path.Combine(dir, DataSet.TestFileMain));

            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);
                return(p.Run(new[] { "build", "--stdout" }.Concat(bicepFiles).ToArray()));
            });

            result.Should().Be(1);
            output.Should().Be("[]");
            error.Should().NotBeEmpty();

            var diagnosticsFromAllFiles = bicepFiles.SelectMany(file => GetAllDiagnostics(file));

            error.Should().ContainAll(diagnosticsFromAllFiles);
        }
Beispiel #23
0
        public void BuildManyFilesShouldProduceExpectedTemplate()
        {
            var validDataSets     = DataSets.AllDataSets.Where(ds => ds.IsValid).ToList();
            var outputDirectories = validDataSets.ToDictionary(ds => ds, ds => ds.SaveFilesToTestDirectory(TestContext, ds.Name));

            var bicepFiles = outputDirectories.Values.Select(dir => Path.Combine(dir, DataSet.TestFileMain));

            var(output, error, result) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = CreateProgram(@out, err);

                string[] args = "build".AsEnumerable().Concat(bicepFiles).ToArray();
                return(p.Run(args));
            });

            using (new AssertionScope())
            {
                result.Should().Be(0);
                output.Should().BeEmpty();
                error.Should().BeEmpty();
            }

            foreach (var kvp in outputDirectories)
            {
                var outputDirectory = kvp.Value;
                var dataSet         = kvp.Key;

                var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled);
                File.Exists(compiledFilePath).Should().BeTrue();

                var actual = JToken.Parse(File.ReadAllText(compiledFilePath));

                actual.Should().EqualWithJsonDiffOutput(
                    TestContext,
                    JToken.Parse(dataSet.Compiled !),
                    expectedLocation: Path.Combine("src", "Bicep.Core.Samples", "Files", dataSet.Name, DataSet.TestFileMainCompiled),
                    actualLocation: compiledFilePath);
            }
        }
Beispiel #24
0
        public void BuildSingleFileToStdOutShouldProduceExpectedTemplate(DataSet dataSet)
        {
            var bicepFilePath = FileHelper.SaveResultFile(this.TestContext !, Path.Combine(dataSet.Name, DataSet.TestFileMain), dataSet.Bicep);

            var(output, error) = TextWriterHelper.InvokeWriterAction((@out, err) =>
            {
                var p = new Program(@out, err);
                p.Run(new[] { "build", "--stdout", bicepFilePath }).Should().Be(0);
            });

            error.Should().BeEmpty();
            output.Should().NotBeEmpty();

            var compiledFilePath = FileHelper.SaveResultFile(this.TestContext !, Path.Combine(dataSet.Name, DataSet.TestFileMainCompiled), output);

            File.Exists(compiledFilePath).Should().BeTrue();

            var actual = JToken.Parse(output);

            actual.Should().EqualWithJsonDiffOutput(
                JToken.Parse(dataSet.Compiled !),
                expectedLocation: Path.Combine("src", "Bicep.Core.Samples", dataSet.Name, DataSet.TestFileMainCompiled),
                actualLocation: compiledFilePath);
        }