Skip to content

Commit 30acd0f

Browse files
committed
Added tests for unified lanuch file
1 parent 550b265 commit 30acd0f

File tree

1 file changed

+48
-3
lines changed

1 file changed

+48
-3
lines changed

src/Dotnet.Script.Tests/ScaffoldingTests.cs

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
using Dotnet.Script.DependencyModel.Environment;
1+
using Dotnet.Script.Core;
2+
using Dotnet.Script.DependencyModel.Environment;
23
using Dotnet.Script.Shared.Tests;
34
using Newtonsoft.Json.Linq;
5+
using System;
46
using System.IO;
7+
using System.Reflection;
58
using System.Text.RegularExpressions;
69
using Xunit;
7-
10+
using Xunit.Abstractions;
811

912
namespace Dotnet.Script.Tests
1013
{
1114
public class ScaffoldingTests
1215
{
1316
private readonly ScriptEnvironment _scriptEnvironment;
1417

15-
public ScaffoldingTests()
18+
public ScaffoldingTests(ITestOutputHelper testOutputHelper)
1619
{
1720
_scriptEnvironment = ScriptEnvironment.Default;
21+
testOutputHelper.Capture();
1822
}
1923

2024
[Fact]
@@ -178,5 +182,46 @@ public void ShouldUpdatePathToDotnetScript()
178182
Assert.NotEqual("InvalidPath/dotnet-script.dll", config.SelectToken("configurations[0].args[1]").Value<string>());
179183
}
180184
}
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+
}
181226
}
182227
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy