Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 30acd0f

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

File tree

Expand file treeCollapse file tree

1 file changed

+48
-3
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+48
-3
lines changed

‎src/Dotnet.Script.Tests/ScaffoldingTests.cs

Copy file name to clipboardExpand all lines: src/Dotnet.Script.Tests/ScaffoldingTests.cs
+48-3Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.