Browse Source

Debugger tests pre-compiled

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@851 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
David Srbecký 20 years ago
parent
commit
06f7f16301
  1. 5
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/NDebugger-Breakpoints.cs
  2. 8
      src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs
  3. 18
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj
  4. 95
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs
  5. 28
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestProgram.cs
  6. 10
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Breakpoint.cs
  7. 8
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/HelloWorld.cs
  8. 2
      src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/SimpleProgram.cs

5
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Breakpoints/NDebugger-Breakpoints.cs

@ -81,6 +81,11 @@ namespace Debugger
return breakpoint; return breakpoint;
} }
public Breakpoint AddBreakpoint(string filename, int line)
{
return AddBreakpoint(new SourcecodeSegment(filename, line), true);
}
public Breakpoint AddBreakpoint(SourcecodeSegment segment, bool breakpointEnabled) public Breakpoint AddBreakpoint(SourcecodeSegment segment, bool breakpointEnabled)
{ {
return AddBreakpoint(new Breakpoint(this, segment, breakpointEnabled)); return AddBreakpoint(new Breakpoint(this, segment, breakpointEnabled));

8
src/AddIns/Misc/Debugger/Debugger.Core/Project/Src/Debugger/NDebugger-StateControl.cs

@ -221,7 +221,15 @@ namespace Debugger
public void WaitForPause() public void WaitForPause()
{ {
if (IsRunning) { if (IsRunning) {
EventHandler<ProcessEventArgs> throwError = delegate {
if (Processes.Count == 0) {
throw new DebuggerException("Process exited before pausing");
}
};
this.ProcessExited += throwError;
throwError(null, null);
this.MTA2STA.SoftWait(WaitForPauseHandle); this.MTA2STA.SoftWait(WaitForPauseHandle);
this.ProcessExited -= throwError;
} }
} }

18
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Debugger.Tests.csproj

@ -1,6 +1,6 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<OutputType>Library</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>Debugger.Tests</RootNamespace> <RootNamespace>Debugger.Tests</RootNamespace>
<AssemblyName>Debugger.Tests</AssemblyName> <AssemblyName>Debugger.Tests</AssemblyName>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -9,11 +9,18 @@
<OutputPath>..\..\..\..\..\..\bin\UnitTests\</OutputPath> <OutputPath>..\..\..\..\..\..\bin\UnitTests\</OutputPath>
<Optimize>False</Optimize> <Optimize>False</Optimize>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow> <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<NoStdLib>False</NoStdLib> <NoStdLib>False</NoStdLib>
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugType>Full</DebugType>
<RegisterForComInterop>False</RegisterForComInterop>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<BaseAddress>4194304</BaseAddress>
<FileAlignment>4096</FileAlignment>
<DebugSymbols>true</DebugSymbols>
<StartupObject>Debugger.Tests.TestProgram</StartupObject>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
@ -32,9 +39,10 @@
<ItemGroup> <ItemGroup>
<Compile Include="Configuration\AssemblyInfo.cs" /> <Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\DebuggerTests.cs" /> <Compile Include="Src\DebuggerTests.cs" />
<EmbeddedResource Include="Src\TestPrograms\SimpleProgram.cs" /> <Compile Include="Src\TestPrograms\SimpleProgram.cs" />
<EmbeddedResource Include="Src\TestPrograms\ConsoleHelloWorld.cs" /> <Compile Include="Src\TestProgram.cs" />
<EmbeddedResource Include="Src\TestPrograms\DiagnosticsDebugHelloWorld.cs" /> <Compile Include="Src\TestPrograms\HelloWorld.cs" />
<Compile Include="Src\TestPrograms\Breakpoint.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Src" /> <Folder Include="Src" />

95
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/DebuggerTests.cs

@ -16,7 +16,7 @@ using System.Reflection;
using System.Resources; using System.Resources;
using System.Threading; using System.Threading;
namespace DebuggerLibrary.Tests namespace Debugger.Tests
{ {
/// <summary> /// <summary>
/// This class contains methods that test the debugger /// This class contains methods that test the debugger
@ -24,100 +24,51 @@ namespace DebuggerLibrary.Tests
[TestFixture] [TestFixture]
public class DebuggerTests public class DebuggerTests
{ {
string resourcePrefix = "Debugger.Tests.Src.TestPrograms."; NDebugger debugger;
string tempPath = MakeTempDirectory(); string log;
Hashtable programs = new Hashtable(); string lastLogMessage;
NDebugger debugger = new NDebugger();
public DebuggerTests() public DebuggerTests()
{ {
CompileTestPrograms(); debugger = new NDebugger();
debugger.LogMessage += delegate(object sender, MessageEventArgs e) {
log += e.Message;
lastLogMessage = e.Message;
};
} }
public void CompileTestPrograms() void StartProgram(string name)
{ {
Assembly assembly = Assembly.GetExecutingAssembly(); log = "";
foreach(string name in assembly.GetManifestResourceNames()) { lastLogMessage = null;
if (name.StartsWith(resourcePrefix)) { string filename = Assembly.GetCallingAssembly().Location;
string programName = name.Substring(resourcePrefix.Length, name.Length - resourcePrefix.Length - ".cs".Length); debugger.Start(filename, Path.GetDirectoryName(filename), name);
Stream codeStream = assembly.GetManifestResourceStream(name);
string code = new StreamReader(codeStream).ReadToEnd();
string codeFilename = Path.Combine(tempPath, programName + ".cs");
string exeFilename = Path.Combine(tempPath, programName + ".exe");
StreamWriter file = new StreamWriter(codeFilename);
file.Write(code);
file.Close();
CompilerParameters compParams = new CompilerParameters();
compParams.GenerateExecutable = true;
compParams.GenerateInMemory = false;
compParams.TreatWarningsAsErrors = false;
compParams.IncludeDebugInformation = true;
compParams.ReferencedAssemblies.Add("System.dll");
compParams.OutputAssembly = exeFilename;
CSharpCodeProvider compiler = new CSharpCodeProvider();
CompilerResults result = compiler.CompileAssemblyFromFile(compParams, codeFilename);
if (result.Errors.Count > 0) {
throw new System.Exception("There was an error(s) during compilation of test program:\n" + result.Errors[0].ToString());
}
programs.Add(programName, exeFilename);
}
}
}
~DebuggerTests()
{
//Directory.Delete(tempPath, true);
}
static string MakeTempDirectory()
{
Random rand = new Random();
string path;
do {
path = Path.Combine(Path.GetTempPath(), "SharpDevelop");
path = Path.Combine(path, "DebuggerTests" + rand.Next(10000,99999));
} while (Directory.Exists(path));
Directory.CreateDirectory(path);
return path;
} }
[Test] [Test]
public void RunSimpleProgram() public void SimpleProgram()
{ {
debugger.Start((string)programs["SimpleProgram"], tempPath, ""); StartProgram("SimpleProgram");
debugger.WaitForPrecessExit(); debugger.WaitForPrecessExit();
} }
[Test] [Test]
public void RunDiagnosticsDebugHelloWorld() public void HelloWorld()
{ {
string log = ""; StartProgram("HelloWorld");
debugger.LogMessage += delegate(object sender, MessageEventArgs e) { log += e.Message; };
debugger.Start((string)programs["DiagnosticsDebugHelloWorld"], tempPath, "");
debugger.WaitForPrecessExit(); debugger.WaitForPrecessExit();
Assert.AreEqual("Hello world!\r\n", log); Assert.AreEqual("Hello world!\r\n", log);
} }
[Test] [Test, Ignore("Deadlocks")]
public void RunDiagnosticsDebugHelloWorldWithBreakpoint() public void Breakpoint()
{ {
string log = ""; debugger.AddBreakpoint("Breakpoint.cs", 16);
debugger.LogMessage += delegate(object sender, MessageEventArgs e) { log += e.Message; };
string souceCodeFilename = ((string)programs["DiagnosticsDebugHelloWorld"]).Replace(".exe",".cs"); StartProgram("Breakpoint");
debugger.AddBreakpoint(new SourcecodeSegment(souceCodeFilename, 16), true);
debugger.Start((string)programs["DiagnosticsDebugHelloWorld"], tempPath, "");
debugger.WaitForPause(); debugger.WaitForPause();
Assert.AreEqual(PausedReason.Breakpoint, debugger.PausedReason); Assert.AreEqual(PausedReason.Breakpoint, debugger.PausedReason);
@ -127,7 +78,7 @@ namespace DebuggerLibrary.Tests
debugger.WaitForPrecessExit(); debugger.WaitForPrecessExit();
Assert.AreEqual("Hello world!\r\n", log); Assert.AreEqual("Line 16\r\n", log);
} }
} }
} }

28
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestProgram.cs

@ -0,0 +1,28 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version>
// </file>
using System;
using Progs = Debugger.Tests.TestPrograms;
namespace Debugger.Tests
{
public class TestProgram
{
public static void Main(string[] args)
{
if (args.Length == 0) {
return;
}
switch (args[0]) {
case "SimpleProgram": Progs.SimpleProgram.Main(); break;
case "HelloWorld": Progs.HelloWorld.Main(); break;
case "Breakpoint": Progs.Breakpoint.Main(); break;
}
}
}
}

10
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/ConsoleHelloWorld.cs → src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/Breakpoint.cs

@ -1,19 +1,19 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright> // <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license> // <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/> // <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using System; using System;
namespace DebuggerLibrary.Tests.TestPrograms namespace Debugger.Tests.TestPrograms
{ {
public class ConsoleHelloWorld public class Breakpoint
{ {
public static void Main() public static void Main()
{ {
Console.WriteLine("Hello world!"); System.Diagnostics.Debug.WriteLine("Line 16");
} }
} }
} }

8
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/DiagnosticsDebugHelloWorld.cs → src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/HelloWorld.cs

@ -1,15 +1,15 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright> // <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license> // <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="David Srbecký" email="dsrbecky@gmail.com"/> // <owner name="David Srbecký" email="dsrbecky@gmail.com"/>
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using System; using System;
namespace DebuggerLibrary.Tests.TestPrograms namespace Debugger.Tests.TestPrograms
{ {
public class DiagnosticsDebugHelloWorld public class HelloWorld
{ {
public static void Main() public static void Main()
{ {

2
src/AddIns/Misc/Debugger/Debugger.Tests/Project/Src/TestPrograms/SimpleProgram.cs

@ -7,7 +7,7 @@
using System; using System;
namespace DebuggerLibrary.Tests.TestPrograms namespace Debugger.Tests.TestPrograms
{ {
public class SimpleProgram public class SimpleProgram
{ {

Loading…
Cancel
Save