Exemplo n.º 1
0
            public void Should_Process_Tool_Directive_With_Source()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", "#tool \"Hello.World\" \"http://source\"");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(1, result.Script.Tools.Count);
                Assert.Equal("nuget:http://source/?package=Hello.World", result.Script.Tools.ElementAt(0).OriginalString);
            }
Exemplo n.º 2
0
            public void Should_Process_Using_Alias_Directives()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", "using Core = Cake.Core;");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(1, result.Script.UsingAliases.Count);
                Assert.Equal("using Core = Cake.Core;", result.Script.UsingAliases.ElementAt(0));
            }
Exemplo n.º 3
0
            public void Should_Process_Addin_Directive_Using_Uri()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", "#addin \"npm:?package=node\"");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(1, result.Script.Addins.Count);
                Assert.Equal("npm:?package=node", result.Script.Addins.ElementAt(0).OriginalString);
            }
Exemplo n.º 4
0
            public void Should_Return_Single_Assembly_Reference_With_Space_In_File_Name_Found_In_Source(string source)
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", source);

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(1, result.Script.References.Count);
                Assert.Equal("hello world.dll", result.Script.References.ElementAt(0));
            }
Exemplo n.º 5
0
            public void Should_Process_Single_Script_Reference_Found_In_Source(string source)
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", source);
                fixture.GivenScriptExist("/Working/utils.cake", "Console.WriteLine();");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(1, result.Script.Includes.Count);
                Assert.Equal("/Working/utils.cake", result.Script.Includes[0].Path.FullPath);
            }
Exemplo n.º 6
0
            public void Should_Process_Tools_Directive_Without_Source()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", "#tool \"Hello.World\"");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(1, result.Script.Tools.Count);
                Assert.Equal("Hello.World", result.Script.Tools.ElementAt(0).PackageId);
                Assert.Equal(null, result.Script.Tools.ElementAt(0).Source);
            }
Exemplo n.º 7
0
            public void Should_Process_Addin_Directive_With_Source()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", "#addin \"Hello.World\" \"http://source\"");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(1, result.Script.Addins.Count);
                Assert.Equal("Hello.World", result.Script.Addins.ElementAt(0).PackageId);
                Assert.Equal("http://source", result.Script.Addins.ElementAt(0).Source);
            }
Exemplo n.º 8
0
            public void Should_Remove_Shebang()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", "#!/usr/bin/cake\nConsole.WriteLine();");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(2, result.Lines.Count);
                Assert.Equal(result.Lines[0], "#line 1 \"/Working/script.cake\"");
                Assert.Equal(result.Lines[1], "Console.WriteLine();");
            }
Exemplo n.º 9
0
            public void Should_Return_Code_Read_From_File()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", "Console.ReadKey();");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(2, result.Lines.Count);
                Assert.Equal("#line 1 \"/Working/script.cake\"", result.Lines[0]);
                Assert.Equal("Console.ReadKey();", result.Lines[1]);
            }
Exemplo n.º 10
0
            public void Should_Process_Break_Directive()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", "#break");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(2, result.Lines.Count);
                Assert.Equal(result.Lines[0], "#line 1 \"/Working/script.cake\"");
                Assert.Equal(result.Lines[1], @"if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); }");
            }
        public void Should_Process_WindowsRelativePath_Script_Reference_Found_In_Source(string source)
        {
            // Given
            var fixture = new ScriptAnalyzerFixture(windows: true);

            fixture.AddFileLoadDirectiveProvider();
            fixture.GivenScriptExist("C:/Working/script.cake", source);
            fixture.GivenScriptExist("C:/Working/test/utils.cake", "Console.WriteLine();");

            // When
            var result = fixture.Analyze("C:/Working/script.cake");

            // Then
            Assert.Equal(1, result.Script.Includes.Count);
            Assert.Equal("C:/Working/test/utils.cake", result.Script.Includes[0].Path.FullPath);
        }
        public void Should_Process_Single_Script_Reference_With_Any_Extension_Found_In_Source(string filename)
        {
            // Given
            var fixture = new ScriptAnalyzerFixture();

            fixture.AddFileLoadDirectiveProvider();
            fixture.GivenScriptExist("/Working/script.cake", $"#l \"{filename}\"");
            fixture.GivenScriptExist($"/Working/{filename}", "Console.WriteLine();");

            // When
            var result = fixture.Analyze("/Working/script.cake");

            // Then
            Assert.Equal(1, result.Script.Includes.Count);
            Assert.Equal($"/Working/{filename}", result.Script.Includes[0].Path.FullPath);
        }
Exemplo n.º 13
0
        public void Should_Process_Single_Script_Reference_With_Spaces_In_File_Name_Found_In_Source(string source)
        {
            // Given
            var fixture = new ScriptAnalyzerFixture();

            fixture.Providers.Add(new FileLoadDirectiveProvider());
            fixture.GivenScriptExist("/Working/script.cake", source);
            fixture.GivenScriptExist("/Working/test/my utils.cake", "Console.WriteLine();");

            // When
            var result = fixture.Analyze("/Working/script.cake");

            // Then
            Assert.Equal(1, result.Script.Includes.Count);
            Assert.Equal("/Working/test/my utils.cake", result.Script.Includes[0].Path.FullPath);
        }
        public void Should_Ignore_Globber_Matches_With_Invalid_Extensions(string source)
        {
            // Given
            var fixture = new ScriptAnalyzerFixture();

            fixture.AddFileLoadDirectiveProvider();
            fixture.GivenScriptExist("/Working/bootstrap.cake", source);
            fixture.GivenScriptExist("/Working/scripts/utils.cs", "Console.WriteLine();");
            fixture.GivenScriptExist("/Working/scripts/other.kake", "Console.WriteLine();");

            // When
            var result = fixture.Analyze("/Working/bootstrap.cake");

            // Then
            Assert.Equal(0, result.Script.Includes.Count);
        }
Exemplo n.º 15
0
        public void Should_Process_Environment_Variable_Found_In_Source(string source)
        {
            // Given
            var fixture = new ScriptAnalyzerFixture();

            fixture.Environment.SetEnvironmentVariable("CAKE_TEST_SCRIPT_PATH", "test");
            fixture.Providers.Add(new FileLoadDirectiveProvider());
            fixture.GivenScriptExist("/Working/script.cake", source);
            fixture.GivenScriptExist("/Working/test/utils.cake", "Console.WriteLine();");

            // When
            var result = fixture.Analyze("/Working/script.cake");

            // Then
            Assert.Equal(1, result.Script.Includes.Count);
            Assert.Equal("/Working/test/utils.cake", result.Script.Includes[0].Path.FullPath);
        }
Exemplo n.º 16
0
            public void Should_Keep_Using_Block()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.GivenScriptExist("/Working/script.cake", "using(new Temp())\n{\n}");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(0, result.Script.UsingAliases.Count);
                Assert.Equal(0, result.Script.Namespaces.Count);
                Assert.Equal(4, result.Lines.Count);
                Assert.Equal(result.Lines[0], "#line 1 \"/Working/script.cake\"");
                Assert.Equal(result.Lines[1], "using(new Temp())");
                Assert.Equal(result.Lines[2], "{");
                Assert.Equal(result.Lines[3], "}");
            }
Exemplo n.º 17
0
            public void Should_Log_Error_Location_In_Loaded_Script()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.Providers.Add(new FileLoadDirectiveProvider());
                fixture.GivenScriptExist("/Working/script.cake", "#load \"local:?path=script2.cake\"");
                fixture.GivenScriptExist("/Working/script2.cake", "\n#load \"local:?path=1&path=2\"");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(6, result.Lines.Count);
                Assert.False(result.Succeeded);
                Assert.Equal(1, result.Errors.Count);
                Assert.Equal("/Working/script2.cake", result.Errors[0].File.FullPath);
                Assert.Equal(2, result.Errors[0].Line);
                Assert.Equal("Query string for #load contains more than one parameter 'path'.", result.Errors[0].Message);
            }
Exemplo n.º 18
0
            public void Should_Log_Error_Location()
            {
                // Given
                var fixture = new ScriptAnalyzerFixture();

                fixture.Providers.Add(new FileLoadDirectiveProvider());
                fixture.GivenScriptExist("/Working/script.cake", "#load \"local:?pat\"");

                // When
                var result = fixture.Analyze("/Working/script.cake");

                // Then
                Assert.Equal(2, result.Lines.Count);
                Assert.Equal("#line 1 \"/Working/script.cake\"", result.Lines[0]);
                Assert.Equal("// #load \"local:?pat\"", result.Lines[1]);
                Assert.False(result.Succeeded);
                Assert.Equal(1, result.Errors.Count);
                Assert.Equal("/Working/script.cake", result.Errors[0].File.FullPath);
                Assert.Equal(1, result.Errors[0].Line);
                Assert.Equal("Query string for #load is missing parameter 'path'.", result.Errors[0].Message);
            }