|
1 |
| -using Dotnet.Script.DependencyModel.Environment; |
| 1 | +using Dotnet.Script.Core; |
| 2 | +using Dotnet.Script.DependencyModel.Environment; |
2 | 3 | using Dotnet.Script.Shared.Tests;
|
3 | 4 | using Newtonsoft.Json.Linq;
|
| 5 | +using System; |
4 | 6 | using System.IO;
|
| 7 | +using System.Reflection; |
5 | 8 | using System.Text.RegularExpressions;
|
6 | 9 | using Xunit;
|
7 |
| - |
| 10 | +using Xunit.Abstractions; |
8 | 11 |
|
9 | 12 | namespace Dotnet.Script.Tests
|
10 | 13 | {
|
11 | 14 | public class ScaffoldingTests
|
12 | 15 | {
|
13 | 16 | private readonly ScriptEnvironment _scriptEnvironment;
|
14 | 17 |
|
15 |
| - public ScaffoldingTests() |
| 18 | + public ScaffoldingTests(ITestOutputHelper testOutputHelper) |
16 | 19 | {
|
17 | 20 | _scriptEnvironment = ScriptEnvironment.Default;
|
| 21 | + testOutputHelper.Capture(); |
18 | 22 | }
|
19 | 23 |
|
20 | 24 | [Fact]
|
@@ -178,5 +182,46 @@ public void ShouldUpdatePathToDotnetScript()
|
178 | 182 | Assert.NotEqual("InvalidPath/dotnet-script.dll", config.SelectToken("configurations[0].args[1]").Value<string>());
|
179 | 183 | }
|
180 | 184 | }
|
| 185 | + |
| 186 | + [Fact] |
| 187 | + public void ShouldCreateUnifiedLaunchFileWhenInstalledAsGlobalTool() |
| 188 | + { |
| 189 | + Scaffolder scaffolder = CreateTestScaffolder("somefolder/.dotnet/tools/dotnet-script"); |
| 190 | + |
| 191 | + using (var scriptFolder = new DisposableFolder()) |
| 192 | + { |
| 193 | + scaffolder.InitializerFolder("main.csx", scriptFolder.Path); |
| 194 | + var fileContent = File.ReadAllText(Path.Combine(scriptFolder.Path, ".vscode", "launch.json")); |
| 195 | + Assert.Contains("{env:HOME}/.dotnet/tools/dotnet-script", fileContent); |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + [Fact] |
| 200 | + public void ShouldUpdateToUnifiedLaunchFileWhenInstalledAsGlobalTool() |
| 201 | + { |
| 202 | + Scaffolder scaffolder = CreateTestScaffolder("some-install-folder"); |
| 203 | + Scaffolder globalToolScaffolder = CreateTestScaffolder("somefolder/.dotnet/tools/dotnet-script"); |
| 204 | + using (var scriptFolder = new DisposableFolder()) |
| 205 | + { |
| 206 | + scaffolder.InitializerFolder("main.csx", scriptFolder.Path); |
| 207 | + var fileContent = File.ReadAllText(Path.Combine(scriptFolder.Path, ".vscode", "launch.json")); |
| 208 | + Assert.Contains("some-install-folder", fileContent); |
| 209 | + globalToolScaffolder.InitializerFolder("main.csx", scriptFolder.Path); |
| 210 | + fileContent = File.ReadAllText(Path.Combine(scriptFolder.Path, ".vscode", "launch.json")); |
| 211 | + Assert.Contains("{env:HOME}/.dotnet/tools/dotnet-script", fileContent); |
| 212 | + } |
| 213 | + } |
| 214 | + |
| 215 | + private static Scaffolder CreateTestScaffolder(string installLocation) |
| 216 | + { |
| 217 | + var scriptEnvironment = (ScriptEnvironment)Activator.CreateInstance(typeof(ScriptEnvironment), nonPublic: true); |
| 218 | + var installLocationField = typeof(ScriptEnvironment).GetField("_installLocation", BindingFlags.NonPublic | BindingFlags.Instance); |
| 219 | + installLocationField.SetValue(scriptEnvironment, new Lazy<string>(() => installLocation)); |
| 220 | + StringWriter output = new StringWriter(); |
| 221 | + StringWriter error = new StringWriter(); |
| 222 | + var scriptConsole = new ScriptConsole(output, StringReader.Null, error); |
| 223 | + var scaffolder = new Scaffolder(TestOutputHelper.CreateTestLogFactory(), scriptConsole, scriptEnvironment); |
| 224 | + return scaffolder; |
| 225 | + } |
181 | 226 | }
|
182 | 227 | }
|
0 commit comments