diff options
author | Jeffrey Stedfast <jestedfa@microsoft.com> | 2019-05-09 21:11:42 +0300 |
---|---|---|
committer | Jeffrey Stedfast <jestedfa@microsoft.com> | 2019-05-20 20:14:28 +0300 |
commit | 70ac70a3596b1fc5972510133fa700edecc49dd6 (patch) | |
tree | 138f4d726618f0f7ea717278021ebb4513b1ff92 /main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests | |
parent | c33e71ec4ac630876a4b078acee10c902f046b49 (diff) |
[Debugger] Refactored unit tests to better allow testing of the DotNetCore debugger backend
Diffstat (limited to 'main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests')
2 files changed, 153 insertions, 138 deletions
diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests/DebugTests.MonoDevelop.cs b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests/DebugTests.MonoDevelop.cs index 5e9a098fd6..0bafdcd00f 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests/DebugTests.MonoDevelop.cs +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests/DebugTests.MonoDevelop.cs @@ -1,142 +1,155 @@ -using System;
-using System.IO;
-using System.Linq;
-using Mono.Debugging.Client;
-using MonoDevelop.Core;
-using MonoDevelop.Core.Assemblies;
-using MonoDevelop.Core.Execution;
-using MonoDevelop.Debugger;
-using NUnit.Framework;
-
-using MDTextFile = MonoDevelop.Projects.Text.TextFile;
-using System.Diagnostics;
-
-namespace Mono.Debugging.Tests
-{
- public abstract partial class DebugTests
- {
- DebuggerEngine engine;
- TargetRuntime runtime;
-
- static bool testProjectReady;
-
- partial void SetUpPartial()
- {
- foreach (var e in DebuggingService.GetDebuggerEngines ()) {
- if (e.Id == EngineId) {
- engine = e;
- break;
- }
- }
- if (engine == null)
- Assert.Ignore ("Engine not found: {0}", EngineId);
-
- if (!testProjectReady) {
- testProjectReady = true;
- var packagesConfig = Path.Combine (TargetProjectSourceDir, "packages.config");
- var packagesDir = Path.Combine (TargetProjectSourceDir, "packages");
- Process.Start ("nuget", $"restore \"{packagesConfig}\" -PackagesDirectory \"{packagesDir}\"").WaitForExit ();
- Process.Start ("msbuild", "\"" + TargetProjectSourceDir + "\"").WaitForExit ();
- }
- }
-
- partial void TearDownPartial ()
- {
- }
-
- protected string TargetExeDirectory
- {
- get {
- FilePath path = TargetProjectSourceDir;
- return path.Combine ("bin", "Debug");
- }
- }
-
- protected string TargetProjectSourceDir
- {
- get {
- FilePath path = Path.GetDirectoryName (GetType ().Assembly.Location);
- return path.Combine ("DebuggerTestProjects", TestAppProjectDirName);
- }
- }
-
- protected DebuggerSession CreateSession (string test, string engineId)
- {
- switch (engineId) {
- case "MonoDevelop.Debugger.Win32":
- runtime = Runtime.SystemAssemblyService.GetTargetRuntime ("MS.NET");
- break;
- case "Mono.Debugger.Soft":
- runtime = Runtime.SystemAssemblyService.GetTargetRuntimes ()
- .OfType<MonoTargetRuntime> ()
- .OrderByDescending ((o) => {
- //Attempt to find latest version of Mono registred in IDE and use that for unit tests
- if (string.IsNullOrWhiteSpace (o.Version) || o.Version == "Unknown")
- return new Version (0, 0, 0, 0);
- int indexOfBeforeDetails = o.Version.IndexOf (" (", StringComparison.Ordinal);
- string hopefullyVersion;
+using System; +using System.IO; +using System.Linq; +using System.Diagnostics; + +using Mono.Debugging.Client; +using MonoDevelop.Core; +using MonoDevelop.Core.Assemblies; +using MonoDevelop.Core.Execution; +using MonoDevelop.Debugger; + +using NUnit.Framework; + +using MDTextFile = MonoDevelop.Projects.Text.TextFile; + +namespace Mono.Debugging.Tests +{ + public abstract partial class DebugTests + { + static bool testProjectReady; + + DebuggerEngine engine; + TargetRuntime runtime; + + protected virtual string TestAppProjectDirName { + get { return "MonoDevelop.Debugger.Tests.TestApp"; } + } + + protected virtual string TestAppExeName { + get { return TestAppProjectDirName + ".exe"; } + } + + partial void SetUpPartial () + { + engine = DebuggingService.GetDebuggerEngines ().FirstOrDefault (e => e.Id == EngineId); + + if (engine == null) + Assert.Ignore ("Engine not found: {0}", EngineId); + + if (!testProjectReady) { + testProjectReady = true; + var packagesConfig = Path.Combine (TargetProjectSourceDir, "packages.config"); + var packagesDir = Path.Combine (TargetProjectSourceDir, "packages"); + + if (File.Exists (packagesConfig)) { + Process.Start ("nuget", $"restore \"{packagesConfig}\" -PackagesDirectory \"{packagesDir}\"").WaitForExit (); + } else { + var projFile = Path.Combine (TargetProjectSourceDir, TestAppProjectDirName + ".csproj"); + + Process.Start ("nuget", $"restore \"{projFile}\" -PackagesDirectory \"{packagesDir}\"").WaitForExit (); + } + + Process.Start ("msbuild", "\"" + TargetProjectSourceDir + "\"").WaitForExit (); + } + } + + partial void TearDownPartial () + { + } + + protected string TargetExeDirectory { + get { + return Path.Combine (TargetProjectSourceDir, "bin", "Debug"); + } + } + + protected string TargetProjectSourceDir { + get { + var path = Path.GetDirectoryName (GetType ().Assembly.Location); + + return Path.Combine (path, "DebuggerTestProjects", TestAppProjectDirName); + } + } + + protected virtual DebuggerSession CreateSession (string test, string engineId) + { + switch (engineId) { + case "MonoDevelop.Debugger.Win32": + runtime = Runtime.SystemAssemblyService.GetTargetRuntime ("MS.NET"); + break; + case "Mono.Debugger.Soft": + runtime = Runtime.SystemAssemblyService.GetTargetRuntimes () + .OfType<MonoTargetRuntime> () + .OrderByDescending ((o) => { + //Attempt to find latest version of Mono registred in IDE and use that for unit tests + if (string.IsNullOrWhiteSpace (o.Version) || o.Version == "Unknown") + return new Version (0, 0, 0, 0); + + int indexOfBeforeDetails = o.Version.IndexOf (" (", StringComparison.Ordinal); + + string hopefullyVersion; if (indexOfBeforeDetails != -1) hopefullyVersion = o.Version.Remove (indexOfBeforeDetails); else hopefullyVersion = o.Version; - Version version;
- if (Version.TryParse (hopefullyVersion, out version)) {
- return version;
- } else {
- return new Version (0, 0, 0, 0);
- }
- }).FirstOrDefault ();
- break;
- default:
- runtime = Runtime.SystemAssemblyService.DefaultRuntime;
- break;
- }
-
- if (runtime == null) {
- Assert.Ignore ("Runtime not found for: {0}", engineId);
- }
-
- Console.WriteLine ("Target Runtime: " + runtime.DisplayRuntimeName + " " + runtime.Version + " " + (IntPtr.Size == 8 ? "64bit" : "32bit"));
-
- // main/build/tests
- var exe = TargetExePath;
-
- var cmd = new DotNetExecutionCommand ();
- cmd.TargetRuntime = runtime;
- cmd.Command = exe;
- cmd.Arguments = test;
-
- if (Platform.IsWindows) {
- var monoRuntime = runtime as MonoTargetRuntime;
- if (monoRuntime != null) {
- var psi = new System.Diagnostics.ProcessStartInfo (Path.Combine (monoRuntime.Prefix, "bin", "pdb2mdb.bat"), exe);
- psi.UseShellExecute = false;
- psi.CreateNoWindow = true;
- System.Diagnostics.Process.Start (psi).WaitForExit ();
- }
- }
- return engine.CreateSession ();
- }
-
- protected DebuggerStartInfo CreateStartInfo (string test, string engineId)
- {
- var cmd = new DotNetExecutionCommand {
- TargetRuntime = runtime,
- Command = TargetExePath,
- Arguments = test
- };
- var dsi = engine.CreateDebuggerStartInfo (cmd);
- return dsi;
- }
-
- /// <summary>
- /// Reads file from given path
- /// </summary>
- /// <param name="sourcePath"></param>
- /// <returns></returns>
- public static ITextFile ReadFile (string sourcePath)
- {
- return new TextFile(MDTextFile.ReadFile (sourcePath));
- }
- }
-}
\ No newline at end of file + + if (Version.TryParse (hopefullyVersion, out var version)) + return version; + + return new Version (0, 0, 0, 0); + }).FirstOrDefault (); + break; + default: + runtime = Runtime.SystemAssemblyService.DefaultRuntime; + break; + } + + if (runtime == null) + Assert.Ignore ("Runtime not found for: {0}", engineId); + + Console.WriteLine ("Target Runtime: " + runtime.DisplayRuntimeName + " " + runtime.Version + " " + (IntPtr.Size == 8 ? "64bit" : "32bit")); + + // main/build/tests + var exe = TargetExePath; + + var cmd = new DotNetExecutionCommand (); + cmd.TargetRuntime = runtime; + cmd.Command = exe; + cmd.Arguments = test; + + if (Platform.IsWindows) { + var monoRuntime = runtime as MonoTargetRuntime; + if (monoRuntime != null) { + var psi = new ProcessStartInfo (Path.Combine (monoRuntime.Prefix, "bin", "pdb2mdb.bat"), exe); + psi.UseShellExecute = false; + psi.CreateNoWindow = true; + Process.Start (psi).WaitForExit (); + } + } + + return engine.CreateSession (); + } + + protected DebuggerStartInfo CreateStartInfo (string test, string engineId) + { + var cmd = new DotNetExecutionCommand { + TargetRuntime = runtime, + Command = TargetExePath, + Arguments = test + }; + var dsi = engine.CreateDebuggerStartInfo (cmd); + return dsi; + } + + /// <summary> + /// Reads file from given path + /// </summary> + /// <param name="sourcePath"></param> + /// <returns></returns> + public static ITextFile ReadFile (string sourcePath) + { + return new TextFile (MDTextFile.ReadFile (sourcePath)); + } + } +} diff --git a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests/MonoDevelop.Debugger.Tests.csproj b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests/MonoDevelop.Debugger.Tests.csproj index d25737367e..66a368f365 100644 --- a/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests/MonoDevelop.Debugger.Tests.csproj +++ b/main/src/addins/MonoDevelop.Debugger/MonoDevelop.Debugger.Tests/MonoDevelop.Debugger.Tests.csproj @@ -17,6 +17,8 @@ </ItemGroup> <ItemGroup> <Compile Include="..\..\..\..\external\debugger-libs\UnitTests\Mono.Debugging.Tests\Shared\*.cs" /> + <Compile Include="..\..\..\..\external\debugger-libs\UnitTests\Mono.Debugging.Tests\Shared\Sdb\*.cs" /> + <Compile Include="..\..\..\..\external\debugger-libs\UnitTests\Mono.Debugging.Tests\Shared\Win32\*.cs" /> <Compile Include="DebugTests.MonoDevelop.cs" /> <Compile Include="TextFile.cs" /> </ItemGroup> |