Skip to content

Commit 8151740

Browse files
authored
[wasm][debugger] Fix source-link test (dotnet#62786)
* Fix 62551 * Addressing @radical comments. * Adding comments to not forget what we were trying to test. Indenting.
1 parent e233b7b commit 8151740

File tree

4 files changed

+56
-15
lines changed

4 files changed

+56
-15
lines changed

src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,14 +824,14 @@ internal void AddMethod(MethodInfo mi)
824824
return (start.StartLocation.Line, start.StartLocation.Column, end.EndLocation.Line, end.EndLocation.Column);
825825
}
826826

827-
private async Task<MemoryStream> GetDataAsync(Uri uri, CancellationToken token)
827+
private static async Task<MemoryStream> GetDataAsync(Uri uri, CancellationToken token)
828828
{
829829
var mem = new MemoryStream();
830830
try
831831
{
832832
if (uri.IsFile && File.Exists(uri.LocalPath))
833833
{
834-
using (FileStream file = File.Open(SourceUri.LocalPath, FileMode.Open))
834+
using (FileStream file = File.Open(uri.LocalPath, FileMode.Open))
835835
{
836836
await file.CopyToAsync(mem, token).ConfigureAwait(false);
837837
mem.Position = 0;

src/mono/wasm/debugger/DebuggerTestSuite/Tests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,38 @@ await LoadAssemblyDynamically(
806806
Assert.DoesNotContain(source_location, scripts.Values);
807807
}
808808

809+
[Fact]
810+
public async Task GetSourceUsingSourceUri()
811+
{
812+
//testing without using sourcelink, expected values at GetSourceAsync
813+
//SourceUri - file:///LOCAL_PATH/runtime/src/mono/wasm/debugger/tests/debugger-test/debugger-test.cs
814+
//SourceLinkUri - empty
815+
var bp1_res = await SetBreakpoint("dotnet://debugger-test.dll/debugger-test.cs", 10, 8);
816+
817+
Assert.EndsWith("debugger-test.cs", bp1_res.Value["breakpointId"].ToString());
818+
Assert.Equal(1, bp1_res.Value["locations"]?.Value<JArray>()?.Count);
819+
820+
var loc = bp1_res.Value["locations"]?.Value<JArray>()[0];
821+
822+
var sourceToGet = JObject.FromObject(new
823+
{
824+
scriptId = loc["scriptId"]?.Value<string>()
825+
});
826+
827+
Assert.Equal("dotnet://debugger-test.dll/debugger-test.cs", scripts[loc["scriptId"]?.Value<string>()]);
828+
var source = await cli.SendCommand("Debugger.getScriptSource", sourceToGet, token);
829+
Assert.True(source.IsOk);
830+
}
809831
[Fact]
810832
public async Task GetSourceUsingSourceLink()
811833
{
834+
//testing using sourcelink, expected values at GetSourceAsync
835+
// On CI
836+
//SourceUri - file:///fakepath/LOCAL_PATH/runtime/src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs
837+
//SourceLinkUri - file:///LOCAL_PATH/runtime/src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs
838+
// Locally
839+
// SourceUri - file:////src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs
840+
// SourceLinkUri - https://raw.githubusercontent.com/FORK/runtime/COMMIT_ID/src/mono/wasm/debugger/tests/debugger-test-with-source-link/test.cs
812841
var bp = await SetBreakpointInMethod("debugger-test-with-source-link.dll", "DebuggerTests.ClassToBreak", "TestBreakpoint", 0);
813842
var pause_location = await EvaluateAndCheck(
814843
"window.setTimeout(function() { invoke_static_method ('[debugger-test-with-source-link] DebuggerTests.ClassToBreak:TestBreakpoint'); }, 1);",
Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<PackageId>LibraryTest</PackageId>
4-
<Version>1.0.0</Version>
5-
<PublishRepositoryUrl>true</PublishRepositoryUrl>
6-
<RepositoryUrl>https://github.com/dotnet/runtime.git</RepositoryUrl>
7-
<RepositoryType>git</RepositoryType>
8-
<EnableSourceLink>true</EnableSourceLink>
9-
<IncludeSymbols>true</IncludeSymbols>
10-
<DebugType>embedded</DebugType>
11-
<IncludeSymbols>true</IncludeSymbols>
12-
<DeterministicSourcePaths>true</DeterministicSourcePaths>
13-
<DisableSourceLink>false</DisableSourceLink>
14-
</PropertyGroup>
2+
<PropertyGroup>
3+
<PackageId>LibraryTest</PackageId>
4+
<Version>1.0.0</Version>
5+
<DeterministicSourcePaths>true</DeterministicSourcePaths>
6+
</PropertyGroup>
7+
<PropertyGroup Condition="'$(ContinuousIntegrationBuild)' != 'true'">
8+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
9+
<RepositoryUrl>https://github.com/dotnet/runtime.git</RepositoryUrl>
10+
<RepositoryType>git</RepositoryType>
11+
<EnableSourceLink>true</EnableSourceLink>
12+
<IncludeSymbols>true</IncludeSymbols>
13+
<DebugType>embedded</DebugType>
14+
<IncludeSymbols>true</IncludeSymbols>
15+
<DisableSourceLink>false</DisableSourceLink>
16+
</PropertyGroup>
17+
<PropertyGroup Condition="'$(ContinuousIntegrationBuild)' == 'true'">
18+
<SourceLink>source-link.json</SourceLink>
19+
<AppOutputBase>$(MSBuildProjectDirectory)\</AppOutputBase>
20+
<PathMap>$(AppOutputBase)=/fakepath/$(MSBuildProjectDirectory)</PathMap>
21+
</PropertyGroup>
1522
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"documents": {
3+
"/fakepath/*": ""
4+
}
5+
}

0 commit comments

Comments
 (0)