Skip to content

Commit 5eadc6c

Browse files
committed
Split DebugTests into partial classes (part #1)
1 parent 7786ad8 commit 5eadc6c

File tree

3 files changed

+147
-82
lines changed

3 files changed

+147
-82
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using Mono.Debugging.Client;
5+
using MonoDevelop.Core;
6+
using MonoDevelop.Core.Assemblies;
7+
using MonoDevelop.Core.Execution;
8+
using NUnit.Framework;
9+
10+
namespace MonoDevelop.Debugger.Tests
11+
{
12+
public abstract partial class DebugTests
13+
{
14+
DebuggerEngine engine;
15+
TargetRuntime runtime;
16+
17+
partial void SetUpPartial()
18+
{
19+
foreach (var e in DebuggingService.GetDebuggerEngines ()) {
20+
if (e.Id == EngineId) {
21+
engine = e;
22+
break;
23+
}
24+
}
25+
if (engine == null)
26+
Assert.Ignore ("Engine not found: {0}", EngineId);
27+
}
28+
29+
partial void TearDownPartial ()
30+
{
31+
}
32+
33+
protected string TargetExeDirectory
34+
{
35+
get{
36+
return Path.GetDirectoryName (GetType ().Assembly.Location);
37+
}
38+
}
39+
40+
protected string TargetProjectSourceDir
41+
{
42+
get{
43+
FilePath path = TargetExeDirectory;
44+
return path.ParentDirectory.ParentDirectory.Combine ("src", "addins", "MonoDevelop.Debugger", TestAppProjectDirName);
45+
}
46+
}
47+
48+
protected DebuggerSession CreateSession (string test)
49+
{
50+
switch (EngineId) {
51+
case "MonoDevelop.Debugger.Win32":
52+
runtime = Runtime.SystemAssemblyService.GetTargetRuntime ("MS.NET");
53+
break;
54+
case "Mono.Debugger.Soft":
55+
runtime = Runtime.SystemAssemblyService.GetTargetRuntimes ()
56+
.OfType<MonoTargetRuntime> ()
57+
.OrderByDescending ((o) => {
58+
//Attempt to find latest version of Mono registred in IDE and use that for unit tests
59+
if (string.IsNullOrWhiteSpace (o.Version) || o.Version == "Unknown")
60+
return new Version (0, 0, 0, 0);
61+
int indexOfBeforeDetails = o.Version.IndexOf (" (", StringComparison.Ordinal);
62+
if (indexOfBeforeDetails == -1)
63+
return new Version (0, 0, 0, 0);
64+
string hopefullyVersion = o.Version.Remove (indexOfBeforeDetails);
65+
Version version;
66+
if (Version.TryParse (hopefullyVersion, out version)) {
67+
return version;
68+
} else {
69+
return new Version (0, 0, 0, 0);
70+
}
71+
}).FirstOrDefault ();
72+
break;
73+
default:
74+
runtime = Runtime.SystemAssemblyService.DefaultRuntime;
75+
break;
76+
}
77+
78+
if (runtime == null) {
79+
Assert.Ignore ("Runtime not found for: {0}", EngineId);
80+
}
81+
82+
Console.WriteLine ("Target Runtime: " + runtime.DisplayRuntimeName + " " + runtime.Version + " " + (IntPtr.Size == 8 ? "64bit" : "32bit"));
83+
84+
// main/build/tests
85+
var exe = TargetExePath;
86+
87+
var cmd = new DotNetExecutionCommand ();
88+
cmd.TargetRuntime = runtime;
89+
cmd.Command = exe;
90+
cmd.Arguments = test;
91+
92+
if (Platform.IsWindows) {
93+
var monoRuntime = runtime as MonoTargetRuntime;
94+
if (monoRuntime != null) {
95+
var psi = new System.Diagnostics.ProcessStartInfo (Path.Combine (monoRuntime.Prefix, "bin", "pdb2mdb.bat"), exe);
96+
psi.UseShellExecute = false;
97+
psi.CreateNoWindow = true;
98+
System.Diagnostics.Process.Start (psi).WaitForExit ();
99+
}
100+
}
101+
return engine.CreateSession ();
102+
}
103+
104+
protected DebuggerStartInfo CreateStartInfo (string test)
105+
{
106+
var cmd = new DotNetExecutionCommand {
107+
TargetRuntime = runtime,
108+
Command = TargetExePath,
109+
Arguments = test
110+
};
111+
var dsi = engine.CreateDebuggerStartInfo (cmd);
112+
return dsi;
113+
}
114+
}
115+
}

MonoDevelop.Debugger.Tests/DebugTests.cs

Lines changed: 30 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,27 @@
2626

2727
using System;
2828
using System.IO;
29-
using System.Linq;
3029
using System.Threading;
3130
using System.Reflection;
3231
using System.Collections.Generic;
3332

3433
using Mono.Debugging.Soft;
3534
using Mono.Debugging.Client;
3635

37-
using MonoDevelop.Core;
38-
using MonoDevelop.Core.Execution;
3936
using MonoDevelop.Projects.Text;
40-
using MonoDevelop.Core.Assemblies;
4137

4238
using NUnit.Framework;
4339

4440
namespace MonoDevelop.Debugger.Tests
4541
{
4642
[TestFixture]
47-
public abstract class DebugTests
43+
public abstract partial class DebugTests
4844
{
45+
const string TestAppExeName = "MonoDevelop.Debugger.Tests.TestApp.exe";
46+
const string TestAppProjectDirName = "MonoDevelop.Debugger.Tests.TestApp";
47+
4948
readonly ManualResetEvent targetStoppedEvent = new ManualResetEvent (false);
5049
readonly string EngineId;
51-
DebuggerEngine engine;
5250
string TestName = "";
5351
TextFile SourceFile;
5452

@@ -82,106 +80,57 @@ public void IgnoreSoftDebugger (string message = "")
8280
[TestFixtureSetUp]
8381
public virtual void SetUp ()
8482
{
85-
foreach (var e in DebuggingService.GetDebuggerEngines ()) {
86-
if (e.Id == EngineId) {
87-
engine = e;
88-
break;
89-
}
90-
}
91-
if (engine == null)
92-
Assert.Ignore ("Engine not found: {0}", EngineId);
83+
SetUpPartial ();
9384
}
9485

86+
partial void SetUpPartial();
87+
88+
9589
[TestFixtureTearDown]
9690
public virtual void TearDown ()
9791
{
92+
TearDownPartial ();
9893
if (Session != null) {
9994
Session.Exit ();
10095
Session.Dispose ();
10196
Session = null;
10297
}
10398
}
10499

105-
protected void Start (string test)
106-
{
107-
TargetRuntime runtime;
100+
partial void TearDownPartial ();
108101

109-
switch (EngineId) {
110-
case "MonoDevelop.Debugger.Win32":
111-
runtime = Runtime.SystemAssemblyService.GetTargetRuntime ("MS.NET");
112-
break;
113-
case "Mono.Debugger.Soft":
114-
runtime = Runtime.SystemAssemblyService.GetTargetRuntimes ()
115-
.OfType<MonoTargetRuntime> ()
116-
.OrderByDescending ((o) => {
117-
//Attempt to find latest version of Mono registred in IDE and use that for unit tests
118-
if (string.IsNullOrWhiteSpace (o.Version) || o.Version == "Unknown")
119-
return new Version (0, 0, 0, 0);
120-
int indexOfBeforeDetails = o.Version.IndexOf (" (", StringComparison.Ordinal);
121-
if (indexOfBeforeDetails == -1)
122-
return new Version (0, 0, 0, 0);
123-
string hopefullyVersion = o.Version.Remove (indexOfBeforeDetails);
124-
Version version;
125-
if (Version.TryParse (hopefullyVersion, out version)) {
126-
return version;
127-
} else {
128-
return new Version (0, 0, 0, 0);
129-
}
130-
}).FirstOrDefault ();
131-
break;
132-
default:
133-
runtime = Runtime.SystemAssemblyService.DefaultRuntime;
134-
break;
135-
}
136-
137-
if (runtime == null) {
138-
Assert.Ignore ("Runtime not found for: {0}", EngineId);
139-
return;
102+
protected string TargetExePath
103+
{
104+
get{
105+
return Path.Combine (TargetExeDirectory, TestAppExeName);
140106
}
107+
}
141108

142-
Console.WriteLine ("Target Runtime: " + runtime.DisplayRuntimeName + " " + runtime.Version + " " + (IntPtr.Size == 8 ? "64bit" : "32bit"));
143-
144-
// main/build/tests
145-
FilePath path = Path.GetDirectoryName (GetType ().Assembly.Location);
146-
var exe = Path.Combine (path, "MonoDevelop.Debugger.Tests.TestApp.exe");
147-
148-
var cmd = new DotNetExecutionCommand ();
149-
cmd.TargetRuntime = runtime;
150-
cmd.Command = exe;
151-
cmd.Arguments = test;
152-
153-
if (Platform.IsWindows) {
154-
var monoRuntime = runtime as MonoTargetRuntime;
155-
if (monoRuntime != null) {
156-
var psi = new System.Diagnostics.ProcessStartInfo (Path.Combine (monoRuntime.Prefix, "bin", "pdb2mdb.bat"), cmd.Command);
157-
psi.UseShellExecute = false;
158-
psi.CreateNoWindow = true;
159-
System.Diagnostics.Process.Start (psi).WaitForExit ();
160-
}
161-
}
109+
protected void Start (string test)
110+
{
111+
TestName = test;
112+
Session = CreateSession (test);
162113

163-
var dsi = engine.CreateDebuggerStartInfo (cmd);
114+
var dsi = CreateStartInfo (test);
164115
var soft = dsi as SoftDebuggerStartInfo;
165116

166117
if (soft != null) {
167-
var assemblyName = AssemblyName.GetAssemblyName (exe);
118+
var assemblyName = AssemblyName.GetAssemblyName (TargetExePath);
168119

169-
soft.UserAssemblyNames = new List<AssemblyName> ();
170-
soft.UserAssemblyNames.Add (assemblyName);
120+
soft.UserAssemblyNames = new List<AssemblyName> {assemblyName};
171121
}
172-
173-
Session = engine.CreateSession ();
174-
var ops = new DebuggerSessionOptions ();
175-
ops.ProjectAssembliesOnly = true;
176-
ops.EvaluationOptions = EvaluationOptions.DefaultOptions;
122+
var ops = new DebuggerSessionOptions {
123+
ProjectAssembliesOnly = true,
124+
EvaluationOptions = EvaluationOptions.DefaultOptions
125+
};
177126
ops.EvaluationOptions.AllowTargetInvoke = AllowTargetInvokes;
178127
ops.EvaluationOptions.EvaluationTimeout = 100000;
179128

180-
path = path.ParentDirectory.ParentDirectory.Combine ("src", "addins", "MonoDevelop.Debugger", "MonoDevelop.Debugger.Tests.TestApp", test + ".cs").FullPath;
181-
SourceFile = TextFile.ReadFile (path);
182-
TestName = test;
129+
130+
var sourcePath = Path.Combine (TargetProjectSourceDir, test + ".cs");
131+
SourceFile = TextFile.ReadFile (sourcePath);
183132
AddBreakpoint ("break");
184-
133+
185134
var done = new ManualResetEvent (false);
186135

187136
Session.TargetHitBreakpoint += (sender, e) => {

MonoDevelop.Debugger.Tests/MonoDevelop.Debugger.Tests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -38,6 +38,7 @@
3838
</ItemGroup>
3939
<ItemGroup>
4040
<Compile Include="DebugTests.cs" />
41+
<Compile Include="DebugTests.MonoDevelop.cs" />
4142
<Compile Include="SdbEvaluationTests.cs" />
4243
<Compile Include="EvaluationTests.cs" />
4344
<Compile Include="StackFrameTests.cs" />

0 commit comments

Comments
 (0)