|
4 | 4 |
|
5 | 5 | using Cake.Core.Scripting.Processors.Loading; |
6 | 6 | using Cake.Core.Tests.Fixtures; |
| 7 | +using Cake.Testing.Xunit; |
7 | 8 | using Xunit; |
8 | 9 |
|
9 | 10 | namespace Cake.Core.Tests.Unit.Scripting.Processors |
@@ -137,5 +138,81 @@ public void Should_Insert_Line_Directives_When_Processing_Load_Directives() |
137 | 138 | Assert.Equal(result.Lines[11], "// #l b.cake"); |
138 | 139 | Assert.Equal(result.Lines[12], "int y=2;"); |
139 | 140 | } |
| 141 | + |
| 142 | + [Theory] |
| 143 | + [InlineData("#load \"/utils.cake\"")] |
| 144 | + [InlineData("#load \"local:?path=/utils.cake\"")] |
| 145 | + public void Should_Process_AbsolutePath_Script_Reference_Found_In_Source(string source) |
| 146 | + { |
| 147 | + // Given |
| 148 | + var fixture = new ScriptAnalyzerFixture(); |
| 149 | + fixture.Providers.Add(new FileLoadDirectiveProvider()); |
| 150 | + fixture.GivenScriptExist("/Working/script.cake", source); |
| 151 | + fixture.GivenScriptExist("/utils.cake", "Console.WriteLine();"); |
| 152 | + |
| 153 | + // When |
| 154 | + var result = fixture.Analyze("/Working/script.cake"); |
| 155 | + |
| 156 | + // Then |
| 157 | + Assert.Equal(1, result.Script.Includes.Count); |
| 158 | + Assert.Equal("/utils.cake", result.Script.Includes[0].Path.FullPath); |
| 159 | + } |
| 160 | + |
| 161 | + [Theory] |
| 162 | + [InlineData("#load \"test/utils.cake\"")] |
| 163 | + [InlineData("#load \"local:?path=test/utils.cake\"")] |
| 164 | + public void Should_Process_RelativePath_Script_Reference_Found_In_Source(string source) |
| 165 | + { |
| 166 | + // Given |
| 167 | + var fixture = new ScriptAnalyzerFixture(); |
| 168 | + fixture.Providers.Add(new FileLoadDirectiveProvider()); |
| 169 | + fixture.GivenScriptExist("/Working/script.cake", source); |
| 170 | + fixture.GivenScriptExist("/Working/test/utils.cake", "Console.WriteLine();"); |
| 171 | + |
| 172 | + // When |
| 173 | + var result = fixture.Analyze("/Working/script.cake"); |
| 174 | + |
| 175 | + // Then |
| 176 | + Assert.Equal(1, result.Script.Includes.Count); |
| 177 | + Assert.Equal("/Working/test/utils.cake", result.Script.Includes[0].Path.FullPath); |
| 178 | + } |
| 179 | + |
| 180 | + [WindowsTheory] |
| 181 | + [InlineData("#load \"c:/utils.cake\"")] |
| 182 | + [InlineData("#load \"local:?path=c:/utils.cake\"")] |
| 183 | + public void Should_Process_WindowsAbsolutePath_Script_Reference_Found_In_Source(string source) |
| 184 | + { |
| 185 | + // Given |
| 186 | + var fixture = new ScriptAnalyzerFixture(); |
| 187 | + fixture.Providers.Add(new FileLoadDirectiveProvider()); |
| 188 | + fixture.GivenScriptExist("/Working/script.cake", source); |
| 189 | + fixture.GivenScriptExist("c:/utils.cake", "Console.WriteLine();"); |
| 190 | + |
| 191 | + // When |
| 192 | + var result = fixture.Analyze("/Working/script.cake"); |
| 193 | + |
| 194 | + // Then |
| 195 | + Assert.Equal(1, result.Script.Includes.Count); |
| 196 | + Assert.Equal("c:/utils.cake", result.Script.Includes[0].Path.FullPath); |
| 197 | + } |
| 198 | + |
| 199 | + [WindowsTheory] |
| 200 | + [InlineData("#load \"test/utils.cake\"")] |
| 201 | + [InlineData("#load \"local:?path=test/utils.cake\"")] |
| 202 | + public void Should_Process_WindowsRelativePath_Script_Reference_Found_In_Source(string source) |
| 203 | + { |
| 204 | + // Given |
| 205 | + var fixture = new ScriptAnalyzerFixture(); |
| 206 | + fixture.Providers.Add(new FileLoadDirectiveProvider()); |
| 207 | + fixture.GivenScriptExist("/Working/script.cake", source); |
| 208 | + fixture.GivenScriptExist("/Working/test/utils.cake", "Console.WriteLine();"); |
| 209 | + |
| 210 | + // When |
| 211 | + var result = fixture.Analyze("/Working/script.cake"); |
| 212 | + |
| 213 | + // Then |
| 214 | + Assert.Equal(1, result.Script.Includes.Count); |
| 215 | + Assert.Equal("/Working/test/utils.cake", result.Script.Includes[0].Path.FullPath); |
| 216 | + } |
140 | 217 | } |
141 | 218 | } |
0 commit comments