From cd75ae127698b66821b5a2d364aa5ff7aa1a4a2a Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Tue, 19 Jul 2022 18:59:08 +0200 Subject: [PATCH] [wasm][debugger] Removed duplicated testcases as a follow-up for #70560 (#71827) * Renaming. * Remoe duplicated testcases. * Added missing awaits. * Testing expressions with spaces, fixed indentation * Applied @radical's comments. --- .../EvaluateOnCallFrameTests.cs | 330 +++++++----------- .../debugger-test/debugger-evaluate-test.cs | 67 ++-- 2 files changed, 159 insertions(+), 238 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs index 250df7ef9e027..800c17b45843d 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/EvaluateOnCallFrameTests.cs @@ -40,12 +40,6 @@ public static IEnumerable InstanceMethodForTypeMembersTestData(string } } - public static IEnumerable EvaluateStaticClassFromStaticMethodTestData(string type_name) - { - yield return new object[] { type_name, "EvaluateAsyncMethods", $"{type_name}.EvaluateAsyncMethods", true }; - yield return new object[] { type_name, "EvaluateMethods", $"{type_name}.EvaluateMethods", false }; - } - [ConditionalTheory(nameof(RunningOnChrome))] [MemberData(nameof(InstanceMethodForTypeMembersTestData), parameters: "DebuggerTests.EvaluateTestsStructWithProperties")] [MemberData(nameof(InstanceMethodForTypeMembersTestData), parameters: "DebuggerTests.EvaluateTestsClassWithProperties")] @@ -704,243 +698,171 @@ await EvaluateOnCallFrameAndCheck(id, }); [Theory] - [InlineData("DebuggerTestsV2.EvaluateStaticClass", "Run", "DebuggerTestsV2", "EvaluateStaticClass", 1, 2)] - [InlineData("DebuggerTests.EvaluateStaticClass", "Run", "DebuggerTests", "EvaluateStaticClass", 1, 1)] - [InlineData("DebuggerTests.EvaluateStaticClass", "RunAsync", "DebuggerTests", "EvaluateStaticClass", 1, 1, true)] - [InlineData("DebuggerTests.EvaluateNonStaticClassWithStaticFields", "RunStatic", "DebuggerTests", "EvaluateNonStaticClassWithStaticFields", 1, 7)] - [InlineData("DebuggerTests.EvaluateNonStaticClassWithStaticFields", "RunStaticAsync", "DebuggerTests", "EvaluateNonStaticClassWithStaticFields", 1, 7, true)] - [InlineData("DebuggerTests.EvaluateNonStaticClassWithStaticFields", "Run", "DebuggerTests", "EvaluateNonStaticClassWithStaticFields", 1, 7)] - [InlineData("DebuggerTests.EvaluateNonStaticClassWithStaticFields", "RunAsync", "DebuggerTests", "EvaluateNonStaticClassWithStaticFields", 1, 7, true)] - public async Task EvaluateStaticFields(string bpLocation, string bpMethod, string namespaceName, string className, int bpLine, int expectedInt, bool isAsync = false) => + [InlineData("DebuggerTestsV2.EvaluateStaticFieldsInStaticClass", "Run", "DebuggerTestsV2", "EvaluateStaticFieldsInStaticClass", "EvaluateMethods", 1, 2)] + [InlineData("DebuggerTests.EvaluateStaticFieldsInStaticClass", "Run", "DebuggerTests", "EvaluateStaticFieldsInStaticClass", "EvaluateMethods", 1, 1)] + [InlineData("DebuggerTests.EvaluateStaticFieldsInStaticClass", "RunAsync", "DebuggerTests", "EvaluateStaticFieldsInStaticClass", "EvaluateMethodsAsync", 1, 1)] + [InlineData("DebuggerTests.EvaluateStaticFieldsInInstanceClass", "RunStatic", "DebuggerTests", "EvaluateStaticFieldsInInstanceClass", "EvaluateMethods", 1, 7)] + [InlineData("DebuggerTests.EvaluateStaticFieldsInInstanceClass", "RunStaticAsync", "DebuggerTests", "EvaluateStaticFieldsInInstanceClass", "EvaluateMethodsAsync", 1, 7)] + [InlineData("DebuggerTests.EvaluateStaticFieldsInInstanceClass", "Run", "DebuggerTests", "EvaluateStaticFieldsInInstanceClass", "EvaluateMethods", 1, 7)] + [InlineData("DebuggerTests.EvaluateStaticFieldsInInstanceClass", "RunAsync", "DebuggerTests", "EvaluateStaticFieldsInInstanceClass", "EvaluateMethodsAsync", 1, 7)] + public async Task EvaluateStaticFields( + string bpLocation, string bpMethod, string namespaceName, string className, string triggeringMethod, int bpLine, int expectedInt) => await CheckInspectLocalsAtBreakpointSite( bpLocation, bpMethod, bpLine, $"{bpLocation}.{bpMethod}", - "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateMethods'); })", + $"window.setTimeout(function() {{ invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:{triggeringMethod}'); }})", wait_for_event_fn: async (pause_location) => { var id = pause_location["callFrames"][0]["callFrameId"].Value(); - await EvaluateOnCallFrameAndCheck(id, - ($"{namespaceName}.{className}.StaticField1", TNumber(expectedInt * 10)), - ($"{namespaceName}.{className}.StaticProperty1", TString($"StaticProperty{expectedInt}")), - ($"{namespaceName}.{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")), - ($"{className}.StaticField1", TNumber(expectedInt * 10)), - ($"{className}.StaticProperty1",TString($"StaticProperty{expectedInt}")), - ($"{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")), - ("StaticField1", TNumber(expectedInt * 10)), - ("StaticProperty1", TString($"StaticProperty{expectedInt}")), - ("StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")) - ); + foreach (var pad in new[] { String.Empty, " " }) + { + await EvaluateOnCallFrameAndCheck(id, + ($"{pad}{namespaceName}.{className}.StaticField", TNumber(expectedInt * 10)), + ($"{pad}{namespaceName}{pad}.{className}.{pad}StaticProperty", TString($"StaticProperty{expectedInt}")), + ($"{namespaceName}.{pad}{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")), + ($"{pad}{className}.{pad}StaticField", TNumber(expectedInt * 10)), + ($"{pad}{pad}{className}.StaticProperty", TString($"StaticProperty{expectedInt}")), + ($"{pad}{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")), + ($"{pad}StaticField{pad}", TNumber(expectedInt * 10)), + ($"{pad}StaticProperty", TString($"StaticProperty{expectedInt}")), + ($"{pad}StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")) + ); + } }); - [Fact] - public async Task EvaluateStaticClass() => await CheckInspectLocalsAtBreakpointSite( - "DebuggerTests.EvaluateMethodTestsClass.TestEvaluate", "run", 9, "DebuggerTests.EvaluateMethodTestsClass.TestEvaluate.run", - "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateMethods'); })", - wait_for_event_fn: async (pause_location) => - { - var id = pause_location["callFrames"][0]["callFrameId"].Value(); - - var frame = pause_location["callFrames"][0]; - - await EvaluateOnCallFrameAndCheck(id, - ("DebuggerTests.EvaluateStaticClass.StaticField1", TNumber(10))); - await EvaluateOnCallFrameAndCheck(id, - ("DebuggerTests.EvaluateStaticClass.StaticProperty1", TString("StaticProperty1"))); - await EvaluateOnCallFrameAndCheck(id, - ("DebuggerTests.EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented 1"))); - }); - - [Theory] - [MemberData(nameof(EvaluateStaticClassFromStaticMethodTestData), parameters: "DebuggerTests.EvaluateMethodTestsClass")] - // [MemberData(nameof(EvaluateStaticClassFromStaticMethodTestData), parameters: "EvaluateMethodTestsClass")] - public async Task EvaluateStaticClassFromStaticMethod(string type, string method, string bp_function_name, bool is_async) - => await CheckInspectLocalsAtBreakpointSite( - type, method, 1, bp_function_name, - $"window.setTimeout(function() {{ invoke_static_method ('[debugger-test] {type}:{method}'); }})", - wait_for_event_fn: async (pause_location) => - { - var id = pause_location["callFrames"][0]["callFrameId"].Value(); - - var frame = pause_location["callFrames"][0]; - - await EvaluateOnCallFrameAndCheck(id, - ("EvaluateStaticClass.StaticField1", TNumber(10)), - ("EvaluateStaticClass.StaticProperty1", TString("StaticProperty1")), - ("EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented 1")), - ("DebuggerTests.EvaluateStaticClass.StaticField1", TNumber(10)), - ("DebuggerTests.EvaluateStaticClass.StaticProperty1", TString("StaticProperty1")), - ("DebuggerTests.EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented 1"))); - }); - - [Fact] - public async Task EvaluateNonStaticClassWithStaticFields() => await CheckInspectLocalsAtBreakpointSite( - "DebuggerTests.EvaluateMethodTestsClass", "EvaluateAsyncMethods", 3, "DebuggerTests.EvaluateMethodTestsClass.EvaluateAsyncMethods", - "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateAsyncMethods'); })", - wait_for_event_fn: async (pause_location) => - { - var id = pause_location["callFrames"][0]["callFrameId"].Value(); - - var frame = pause_location["callFrames"][0]; - - await EvaluateOnCallFrameAndCheck(id, - ("DebuggerTests.EvaluateNonStaticClassWithStaticFields.StaticField1", TNumber(70)), - ("DebuggerTests.EvaluateNonStaticClassWithStaticFields.StaticProperty1", TString("StaticProperty7")), - ("DebuggerTests.EvaluateNonStaticClassWithStaticFields.StaticPropertyWithError", TString("System.Exception: not implemented 7")), - ("EvaluateNonStaticClassWithStaticFields.StaticField1", TNumber(70)), - ("EvaluateNonStaticClassWithStaticFields.StaticProperty1", TString("StaticProperty7")), - ("EvaluateNonStaticClassWithStaticFields.StaticPropertyWithError", TString("System.Exception: not implemented 7"))); - }); - [ConditionalFact(nameof(RunningOnChrome))] public async Task EvaluateStaticClassesNested() => await CheckInspectLocalsAtBreakpointSite( "DebuggerTests.EvaluateMethodTestsClass", "EvaluateMethods", 3, "DebuggerTests.EvaluateMethodTestsClass.EvaluateMethods", "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateMethods'); })", wait_for_event_fn: async (pause_location) => - { - var id = pause_location["callFrames"][0]["callFrameId"].Value(); - - var frame = pause_location["callFrames"][0]; - - await EvaluateOnCallFrameAndCheck(id, - ("DebuggerTests.EvaluateStaticClass.NestedClass1.NestedClass2.NestedClass3.StaticField1", TNumber(3)), - ("DebuggerTests.EvaluateStaticClass.NestedClass1.NestedClass2.NestedClass3.StaticProperty1", TString("StaticProperty3")), - ("DebuggerTests.EvaluateStaticClass.NestedClass1.NestedClass2.NestedClass3.StaticPropertyWithError", TString("System.Exception: not implemented 3")), - ("EvaluateStaticClass.NestedClass1.NestedClass2.NestedClass3.StaticField1", TNumber(3)), - ("EvaluateStaticClass.NestedClass1.NestedClass2.NestedClass3.StaticProperty1", TString("StaticProperty3")), - ("EvaluateStaticClass.NestedClass1.NestedClass2.NestedClass3.StaticPropertyWithError", TString("System.Exception: not implemented 3"))); - }); + { + var id = pause_location["callFrames"][0]["callFrameId"].Value(); + foreach (var pad in new[] { String.Empty, " " }) + { + await EvaluateOnCallFrameAndCheck(id, + ($"{pad}DebuggerTests{pad}.EvaluateStaticFieldsInStaticClass.NestedClass1.{pad}NestedClass2.NestedClass3.{pad}StaticField", TNumber(3)), + ($"{pad}DebuggerTests.EvaluateStaticFieldsInStaticClass.NestedClass1.NestedClass2.NestedClass3.StaticProperty", TString("StaticProperty3")), + ($"{pad}{pad}DebuggerTests.{pad}EvaluateStaticFieldsInStaticClass.NestedClass1.NestedClass2.NestedClass3.{pad}StaticPropertyWithError", TString("System.Exception: not implemented 3")), + ($"EvaluateStaticFieldsInStaticClass.{pad}NestedClass1.{pad}NestedClass2.NestedClass3.StaticField", TNumber(3)), + ($"EvaluateStaticFieldsInStaticClass.NestedClass1.{pad}{pad}NestedClass2.NestedClass3.{pad}StaticProperty", TString("StaticProperty3")), + ($"{pad}EvaluateStaticFieldsInStaticClass.NestedClass1.{pad}NestedClass2.{pad}NestedClass3.StaticPropertyWithError", TString("System.Exception: not implemented 3"))); + } + }); [Fact] public async Task EvaluateStaticClassesNestedWithNoNamespace() => await CheckInspectLocalsAtBreakpointSite( "NoNamespaceClass", "EvaluateMethods", 1, "NoNamespaceClass.EvaluateMethods", "window.setTimeout(function() { invoke_static_method ('[debugger-test] NoNamespaceClass:EvaluateMethods'); })", wait_for_event_fn: async (pause_location) => - { - var id = pause_location["callFrames"][0]["callFrameId"].Value(); - - var frame = pause_location["callFrames"][0]; - - await EvaluateOnCallFrameAndCheck(id, - ("NoNamespaceClass.NestedClass1.NestedClass2.NestedClass3.StaticField1", TNumber(30)), - ("NoNamespaceClass.NestedClass1.NestedClass2.NestedClass3.StaticProperty1", TString("StaticProperty30")), - ("NoNamespaceClass.NestedClass1.NestedClass2.NestedClass3.StaticPropertyWithError", TString("System.Exception: not implemented 30"))); - }); + { + var id = pause_location["callFrames"][0]["callFrameId"].Value(); + foreach (var pad in new[] { String.Empty, " " }) + { + await EvaluateOnCallFrameAndCheck(id, + ($"{pad}NoNamespaceClass.NestedClass1.NestedClass2.{pad}NestedClass3.StaticField", TNumber(30)), + ($"NoNamespaceClass.NestedClass1.{pad}NestedClass2.NestedClass3.StaticProperty", TString("StaticProperty30")), + ($"NoNamespaceClass.{pad}NestedClass1.NestedClass2.NestedClass3.{pad}StaticPropertyWithError", TString("System.Exception: not implemented 30"))); + } + }); [Fact] public async Task EvaluateStaticClassesNestedWithSameNames() => await CheckInspectLocalsAtBreakpointSite( "NestedWithSameNames.B.NestedWithSameNames.B", "Run", 1, "NestedWithSameNames.B.NestedWithSameNames.B.Run", "window.setTimeout(function() { invoke_static_method ('[debugger-test] NestedWithSameNames:Evaluate'); })", wait_for_event_fn: async (pause_location) => - { - var id = pause_location["callFrames"][0]["callFrameId"].Value(); - - await EvaluateOnCallFrameAndCheck(id, - ("NestedWithSameNames", TNumber(90)), - ("B.NestedWithSameNames", TNumber(90)), - ("B.StaticField1", TNumber(40)), - ("B.StaticProperty1", TString("StaticProperty4")), - ("B.StaticPropertyWithError", TString("System.Exception: not implemented V4")) - ); - - await CheckEvaluateFail(id, - ("NestedWithSameNames.B.StaticField1", GetPrimitiveHasNoMembersMessage("B")), - ("NestedWithSameNames.B.StaticProperty1", GetPrimitiveHasNoMembersMessage("B")), - ("NestedWithSameNames.B.StaticPropertyWithError", GetPrimitiveHasNoMembersMessage("B")), - ("NestedWithSameNames.B.NestedWithSameNames", GetPrimitiveHasNoMembersMessage("B")), - ("B.NestedWithSameNames.B.StaticField1", GetPrimitiveHasNoMembersMessage("B")), - ("B.NestedWithSameNames.B.StaticProperty1", GetPrimitiveHasNoMembersMessage("B")), - ("B.NestedWithSameNames.B.StaticPropertyWithError", GetPrimitiveHasNoMembersMessage("B")), - ("NestedWithSameNames.B.NestedWithSameNames.B.NestedWithSameNames", GetPrimitiveHasNoMembersMessage("B")), - ("NestedWithSameNames.B.NestedWithDifferentName.B.StaticField1", GetPrimitiveHasNoMembersMessage("B")), - ("NestedWithSameNames.B.NestedWithDifferentName.B.StaticProperty1", GetPrimitiveHasNoMembersMessage("B")), - ("NestedWithSameNames.B.NestedWithDifferentName.B.StaticPropertyWithError", GetPrimitiveHasNoMembersMessage("B")) - ); - string GetPrimitiveHasNoMembersMessage(string name) => $"Cannot find member '{name}' on a primitive type"; - }); - - [ConditionalTheory(nameof(RunningOnChrome))] - [InlineData("DebuggerTests", "EvaluateNonStaticClassWithStaticFields", 7, true)] - [InlineData("DebuggerTestsV2", "EvaluateStaticClass", 2)] - public async Task EvaluateStaticFieldsFromDifferentNamespaceInDifferentFrames(string namespaceName, string className, int expectedInt, bool isFromDifferentNamespace = false) => await CheckInspectLocalsAtBreakpointSite( - "DebuggerTestsV2.EvaluateStaticClass", "Run", 1, "DebuggerTestsV2.EvaluateStaticClass.Run", - "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateMethods'); })", - wait_for_event_fn: async (pause_location) => { - var id_top = pause_location["callFrames"][0]["callFrameId"].Value(); - await EvaluateOnCallFrameAndCheck(id_top, - ("StaticField1", TNumber(20)), - ($"{namespaceName}.{className}.StaticField1", TNumber(expectedInt * 10)), - ("StaticProperty1", TString($"StaticProperty2")), - ($"{namespaceName}.{className}.StaticProperty1", TString($"StaticProperty{expectedInt}")), - ("StaticPropertyWithError", TString($"System.Exception: not implemented 2")), - ($"{namespaceName}.{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")) - ); - - if (!isFromDifferentNamespace) + var id = pause_location["callFrames"][0]["callFrameId"].Value(); + foreach (var pad in new[] { String.Empty, " " }) { - await EvaluateOnCallFrameAndCheck(id_top, - ($"{className}.StaticField1", TNumber(expectedInt * 10)), - ($"{className}.StaticProperty1", TString($"StaticProperty{expectedInt}")), - ($"{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")) + await EvaluateOnCallFrameAndCheck(id, + ($"{pad}NestedWithSameNames", TNumber(90)), + ($"B.{pad}NestedWithSameNames", TNumber(90)), + ($"{pad}B.{pad}StaticField", TNumber(40)), + ($"{pad}{pad}B.StaticProperty", TString("StaticProperty4")), + ($"B.{pad}StaticPropertyWithError{pad}", TString("System.Exception: not implemented V4")) + ); + await CheckEvaluateFail(id, + ($"{pad}NestedWithSameNames.B.{pad}StaticField", GetPrimitiveHasNoMembersMessage("B")), + ($"NestedWithSameNames.{pad}B.StaticProperty", GetPrimitiveHasNoMembersMessage("B")), + ($"{pad}NestedWithSameNames{pad}.{pad}B.StaticPropertyWithError", GetPrimitiveHasNoMembersMessage("B")), + ($"{pad}NestedWithSameNames.B.{pad}NestedWithSameNames", GetPrimitiveHasNoMembersMessage("B")), + ($"B.NestedWithSameNames.{pad}B{pad}.StaticField", GetPrimitiveHasNoMembersMessage("B")), + ($"{pad}B.NestedWithSameNames.{pad}B.StaticProperty", GetPrimitiveHasNoMembersMessage("B")), + ($"B.NestedWithSameNames{pad}.B.{pad}StaticPropertyWithError", GetPrimitiveHasNoMembersMessage("B")), + ($"{pad}NestedWithSameNames.B{pad}.NestedWithSameNames.B{pad}.NestedWithSameNames{pad}", GetPrimitiveHasNoMembersMessage("B")), + ($"NestedWithSameNames.B{pad}.{pad}{pad}NestedWithDifferentName.B.{pad}StaticField", GetPrimitiveHasNoMembersMessage("B")), + ($"{pad}NestedWithSameNames.B.NestedWithDifferentName.B.StaticProperty", GetPrimitiveHasNoMembersMessage("B")), + ($"NestedWithSameNames.{pad}B.{pad}NestedWithDifferentName.B.{pad}StaticPropertyWithError", GetPrimitiveHasNoMembersMessage("B")) ); } - - var id_second = pause_location["callFrames"][1]["callFrameId"].Value(); - int expectedIntInPrevFrame = isFromDifferentNamespace ? 7 : 1; - await EvaluateOnCallFrameAndCheck(id_second, - ($"{namespaceName}.{className}.StaticField1", TNumber(expectedInt * 10)), - ($"{className}.StaticField1", TNumber(expectedIntInPrevFrame * 10)), - ($"{namespaceName}.{className}.StaticProperty1", TString($"StaticProperty{expectedInt}")), - ($"{className}.StaticProperty1", TString($"StaticProperty{expectedIntInPrevFrame}")), - ($"{namespaceName}.{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")), - ($"{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedIntInPrevFrame}")) - ); - - await CheckEvaluateFail(id_second, - ("StaticField1", GetNonExistingVarMessage("StaticField1")), - ("StaticProperty1", GetNonExistingVarMessage("StaticProperty1")), - ("StaticPropertyWithError", GetNonExistingVarMessage("StaticPropertyWithError")) - ); - string GetNonExistingVarMessage(string name) => $"The name {name} does not exist in the current context"; + string GetPrimitiveHasNoMembersMessage(string name) => $"Cannot find member '{name}' on a primitive type"; }); - [ConditionalFact(nameof(RunningOnChrome))] - public async Task EvaluateStaticClassesFromDifferentNamespaceInDifferentFrames() => await CheckInspectLocalsAtBreakpointSite( - "DebuggerTestsV2.EvaluateStaticClass", "Run", 1, "DebuggerTestsV2.EvaluateStaticClass.Run", - "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateMethods'); })", - wait_for_event_fn: async (pause_location) => - { - var id_top = pause_location["callFrames"][0]["callFrameId"].Value(); - var frame = pause_location["callFrames"][0]; - - await EvaluateOnCallFrameAndCheck(id_top, - ("EvaluateStaticClass.StaticField1", TNumber(20)), - ("EvaluateStaticClass.StaticProperty1", TString("StaticProperty2")), - ("EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented 2"))); - - var id_second = pause_location["callFrames"][1]["callFrameId"].Value(); + [ConditionalTheory(nameof(RunningOnChrome))] + [InlineData("DebuggerTests", "EvaluateStaticFieldsInInstanceClass", 7, true)] + [InlineData("DebuggerTestsV2", "EvaluateStaticFieldsInStaticClass", 2, false)] + public async Task EvaluateStaticFieldsFromDifferentNamespaceInDifferentFrames( + string namespaceName, string className, int expectedInt, bool isFromDifferentNamespace) => + await CheckInspectLocalsAtBreakpointSite( + "DebuggerTestsV2.EvaluateStaticFieldsInStaticClass", "Run", 1, "DebuggerTestsV2.EvaluateStaticFieldsInStaticClass.Run", + "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateMethods'); })", + wait_for_event_fn: async (pause_location) => + { + var id_top = pause_location["callFrames"][0]["callFrameId"].Value(); + var id_second = pause_location["callFrames"][1]["callFrameId"].Value(); + int expectedIntInPrevFrame = isFromDifferentNamespace ? 7 : 1; - await EvaluateOnCallFrameAndCheck(id_second, - ("EvaluateStaticClass.StaticField1", TNumber(10)), - ("EvaluateStaticClass.StaticProperty1", TString("StaticProperty1")), - ("EvaluateStaticClass.StaticPropertyWithError", TString("System.Exception: not implemented 1"))); - }); + foreach (var pad in new[] { String.Empty, " " }) + { + await EvaluateOnCallFrameAndCheck(id_top, + ($"{pad}StaticField", TNumber(20)), + ($"{pad}{namespaceName}.{pad}{className}.StaticField{pad}", TNumber(expectedInt * 10)), + ($"{pad}StaticProperty", TString($"StaticProperty2")), + ($"{pad}{namespaceName}.{pad}{className}.StaticProperty", TString($"StaticProperty{expectedInt}")), + ($"{pad}StaticPropertyWithError", TString($"System.Exception: not implemented 2")), + ($"{pad}{namespaceName}{pad}.{pad}{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")) + ); + + if (!isFromDifferentNamespace) + { + await EvaluateOnCallFrameAndCheck(id_top, + ($"{pad}{className}.StaticField", TNumber(expectedInt * 10)), + ($"{className}{pad}.StaticProperty{pad}", TString($"StaticProperty{expectedInt}")), + ($"{className}{pad}.{pad}StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")) + ); + } + + await EvaluateOnCallFrameAndCheck(id_second, + ($"{pad}{namespaceName}.{pad}{className}.{pad}StaticField", TNumber(expectedInt * 10)), + ($"{pad}{className}.StaticField", TNumber(expectedIntInPrevFrame * 10)), + ($"{namespaceName}{pad}.{pad}{className}.StaticProperty", TString($"StaticProperty{expectedInt}")), + ($"{pad}{className}.StaticProperty", TString($"StaticProperty{expectedIntInPrevFrame}")), + ($"{pad}{namespaceName}.{className}.StaticPropertyWithError", TString($"System.Exception: not implemented {expectedInt}")), + ($"{className}{pad}.StaticPropertyWithError{pad}", TString($"System.Exception: not implemented {expectedIntInPrevFrame}")) + ); + + await CheckEvaluateFail(id_second, + ($"{pad}StaticField", GetNonExistingVarMessage("StaticField")), + ($"{pad}{pad}StaticProperty", GetNonExistingVarMessage("StaticProperty")), + ($"{pad}StaticPropertyWithError{pad}", GetNonExistingVarMessage("StaticPropertyWithError")) + ); + } + string GetNonExistingVarMessage(string name) => $"The name {name} does not exist in the current context"; + }); [ConditionalFact(nameof(RunningOnChrome))] public async Task EvaluateStaticClassInvalidField() => await CheckInspectLocalsAtBreakpointSite( "DebuggerTests.EvaluateMethodTestsClass.TestEvaluate", "run", 9, "DebuggerTests.EvaluateMethodTestsClass.TestEvaluate.run", "window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.EvaluateMethodTestsClass:EvaluateMethods'); })", wait_for_event_fn: async (pause_location) => - { - var id = pause_location["callFrames"][0]["callFrameId"].Value(); - - var frame = pause_location["callFrames"][0]; + { + var id = pause_location["callFrames"][0]["callFrameId"].Value(); - var (_, res) = await EvaluateOnCallFrame(id, "DebuggerTests.EvaluateStaticClass.StaticProperty2", expect_ok: false); - AssertEqual("Failed to resolve member access for DebuggerTests.EvaluateStaticClass.StaticProperty2", res.Error["result"]?["description"]?.Value(), "wrong error message"); + var (_, res) = await EvaluateOnCallFrame(id, "DebuggerTests.EvaluateStaticFieldsInStaticClass.StaticProperty2", expect_ok: false); + AssertEqual("Failed to resolve member access for DebuggerTests.EvaluateStaticFieldsInStaticClass.StaticProperty2", res.Error["result"]?["description"]?.Value(), "wrong error message"); - (_, res) = await EvaluateOnCallFrame(id, "DebuggerTests.InvalidEvaluateStaticClass.StaticProperty2", expect_ok: false); - AssertEqual("Failed to resolve member access for DebuggerTests.InvalidEvaluateStaticClass.StaticProperty2", res.Error["result"]?["description"]?.Value(), "wrong error message"); - }); + (_, res) = await EvaluateOnCallFrame(id, "DebuggerTests.InvalidEvaluateStaticClass.StaticProperty2", expect_ok: false); + AssertEqual("Failed to resolve member access for DebuggerTests.InvalidEvaluateStaticClass.StaticProperty2", res.Error["result"]?["description"]?.Value(), "wrong error message"); + }); [ConditionalFact(nameof(RunningOnChrome))] public async Task AsyncLocalsInContinueWithBlock() => await CheckInspectLocalsAtBreakpointSite( diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-evaluate-test.cs b/src/mono/wasm/debugger/tests/debugger-test/debugger-evaluate-test.cs index b24676a72a688..74a8ac7424c46 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-evaluate-test.cs +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-evaluate-test.cs @@ -421,27 +421,26 @@ public static void EvaluateMethods() { TestEvaluate f = new TestEvaluate(); f.run(100, 200, "9000", "test", 45); - DebuggerTestsV2.EvaluateStaticClass.Run(); - DebuggerTests.EvaluateStaticClass.Run(); - DebuggerTests.EvaluateStaticClass.RunAsync(); - DebuggerTests.EvaluateNonStaticClassWithStaticFields.RunStatic(); - DebuggerTests.EvaluateNonStaticClassWithStaticFields.RunStaticAsync(); - var instanceWithStaticFields = new EvaluateNonStaticClassWithStaticFields(); + DebuggerTestsV2.EvaluateStaticFieldsInStaticClass.Run(); + DebuggerTests.EvaluateStaticFieldsInStaticClass.Run(); + DebuggerTests.EvaluateStaticFieldsInInstanceClass.RunStatic(); + var instanceWithStaticFields = new EvaluateStaticFieldsInInstanceClass(); instanceWithStaticFields.Run(); - instanceWithStaticFields.RunAsync(); } - public static void EvaluateAsyncMethods() + public static async Task EvaluateMethodsAsync() { - var staticClass = new EvaluateNonStaticClassWithStaticFields(); - staticClass.run(); + await DebuggerTests.EvaluateStaticFieldsInStaticClass.RunAsync(); + await DebuggerTests.EvaluateStaticFieldsInInstanceClass.RunStaticAsync(); + var instanceWithStaticFields = new EvaluateStaticFieldsInInstanceClass(); + await instanceWithStaticFields.RunAsync(); } } - public static class EvaluateStaticClass + public static class EvaluateStaticFieldsInStaticClass { - public static int StaticField1 = 10; - public static string StaticProperty1 => "StaticProperty1"; + public static int StaticField = 10; + public static string StaticProperty => "StaticProperty1"; public static string StaticPropertyWithError => throw new Exception("not implemented 1"); public static void Run() @@ -449,7 +448,7 @@ public static void Run() bool stop = true; } - public async static void RunAsync() + public async static Task RunAsync() { await Task.FromResult(0); } @@ -460,18 +459,18 @@ public static class NestedClass2 { public static class NestedClass3 { - public static int StaticField1 = 3; - public static string StaticProperty1 => "StaticProperty3"; + public static int StaticField = 3; + public static string StaticProperty => "StaticProperty3"; public static string StaticPropertyWithError => throw new Exception("not implemented 3"); } } } } - public class EvaluateNonStaticClassWithStaticFields + public class EvaluateStaticFieldsInInstanceClass { - public static int StaticField1 = 70; - public static string StaticProperty1 => "StaticProperty7"; + public static int StaticField = 70; + public static string StaticProperty => "StaticProperty7"; public static string StaticPropertyWithError => throw new Exception("not implemented 7"); public void Run() @@ -479,7 +478,7 @@ public void Run() bool stop = true; } - public async void RunAsync() + public async Task RunAsync() { await Task.FromResult(0); } @@ -489,7 +488,7 @@ public static void RunStatic() bool stop = true; } - public static async void RunStaticAsync() + public static async Task RunStaticAsync() { await Task.FromResult(0); } @@ -1464,10 +1463,10 @@ static void Evaluate() namespace DebuggerTestsV2 { - public static class EvaluateStaticClass + public static class EvaluateStaticFieldsInStaticClass { - public static int StaticField1 = 20; - public static string StaticProperty1 => "StaticProperty2"; + public static int StaticField = 20; + public static string StaticProperty => "StaticProperty2"; public static string StaticPropertyWithError => throw new Exception("not implemented 2"); public static void Run() @@ -1479,14 +1478,14 @@ public static void Run() public static class NestedWithSameNames { - public static int StaticField1 = 30; - public static string StaticProperty1 => "StaticProperty3"; + public static int StaticField = 30; + public static string StaticProperty => "StaticProperty3"; public static string StaticPropertyWithError => throw new Exception("not implemented V3"); public static class B { - public static int StaticField1 = 60; - public static string StaticProperty1 => "StaticProperty6"; + public static int StaticField = 60; + public static string StaticProperty => "StaticProperty6"; public static string StaticPropertyWithError => throw new Exception("not implemented V6"); public static class NestedWithSameNames @@ -1494,8 +1493,8 @@ public static class NestedWithSameNames public static class B { public static int NestedWithSameNames = 90; - public static int StaticField1 = 40; - public static string StaticProperty1 => "StaticProperty4"; + public static int StaticField = 40; + public static string StaticProperty => "StaticProperty4"; public static string StaticPropertyWithError => throw new Exception("not implemented V4"); public static void Run() @@ -1508,8 +1507,8 @@ public static class NestedWithDifferentName { public static class B { - public static int StaticField1 = 70; - public static string StaticProperty1 => "StaticProperty7"; + public static int StaticField = 70; + public static string StaticProperty => "StaticProperty7"; public static string StaticPropertyWithError => throw new Exception("not implemented V7"); } } @@ -1535,8 +1534,8 @@ public static class NestedClass2 { public static class NestedClass3 { - public static int StaticField1 = 30; - public static string StaticProperty1 => "StaticProperty30"; + public static int StaticField = 30; + public static string StaticProperty => "StaticProperty30"; public static string StaticPropertyWithError => throw new Exception("not implemented 30"); } }