Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6144 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
41 changed files with 1662 additions and 820 deletions
@ -0,0 +1,120 @@
@@ -0,0 +1,120 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
public class CodeCoverageTestRunner : TestProcessRunnerBase |
||||
{ |
||||
UnitTestingOptions options; |
||||
IFileSystem fileSystem; |
||||
PartCoverApplication partCoverApplication; |
||||
PartCoverSettingsFactory settingsFactory; |
||||
|
||||
public CodeCoverageTestRunner() |
||||
: this(new UnitTestProcessRunner(), |
||||
new TestResultsMonitor(), |
||||
new UnitTestingOptions(), |
||||
new FileSystem()) |
||||
{ |
||||
} |
||||
|
||||
public CodeCoverageTestRunner(IUnitTestProcessRunner processRunner, |
||||
ITestResultsMonitor testResultsMonitor, |
||||
UnitTestingOptions options, |
||||
IFileSystem fileSystem) |
||||
: base(processRunner, testResultsMonitor) |
||||
{ |
||||
this.options = options; |
||||
this.fileSystem = fileSystem; |
||||
settingsFactory = new PartCoverSettingsFactory(fileSystem); |
||||
} |
||||
|
||||
public bool HasCodeCoverageResults() |
||||
{ |
||||
return fileSystem.FileExists(CodeCoverageResultsFileName); |
||||
} |
||||
|
||||
public CodeCoverageResults ReadCodeCoverageResults() |
||||
{ |
||||
TextReader reader = fileSystem.CreateTextReader(CodeCoverageResultsFileName); |
||||
return new CodeCoverageResults(reader); |
||||
} |
||||
|
||||
public string CodeCoverageResultsFileName { |
||||
get { return partCoverApplication.CodeCoverageResultsFileName; } |
||||
} |
||||
|
||||
public override void Start(SelectedTests selectedTests) |
||||
{ |
||||
AddProfilerEnvironmentVariableToProcessRunner(); |
||||
CreatePartCoverApplication(selectedTests); |
||||
RemoveExistingCodeCoverageResultsFile(); |
||||
CreateDirectoryForCodeCoverageResultsFile(); |
||||
AppendRunningCodeCoverageMessage(); |
||||
|
||||
base.Start(selectedTests); |
||||
} |
||||
|
||||
void AddProfilerEnvironmentVariableToProcessRunner() |
||||
{ |
||||
ProcessRunner.EnvironmentVariables.Add("COMPLUS_ProfAPI_ProfilerCompatibilitySetting", "EnableV2Profiler"); |
||||
} |
||||
|
||||
void CreatePartCoverApplication(SelectedTests selectedTests) |
||||
{ |
||||
NUnitConsoleApplication nunitConsoleApp = new NUnitConsoleApplication(selectedTests, options); |
||||
nunitConsoleApp.Results = base.TestResultsMonitor.FileName; |
||||
|
||||
PartCoverSettings settings = settingsFactory.CreatePartCoverSettings(selectedTests.Project); |
||||
partCoverApplication = new PartCoverApplication(nunitConsoleApp, settings); |
||||
} |
||||
|
||||
void RemoveExistingCodeCoverageResultsFile() |
||||
{ |
||||
string fileName = CodeCoverageResultsFileName; |
||||
if (fileSystem.FileExists(fileName)) { |
||||
fileSystem.DeleteFile(fileName); |
||||
} |
||||
} |
||||
|
||||
void CreateDirectoryForCodeCoverageResultsFile() |
||||
{ |
||||
string directory = Path.GetDirectoryName(CodeCoverageResultsFileName); |
||||
if (!fileSystem.DirectoryExists(directory)) { |
||||
fileSystem.CreateDirectory(directory); |
||||
} |
||||
} |
||||
|
||||
void AppendRunningCodeCoverageMessage() |
||||
{ |
||||
string message = ParseString("${res:ICSharpCode.CodeCoverage.RunningCodeCoverage}"); |
||||
OnMessageReceived(message); |
||||
} |
||||
|
||||
protected virtual string ParseString(string text) |
||||
{ |
||||
return StringParser.Parse(text); |
||||
} |
||||
|
||||
protected override ProcessStartInfo GetProcessStartInfo(SelectedTests selectedTests) |
||||
{ |
||||
return partCoverApplication.GetProcessStartInfo(); |
||||
} |
||||
|
||||
protected override TestResult CreateTestResultForTestFramework(TestResult testResult) |
||||
{ |
||||
return new NUnitTestResult(testResult); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.UnitTesting; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
public class CodeCoverageTestRunnerFactory : ICodeCoverageTestRunnerFactory |
||||
{ |
||||
public CodeCoverageTestRunner CreateCodeCoverageTestRunner() |
||||
{ |
||||
return new CodeCoverageTestRunner(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
public class FileSystem : IFileSystem |
||||
{ |
||||
public bool FileExists(string path) |
||||
{ |
||||
return File.Exists(path); |
||||
} |
||||
|
||||
public void DeleteFile(string path) |
||||
{ |
||||
File.Delete(path); |
||||
} |
||||
|
||||
public bool DirectoryExists(string path) |
||||
{ |
||||
return Directory.Exists(path); |
||||
} |
||||
|
||||
public void CreateDirectory(string path) |
||||
{ |
||||
Directory.CreateDirectory(path); |
||||
} |
||||
|
||||
public TextReader CreateTextReader(string path) |
||||
{ |
||||
return new StreamReader(path); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
public interface ICodeCoverageTestRunnerFactory |
||||
{ |
||||
CodeCoverageTestRunner CreateCodeCoverageTestRunner(); |
||||
} |
||||
} |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
public interface IFileSystem |
||||
{ |
||||
bool FileExists(string path); |
||||
void DeleteFile(string path); |
||||
|
||||
bool DirectoryExists(string path); |
||||
void CreateDirectory(string path); |
||||
|
||||
TextReader CreateTextReader(string path); |
||||
} |
||||
} |
||||
@ -0,0 +1,164 @@
@@ -0,0 +1,164 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Specialized; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Text; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
public class PartCoverApplication |
||||
{ |
||||
string fileName = String.Empty; |
||||
NUnitConsoleApplication nunitConsoleApp; |
||||
PartCoverSettings settings; |
||||
StringBuilder arguments; |
||||
|
||||
public PartCoverApplication(string fileName, NUnitConsoleApplication nunitConsoleApp, PartCoverSettings settings) |
||||
{ |
||||
this.fileName = fileName; |
||||
this.nunitConsoleApp = nunitConsoleApp; |
||||
this.settings = settings; |
||||
|
||||
if (String.IsNullOrEmpty(fileName)) { |
||||
GetPartCoverApplicationFileName(); |
||||
} |
||||
} |
||||
|
||||
public PartCoverApplication(NUnitConsoleApplication nunitConsoleApp, PartCoverSettings settings) |
||||
: this(null, nunitConsoleApp, settings) |
||||
{ |
||||
} |
||||
|
||||
void GetPartCoverApplicationFileName() |
||||
{ |
||||
fileName = Path.Combine(FileUtility.ApplicationRootPath, @"bin\Tools\PartCover\PartCover.exe"); |
||||
fileName = Path.GetFullPath(fileName); |
||||
} |
||||
|
||||
public PartCoverSettings Settings { |
||||
get { return settings; } |
||||
} |
||||
|
||||
public string FileName { |
||||
get { return fileName; } |
||||
set { fileName = value; } |
||||
} |
||||
|
||||
public string Target { |
||||
get { return nunitConsoleApp.FileName; } |
||||
} |
||||
|
||||
public string GetTargetArguments() |
||||
{ |
||||
return nunitConsoleApp.GetArguments(); |
||||
} |
||||
|
||||
public string GetTargetWorkingDirectory() |
||||
{ |
||||
return Path.GetDirectoryName(nunitConsoleApp.Assemblies[0]); |
||||
} |
||||
|
||||
public string CodeCoverageResultsFileName { |
||||
get { return GetCodeCoverageResultsFileName(); } |
||||
} |
||||
|
||||
string GetCodeCoverageResultsFileName() |
||||
{ |
||||
string outputDirectory = GetOutputDirectory(nunitConsoleApp.Project); |
||||
return Path.Combine(outputDirectory, "coverage.xml"); |
||||
} |
||||
|
||||
string GetOutputDirectory(IProject project) |
||||
{ |
||||
return Path.Combine(project.Directory, "PartCover"); |
||||
} |
||||
|
||||
public ProcessStartInfo GetProcessStartInfo() |
||||
{ |
||||
ProcessStartInfo processStartInfo = new ProcessStartInfo(); |
||||
processStartInfo.FileName = FileName; |
||||
processStartInfo.Arguments = GetArguments(); |
||||
return processStartInfo; |
||||
} |
||||
|
||||
string GetArguments() |
||||
{ |
||||
arguments = new StringBuilder(); |
||||
|
||||
AppendTarget(); |
||||
AppendTargetWorkingDirectory(); |
||||
AppendTargetArguments(); |
||||
AppendCodeCoverageResultsFileName(); |
||||
AppendIncludedItems(); |
||||
AppendExcludedItems(); |
||||
|
||||
return arguments.ToString().Trim(); |
||||
} |
||||
|
||||
void AppendTarget() |
||||
{ |
||||
arguments.AppendFormat("--target \"{0}\" ", Target); |
||||
} |
||||
|
||||
void AppendTargetWorkingDirectory() |
||||
{ |
||||
arguments.AppendFormat("--target-work-dir \"{0}\" ", GetTargetWorkingDirectory()); |
||||
} |
||||
|
||||
void AppendTargetArguments() |
||||
{ |
||||
string targetArguments = GetTargetArguments(); |
||||
arguments.AppendFormat("--target-args \"{0}\" ", targetArguments.Replace("\"", "\\\"")); |
||||
} |
||||
|
||||
void AppendCodeCoverageResultsFileName() |
||||
{ |
||||
arguments.AppendFormat("--output \"{0}\" ", CodeCoverageResultsFileName); |
||||
} |
||||
|
||||
void AppendIncludedItems() |
||||
{ |
||||
StringCollection includedItems = settings.Include; |
||||
if (includedItems.Count == 0) { |
||||
includedItems.Add("[*]*"); |
||||
} |
||||
AppendItems("--include", includedItems); |
||||
} |
||||
|
||||
void AppendExcludedItems() |
||||
{ |
||||
AppendEmptySpace(); |
||||
AppendItems("--exclude", settings.Exclude); |
||||
} |
||||
|
||||
void AppendEmptySpace() |
||||
{ |
||||
arguments.Append(' '); |
||||
} |
||||
|
||||
void AppendItems(string optionName, StringCollection items) |
||||
{ |
||||
string itemArgs = GetItemArguments(optionName, items); |
||||
arguments.Append(itemArgs); |
||||
} |
||||
|
||||
string GetItemArguments(string optionName, StringCollection items) |
||||
{ |
||||
StringBuilder itemArgs = new StringBuilder(); |
||||
foreach (string item in items) { |
||||
itemArgs.AppendFormat("{0} {1} ", optionName, item); |
||||
} |
||||
return itemArgs.ToString().Trim(); |
||||
} |
||||
} |
||||
} |
||||
@ -1,55 +0,0 @@
@@ -1,55 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
/// <summary>
|
||||
/// Represents the method that will handle the
|
||||
/// <see cref="PartCoverRunner.Exited"/> event.
|
||||
/// </summary>
|
||||
public delegate void PartCoverExitEventHandler(object sender, PartCoverExitEventArgs e); |
||||
|
||||
/// <summary>
|
||||
/// The <see cref="PartCoverRunner.Exited"/> event arguments.
|
||||
/// </summary>
|
||||
public class PartCoverExitEventArgs : EventArgs |
||||
{ |
||||
string output; |
||||
int exitCode; |
||||
string error; |
||||
|
||||
public PartCoverExitEventArgs(string output, string error, int exitCode) |
||||
{ |
||||
this.output = output; |
||||
this.error = error; |
||||
this.exitCode = exitCode; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the command line output from PartCover.
|
||||
/// </summary>
|
||||
public string Output { |
||||
get { return output; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the standard error output from PartCover.
|
||||
/// </summary>
|
||||
public string Error { |
||||
get { return error; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the exit code.
|
||||
/// </summary>
|
||||
public int ExitCode { |
||||
get { return exitCode; } |
||||
} |
||||
} |
||||
} |
||||
@ -1,266 +0,0 @@
@@ -1,266 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Specialized; |
||||
using System.Text; |
||||
using ICSharpCode.SharpDevelop.Util; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
/// <summary>
|
||||
/// Description of PartCoverRunner.
|
||||
/// </summary>
|
||||
public class PartCoverRunner |
||||
{ |
||||
ProcessRunner runner; |
||||
string partCoverFileName = String.Empty; |
||||
string workingDirectory = String.Empty; |
||||
string target = String.Empty; |
||||
string targetWorkingDirectory = String.Empty; |
||||
string targetArguments = String.Empty; |
||||
StringCollection include = new StringCollection(); |
||||
StringCollection exclude = new StringCollection(); |
||||
string output = String.Empty; |
||||
|
||||
/// <summary>
|
||||
/// Triggered when PartCover exits.
|
||||
/// </summary>
|
||||
public event PartCoverExitEventHandler Exited; |
||||
|
||||
/// <summary>
|
||||
/// The PartCover runner was started.
|
||||
/// </summary>
|
||||
public event EventHandler Started; |
||||
|
||||
/// <summary>
|
||||
/// The PartCover runner was stopped. Being stopped is not the
|
||||
/// same as PartCover exiting.
|
||||
/// </summary>
|
||||
public event EventHandler Stopped; |
||||
|
||||
/// <summary>
|
||||
/// Triggered when an output line is received from PartCover.
|
||||
/// </summary>
|
||||
public event LineReceivedEventHandler OutputLineReceived; |
||||
|
||||
public PartCoverRunner() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the full path to the PartCover
|
||||
/// executable.
|
||||
/// </summary>
|
||||
public string PartCoverFileName { |
||||
get { return partCoverFileName; } |
||||
set { partCoverFileName = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the working directory to use when running
|
||||
/// PartCover.
|
||||
/// </summary>
|
||||
public string WorkingDirectory { |
||||
get { return workingDirectory; } |
||||
set { workingDirectory = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the filename of the executable to profile with PartCover.
|
||||
/// </summary>
|
||||
public string Target { |
||||
get { return target; } |
||||
set { target = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the working directory for the target executable.
|
||||
/// </summary>
|
||||
public string TargetWorkingDirectory { |
||||
get { return targetWorkingDirectory; } |
||||
set { targetWorkingDirectory = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the arguments to pass to the target executable.
|
||||
/// </summary>
|
||||
public string TargetArguments { |
||||
get { return targetArguments; } |
||||
set { targetArguments = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the regular expressions which specify the items to
|
||||
/// include in the report whilst profiling the target executable.
|
||||
/// </summary>
|
||||
public StringCollection Include { |
||||
get { return include; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the regular expressions which specify the items to
|
||||
/// exclude in the report whilst profiling the target executable.
|
||||
/// </summary>
|
||||
public StringCollection Exclude { |
||||
get { return exclude; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the filename for the code coverage results.
|
||||
/// </summary>
|
||||
public string Output { |
||||
get { return output; } |
||||
set { output = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the full path used to run PartCover.
|
||||
/// Includes the path to the PartCover executable
|
||||
/// and the command line arguments.
|
||||
/// </summary>
|
||||
public string CommandLine { |
||||
get { |
||||
string arguments = GetArguments(); |
||||
if (arguments.Length > 0) { |
||||
return String.Concat(partCoverFileName, " ", arguments); |
||||
} |
||||
return partCoverFileName; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Returns the command line arguments used to run PartCover.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Note that the target arguments may itself contain double quotes
|
||||
/// so in order for this to be passed to PartCover as a single argument
|
||||
/// we need to prefix each double quote by a backslash. For example:
|
||||
///
|
||||
/// Target args: "C:\Projects\My Tests\Test.dll" /output "C:\Projects\My Tests\Output.xml"
|
||||
///
|
||||
/// PartCover: --target-args "\"C:\Projects\My Tests\Test.dll\" /output \"C:\Projects\My Tests\Output.xml\""
|
||||
/// </remarks>
|
||||
public string GetArguments() |
||||
{ |
||||
StringBuilder arguments = new StringBuilder(); |
||||
|
||||
if (!String.IsNullOrEmpty(target)) { |
||||
arguments.AppendFormat("--target \"{0}\" ", target); |
||||
} |
||||
if (!String.IsNullOrEmpty(targetWorkingDirectory)) { |
||||
arguments.AppendFormat("--target-work-dir \"{0}\" ", targetWorkingDirectory); |
||||
} |
||||
if (!String.IsNullOrEmpty(targetArguments)) { |
||||
arguments.AppendFormat("--target-args \"{0}\" ", targetArguments.Replace("\"", "\\\"")); |
||||
} |
||||
if (!String.IsNullOrEmpty(output)) { |
||||
arguments.AppendFormat("--output \"{0}\" ", output); |
||||
} |
||||
|
||||
arguments.Append(GetArguments("--include", include)); |
||||
|
||||
if (include.Count > 0) { |
||||
// Add a space between include and exclude arguments.
|
||||
arguments.Append(' '); |
||||
} |
||||
|
||||
arguments.Append(GetArguments("--exclude", exclude)); |
||||
|
||||
return arguments.ToString().Trim(); |
||||
} |
||||
|
||||
public void Start() |
||||
{ |
||||
string arguments = GetArguments(); |
||||
|
||||
runner = new ProcessRunner(); |
||||
runner.EnvironmentVariables.Add("COMPLUS_ProfAPI_ProfilerCompatibilitySetting", "EnableV2Profiler"); |
||||
runner.WorkingDirectory = workingDirectory; |
||||
runner.ProcessExited += ProcessExited; |
||||
|
||||
if (OutputLineReceived != null) { |
||||
runner.OutputLineReceived += OnOutputLineReceived; |
||||
runner.ErrorLineReceived += OnOutputLineReceived; |
||||
} |
||||
runner.Start(partCoverFileName, arguments); |
||||
OnStarted(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Stops the currently running PartCover instance.
|
||||
/// </summary>
|
||||
public void Stop() |
||||
{ |
||||
if (runner != null) { |
||||
runner.Kill(); |
||||
OnStopped(); |
||||
} |
||||
} |
||||
|
||||
protected void OnExited(string output, string error, int exitCode) |
||||
{ |
||||
if (Exited != null) { |
||||
Exited(this, new PartCoverExitEventArgs(output, error, exitCode)); |
||||
} |
||||
} |
||||
|
||||
protected void OnStarted() |
||||
{ |
||||
if (Started != null) { |
||||
Started(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
protected void OnStopped() |
||||
{ |
||||
if (Stopped != null) { |
||||
Stopped(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="OutputLineReceived"/> event.
|
||||
/// </summary>
|
||||
/// <param name="sender">The event source.</param>
|
||||
/// <param name="e">The event arguments.</param>
|
||||
protected void OnOutputLineReceived(object sender, LineReceivedEventArgs e) |
||||
{ |
||||
if (OutputLineReceived != null) { |
||||
OutputLineReceived(this, e); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Handles the PartCover process exit event.
|
||||
/// </summary>
|
||||
/// <param name="sender">The event source.</param>
|
||||
/// <param name="e">The event arguments.</param>
|
||||
void ProcessExited(object sender, EventArgs e) |
||||
{ |
||||
ProcessRunner runner = (ProcessRunner)sender; |
||||
OnExited(runner.StandardOutput, runner.StandardError, runner.ExitCode); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the command line option that can have multiple items as specified
|
||||
/// in the string array. Each array item will have a separate command line
|
||||
/// argument (e.g. --include=A --include=B --include=B).
|
||||
/// </summary>
|
||||
static string GetArguments(string argumentName, StringCollection items) |
||||
{ |
||||
StringBuilder arguments = new StringBuilder(); |
||||
foreach (string item in items) { |
||||
arguments.Append(argumentName); |
||||
arguments.Append(" "); |
||||
arguments.Append(item); |
||||
arguments.Append(" "); |
||||
} |
||||
return arguments.ToString().Trim(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
public class PartCoverSettingsFactory |
||||
{ |
||||
IFileSystem fileSystem; |
||||
|
||||
public PartCoverSettingsFactory(IFileSystem fileSystem) |
||||
{ |
||||
this.fileSystem = fileSystem; |
||||
} |
||||
|
||||
public PartCoverSettingsFactory() |
||||
: this(new FileSystem()) |
||||
{ |
||||
} |
||||
|
||||
public PartCoverSettings CreatePartCoverSettings(IProject project) |
||||
{ |
||||
string fileName = PartCoverSettings.GetFileName(project); |
||||
if (fileSystem.FileExists(fileName)) { |
||||
return CreatePartCoverSettingsFromFile(fileName); |
||||
} |
||||
return new PartCoverSettings(); |
||||
} |
||||
|
||||
PartCoverSettings CreatePartCoverSettingsFromFile(string fileName) |
||||
{ |
||||
TextReader reader = fileSystem.CreateTextReader(fileName); |
||||
return new PartCoverSettings(reader); |
||||
} |
||||
} |
||||
} |
||||
@ -1,176 +0,0 @@
@@ -1,176 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Coverage |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the PartCoverRunner's command line argumentsests.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class PartCoverCommandLineTests |
||||
{ |
||||
[Test] |
||||
public void PartCoverFileNameSpecified() |
||||
{ |
||||
string partCoverFileName = @"C:\Program Files\PartCover\PartCover.exe"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.PartCoverFileName = partCoverFileName; |
||||
|
||||
Assert.AreEqual(partCoverFileName, runner.CommandLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void ArgumentsStringIsEmptyWhenNothingSpecified() |
||||
{ |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
Assert.AreEqual(String.Empty, runner.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void WorkingDirectoryNotSet() |
||||
{ |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
Assert.AreEqual(String.Empty, runner.WorkingDirectory); |
||||
} |
||||
|
||||
[Test] |
||||
public void WorkingDirectorySet() |
||||
{ |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
string folder = @"C:\Program Files\PartCover"; |
||||
runner.WorkingDirectory = folder; |
||||
Assert.AreEqual(folder, runner.WorkingDirectory); |
||||
} |
||||
|
||||
[Test] |
||||
public void TargetFileNameSpecified() |
||||
{ |
||||
string targetFileName = @"C:\Program Files\SharpDevelop\bin\Tools\NUnit-console.exe"; |
||||
string partCoverFileName = @"C:\Program Files\PartCover\PartCover.exe"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.PartCoverFileName = partCoverFileName; |
||||
runner.Target = targetFileName; |
||||
string expectedCommandLine = partCoverFileName + " --target \"" + targetFileName + "\""; |
||||
|
||||
Assert.AreEqual(expectedCommandLine, runner.CommandLine); |
||||
} |
||||
|
||||
[Test] |
||||
public void TargetWorkingDirectorySpecified() |
||||
{ |
||||
string targetWorkingDirectory = @"C:\Program Files\SharpDevelop\bin\Tools"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.TargetWorkingDirectory = targetWorkingDirectory; |
||||
string expectedArgs = "--target-work-dir \"" + targetWorkingDirectory + "\""; |
||||
|
||||
Assert.AreEqual(expectedArgs, runner.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TargetArguments() |
||||
{ |
||||
string targetArgs = @"C:\Project\Test\MyTests.dll"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.TargetWorkingDirectory = null; |
||||
runner.TargetArguments = targetArgs; |
||||
string expectedArgs = "--target-args \"" + targetArgs + "\""; |
||||
|
||||
Assert.AreEqual(expectedArgs, runner.GetArguments()); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// In order for the target arguments to be successfully passed to
|
||||
/// PartCover we need to prefix any double quote with a backslash.
|
||||
/// </summary>
|
||||
[Test] |
||||
public void TargetArgumentsIncludeDoubleQuotes() |
||||
{ |
||||
string targetArgs = "\"C:\\Project\\My Tests\\MyTests.dll\" /output=\"C:\\Project\\My Tests\\Output.xml\""; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.TargetWorkingDirectory = null; |
||||
runner.TargetArguments = targetArgs; |
||||
string expectedArgs = "--target-args \"" + targetArgs.Replace("\"", "\\\"") + "\""; |
||||
|
||||
Assert.AreEqual(expectedArgs, runner.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void IncludeSpecified() |
||||
{ |
||||
string include = @"[RootNamespace.MyTests]*"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.Include.Add(include); |
||||
string expectedArgs = "--include " + include; |
||||
|
||||
Assert.AreEqual(expectedArgs, runner.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoIncludeItemsSpecified() |
||||
{ |
||||
string include1 = @"[RootNamespace.MyTests]*"; |
||||
string include2 = @"[System]*"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.Include.Add(include1); |
||||
runner.Include.Add(include2); |
||||
string expectedArgs = "--include " + include1 + " --include " + include2; |
||||
|
||||
Assert.AreEqual(expectedArgs, runner.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExcludeSpecified() |
||||
{ |
||||
string exclude = @"[RootNamespace.MyTests]*"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.Exclude.Add(exclude); |
||||
string expectedArgs = "--exclude " + exclude; |
||||
|
||||
Assert.AreEqual(expectedArgs, runner.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void TwoExcludeItemsSpecified() |
||||
{ |
||||
string exclude1 = @"[RootNamespace.MyTests]*"; |
||||
string exclude2 = @"[System]*"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.Exclude.Add(exclude1); |
||||
runner.Exclude.Add(exclude2); |
||||
string expectedArgs = "--exclude " + exclude1 + " --exclude " + exclude2; |
||||
|
||||
Assert.AreEqual(expectedArgs, runner.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneIncludeAndExcludeItemSpecified() |
||||
{ |
||||
string exclude = @"[RootNamespace.MyTests]*"; |
||||
string include = @"[System]*"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.Exclude.Add(exclude); |
||||
runner.Include.Add(include); |
||||
string expectedArgs = "--include " + include + " --exclude " + exclude; |
||||
|
||||
Assert.AreEqual(expectedArgs, runner.GetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void OutputSpecified() |
||||
{ |
||||
string output = @"C:\Projects\MyTests\CodeCoverage.xml"; |
||||
PartCoverRunner runner = new PartCoverRunner(); |
||||
runner.Output = output; |
||||
string expectedArgs = "--output \"" + output + "\""; |
||||
|
||||
Assert.AreEqual(expectedArgs, runner.GetArguments()); |
||||
} |
||||
} |
||||
} |
||||
@ -1,49 +0,0 @@
@@ -1,49 +0,0 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.CodeCoverage; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Coverage |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the PartCoverExitEventArgs class.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class PartCoverExitEventArgsTestFixture |
||||
{ |
||||
PartCoverExitEventArgs eventArgs; |
||||
string output = "Test"; |
||||
string error = "Error"; |
||||
int exitCode = -1; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
eventArgs = new PartCoverExitEventArgs(output, error, exitCode); |
||||
} |
||||
|
||||
[Test] |
||||
public void OutputText() |
||||
{ |
||||
Assert.AreEqual(output, eventArgs.Output); |
||||
} |
||||
|
||||
[Test] |
||||
public void ErrorText() |
||||
{ |
||||
Assert.AreEqual(error, eventArgs.Error); |
||||
} |
||||
|
||||
[Test] |
||||
public void ExitCode() |
||||
{ |
||||
Assert.AreEqual(exitCode, eventArgs.ExitCode); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,64 @@
@@ -0,0 +1,64 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.CodeCoverage.Tests.Utils; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Coverage |
||||
{ |
||||
[TestFixture] |
||||
public class PartCoverSettingsFactoryTests |
||||
{ |
||||
PartCoverSettingsFactory factory; |
||||
PartCoverSettings partCoverSettings; |
||||
MockCSharpProject project; |
||||
MockFileSystem fileSystem; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
fileSystem = new MockFileSystem(); |
||||
factory = new PartCoverSettingsFactory(fileSystem); |
||||
project = new MockCSharpProject(); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreatePartCoverSettingsWhenFileDoesNotExistCreatesSettingsWithNoPartCoverIncludes() |
||||
{ |
||||
fileSystem.FileExistsReturnValue = false; |
||||
CreatePartCoverSettingsFromFactory(); |
||||
Assert.AreEqual(0, partCoverSettings.Include.Count); |
||||
} |
||||
|
||||
void CreatePartCoverSettingsFromFactory() |
||||
{ |
||||
partCoverSettings = factory.CreatePartCoverSettings(project); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreatePartCoverSettingsWhenFileExistsCreatesSettingsFromFile() |
||||
{ |
||||
string partCoverSettingsXml = |
||||
"<PartCoverSettings>\r\n" + |
||||
" <Rule>+test</Rule>\r\n" + |
||||
"</PartCoverSettings>"; |
||||
|
||||
StringReader reader = new StringReader(partCoverSettingsXml); |
||||
fileSystem.CreateTextReaderReturnValue = reader; |
||||
|
||||
fileSystem.FileExistsReturnValue = true; |
||||
|
||||
CreatePartCoverSettingsFromFactory(); |
||||
Assert.AreEqual("test", partCoverSettings.Include[0]); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.IO; |
||||
using ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Editor; |
||||
using ICSharpCode.SharpDevelop.Tests.Utils; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Coverage |
||||
{ |
||||
[TestFixture] |
||||
public class RemoveTaskMarkerTests |
||||
{ |
||||
ITextMarkerService markerService; |
||||
IDocument document; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
document = MockTextMarkerService.CreateDocumentWithMockService(); |
||||
markerService = document.GetService(typeof(ITextMarkerService)) as ITextMarkerService; |
||||
document.Text = |
||||
"{\r\n" + |
||||
" int count = 0;\r\n" + |
||||
"}\r\n"; |
||||
} |
||||
|
||||
[Test] |
||||
public void CodeCoverageHighlighterRemoveMarkersDoesNotThrowInvalidCastExceptionWhenOneMarkerTagIsTask() |
||||
{ |
||||
ITextMarker textMarker = markerService.Create(0, 2); |
||||
textMarker.Tag = new Task(null, String.Empty, 1, 1, TaskType.Error); |
||||
|
||||
CodeCoverageHighlighter highlighter = new CodeCoverageHighlighter(); |
||||
Assert.DoesNotThrow(delegate { highlighter.RemoveMarkers(document); }); |
||||
} |
||||
} |
||||
} |
||||
Binary file not shown.
@ -0,0 +1,239 @@
@@ -0,0 +1,239 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.IO; |
||||
using System.Text; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.CodeCoverage.Tests.Utils; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Testing |
||||
{ |
||||
[TestFixture] |
||||
public class CodeCoverageTestRunnerTests |
||||
{ |
||||
MockProcessRunner processRunner; |
||||
MockTestResultsMonitor testResultsMonitor; |
||||
UnitTestingOptions options; |
||||
DerivedCodeCoverageTestRunner testRunner; |
||||
MockFileSystem fileSystem; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
processRunner = new MockProcessRunner(); |
||||
testResultsMonitor = new MockTestResultsMonitor(); |
||||
options = new UnitTestingOptions(new Properties()); |
||||
fileSystem = new MockFileSystem(); |
||||
testRunner = new DerivedCodeCoverageTestRunner(processRunner, testResultsMonitor, options, fileSystem); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateTestResultForTestFrameworkReturnsNUnitTestResult() |
||||
{ |
||||
TestResult testResult = new TestResult("abc"); |
||||
Assert.IsInstanceOf(typeof(NUnitTestResult), testRunner.CallCreateTestResultForTestFramework(testResult)); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasCodeCoverageResultsWhenCoverageFileExistsReturnsTrue() |
||||
{ |
||||
StartTestRunner(); |
||||
|
||||
fileSystem.FileExistsReturnValue = true; |
||||
|
||||
Assert.IsTrue(testRunner.HasCodeCoverageResults()); |
||||
} |
||||
|
||||
void StartTestRunner() |
||||
{ |
||||
FileUtility.ApplicationRootPath = @"d:\sharpdevelop"; |
||||
MockCSharpProject project = new MockCSharpProject(); |
||||
SelectedTests tests = new SelectedTests(project); |
||||
testRunner.Start(tests); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasCodeCoverageResultsWhenCoverageFileDoesNotExistsReturnsFalse() |
||||
{ |
||||
fileSystem.FileExistsReturnValue = false; |
||||
StartTestRunner(); |
||||
Assert.IsFalse(testRunner.HasCodeCoverageResults()); |
||||
} |
||||
|
||||
[Test] |
||||
public void HasCodeCoverageResultsAfterTestRunChecksPassesCodeCoverageFileToFileExistsMethod() |
||||
{ |
||||
fileSystem.FileExistsReturnValue = false; |
||||
fileSystem.FileExistsPathParameter = null; |
||||
StartTestRunner(); |
||||
testRunner.HasCodeCoverageResults(); |
||||
|
||||
string expectedFileName = |
||||
@"c:\projects\MyTests\PartCover\coverage.xml"; |
||||
|
||||
Assert.AreEqual(expectedFileName, fileSystem.FileExistsPathParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void ReadCodeCoverageResultsAfterTestRunChecksPassesCodeCoverageFileToCreateTextReaderMethod() |
||||
{ |
||||
StartTestRunner(); |
||||
|
||||
fileSystem.FileExistsReturnValue = true; |
||||
fileSystem.CreateTextReaderPathParameter = null; |
||||
fileSystem.CreateTextReaderReturnValue = new StringReader("<abc/>"); |
||||
|
||||
testRunner.ReadCodeCoverageResults(); |
||||
|
||||
string expectedFileName = |
||||
@"c:\projects\MyTests\PartCover\coverage.xml"; |
||||
|
||||
Assert.AreEqual(expectedFileName, fileSystem.CreateTextReaderPathParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProcessStartInfoWhenTestResultsFileNameSetReturnsCommandLineWithTestResultsFileName() |
||||
{ |
||||
FileUtility.ApplicationRootPath = @"d:\sharpdevelop"; |
||||
testResultsMonitor.FileName = @"d:\temp\results.txt"; |
||||
|
||||
fileSystem.CreateTextReaderReturnValue = CreatePartCoverSettingsTextReader(); |
||||
fileSystem.FileExistsReturnValue = true; |
||||
|
||||
MockCSharpProject project = new MockCSharpProject(); |
||||
SelectedTests tests = new SelectedTests(project); |
||||
testRunner.Start(tests); |
||||
ProcessStartInfo processStartInfo = testRunner.CallGetProcessStartInfo(tests); |
||||
|
||||
string expectedCommandLine = |
||||
"--target \"d:\\sharpdevelop\\bin\\Tools\\NUnit\\nunit-console-x86.exe\" " + |
||||
"--target-work-dir \"c:\\projects\\MyTests\\bin\\Debug\" " + |
||||
"--target-args \"\\\"c:\\projects\\MyTests\\bin\\Debug\\MyTests.dll\\\" /results=\\\"d:\\temp\\results.txt\\\"\" " + |
||||
"--output \"c:\\projects\\MyTests\\PartCover\\coverage.xml\" " + |
||||
"--include [MyTests]*"; |
||||
|
||||
Assert.AreEqual(expectedCommandLine, processStartInfo.Arguments); |
||||
} |
||||
|
||||
TextReader CreatePartCoverSettingsTextReader() |
||||
{ |
||||
PartCoverSettings settings = new PartCoverSettings(); |
||||
settings.Include.Add("[MyTests]*"); |
||||
StringBuilder text = new StringBuilder(); |
||||
StringWriter writer = new StringWriter(text); |
||||
settings.Save(writer); |
||||
|
||||
return new StringReader(text.ToString()); |
||||
} |
||||
|
||||
[Test] |
||||
public void StartSetsProfilerEnvironmentVariableInProcessRunner() |
||||
{ |
||||
StartTestRunner(); |
||||
string environmentVariableValue = processRunner.EnvironmentVariables["COMPLUS_ProfAPI_ProfilerCompatibilitySetting"]; |
||||
Assert.AreEqual("EnableV2Profiler", environmentVariableValue); |
||||
} |
||||
|
||||
[Test] |
||||
public void StartWhenCodeCoverageResultsFileExistsDeletesExistingCodeCoverageResultsFile() |
||||
{ |
||||
fileSystem.FileExistsReturnValue = true; |
||||
fileSystem.CreateTextReaderReturnValue = new StringReader("<abc/>"); |
||||
StartTestRunner(); |
||||
|
||||
string expectedFileName = @"c:\projects\MyTests\PartCover\coverage.xml"; |
||||
Assert.AreEqual(expectedFileName, fileSystem.DeleteFilePathParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void StartWhenCodeCoverageResultsFileDoesNotExistsCodeCoverageResultsFileIsNotDeleted() |
||||
{ |
||||
fileSystem.FileExistsReturnValue = false; |
||||
StartTestRunner(); |
||||
|
||||
Assert.IsNull(fileSystem.DeleteFilePathParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void StartCreatesDirectoryCodeCoverageResultsFileIfDoesNotExist() |
||||
{ |
||||
fileSystem.DirectoryExistsReturnValue = false; |
||||
StartTestRunner(); |
||||
|
||||
string expectedDirectory = @"c:\projects\MyTests\PartCover"; |
||||
Assert.AreEqual(expectedDirectory, fileSystem.CreateDirectoryPathParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void StartChecksDirectoryForCodeCoverageResultsExists() |
||||
{ |
||||
fileSystem.DirectoryExistsReturnValue = true; |
||||
StartTestRunner(); |
||||
|
||||
string expectedDirectory = @"c:\projects\MyTests\PartCover"; |
||||
Assert.AreEqual(expectedDirectory, fileSystem.DirectoryExistsPathParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void StartDoesNotCreateDirectoryForCodeCoverageResultsFileIfItExists() |
||||
{ |
||||
fileSystem.DirectoryExistsReturnValue = true; |
||||
StartTestRunner(); |
||||
|
||||
Assert.IsNull(fileSystem.CreateDirectoryPathParameter); |
||||
} |
||||
|
||||
[Test] |
||||
public void StartFiresMessagesReceivedEventTwice() |
||||
{ |
||||
List<string> messages = new List<string>(); |
||||
testRunner.MessageReceived += delegate(object o, MessageReceivedEventArgs e) { |
||||
messages.Add(e.Message); |
||||
}; |
||||
|
||||
testRunner.ParseStringReturnValue = "Running code coverage"; |
||||
StartTestRunner(); |
||||
|
||||
string[] expectedMessages = new string[] { |
||||
"Running code coverage", |
||||
GetCodeCoverageCommandLine() |
||||
}; |
||||
|
||||
Assert.AreEqual(expectedMessages, messages.ToArray()); |
||||
} |
||||
|
||||
string GetCodeCoverageCommandLine() |
||||
{ |
||||
return |
||||
"\"d:\\sharpdevelop\\bin\\Tools\\PartCover\\PartCover.exe\" " + |
||||
"--target \"d:\\sharpdevelop\\bin\\Tools\\NUnit\\nunit-console-x86.exe\" " + |
||||
"--target-work-dir \"c:\\projects\\MyTests\\bin\\Debug\" " + |
||||
"--target-args \"\\\"c:\\projects\\MyTests\\bin\\Debug\\MyTests.dll\\\"\" " + |
||||
"--output \"c:\\projects\\MyTests\\PartCover\\coverage.xml\" " + |
||||
"--include [*]*"; |
||||
} |
||||
|
||||
[Test] |
||||
public void StartParsesTextForRunningCodeCoverageMessages() |
||||
{ |
||||
testRunner.ParseStringReturnValue = "Running code coverage"; |
||||
StartTestRunner(); |
||||
|
||||
string expectedStringResource = "${res:ICSharpCode.CodeCoverage.RunningCodeCoverage}"; |
||||
|
||||
Assert.AreEqual(expectedStringResource, testRunner.ParseStringParameter); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,174 @@
@@ -0,0 +1,174 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Testing |
||||
{ |
||||
[TestFixture] |
||||
public class PartCoverApplicationTests |
||||
{ |
||||
NUnitConsoleApplication nunitConsoleApp; |
||||
SelectedTests selectedTests; |
||||
UnitTestingOptions options; |
||||
PartCoverApplication partCoverApp; |
||||
PartCoverSettings partCoverSettings; |
||||
|
||||
[Test] |
||||
public void FileNameWhenPartCoverApplicationConstructedWithFileNameParameterMatchesFileNameParameter() |
||||
{ |
||||
string expectedFileName = @"d:\projects\PartCover.exe"; |
||||
CreatePartCoverApplication(expectedFileName); |
||||
Assert.AreEqual(expectedFileName, partCoverApp.FileName); |
||||
} |
||||
|
||||
void CreatePartCoverApplication(string fileName) |
||||
{ |
||||
CreateNUnitConsoleApplication(); |
||||
partCoverSettings = new PartCoverSettings(); |
||||
partCoverApp = new PartCoverApplication(fileName, nunitConsoleApp, partCoverSettings); |
||||
} |
||||
|
||||
void CreateNUnitConsoleApplication() |
||||
{ |
||||
MockCSharpProject project = new MockCSharpProject(); |
||||
selectedTests = new SelectedTests(project); |
||||
|
||||
options = new UnitTestingOptions(new Properties()); |
||||
nunitConsoleApp = new NUnitConsoleApplication(selectedTests, options); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileNameWhenPartCoverApplicationConstructedWithNoParametersIsDeterminedFromFileUtilityAppRootPath() |
||||
{ |
||||
FileUtility.ApplicationRootPath = @"d:\sharpdevelop"; |
||||
CreatePartCoverApplicationWithoutFileName(); |
||||
string expectedPath = @"d:\sharpdevelop\bin\Tools\PartCover\PartCover.exe"; |
||||
Assert.AreEqual(expectedPath, partCoverApp.FileName); |
||||
} |
||||
|
||||
void CreatePartCoverApplicationWithoutFileName() |
||||
{ |
||||
CreateNUnitConsoleApplication(); |
||||
partCoverApp = new PartCoverApplication(nunitConsoleApp, new PartCoverSettings()); |
||||
} |
||||
|
||||
[Test] |
||||
public void FileNameWhenTakenFromFileUtilityAppRootPathRemovesDotDotCharacters() |
||||
{ |
||||
FileUtility.ApplicationRootPath = @"d:\sharpdevelop\..\sharpdevelop"; |
||||
CreatePartCoverApplicationWithoutFileName(); |
||||
string expectedPath = @"d:\sharpdevelop\bin\Tools\PartCover\PartCover.exe"; |
||||
Assert.AreEqual(expectedPath, partCoverApp.FileName); |
||||
} |
||||
|
||||
[Test] |
||||
public void TargetIsNUnitConsoleApplicationFileName() |
||||
{ |
||||
CreatePartCoverApplication(); |
||||
Assert.AreEqual(nunitConsoleApp.FileName, partCoverApp.Target); |
||||
} |
||||
|
||||
void CreatePartCoverApplication() |
||||
{ |
||||
string fileName = @"d:\partcover\PartCover.exe"; |
||||
CreatePartCoverApplication(fileName); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetTargetArgumentsReturnsNUnitConsoleApplicationCommandLineArguments() |
||||
{ |
||||
CreatePartCoverApplication(); |
||||
Assert.AreEqual(nunitConsoleApp.GetArguments(), partCoverApp.GetTargetArguments()); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetTargetWorkingDirectoryReturnsWorkingDirectoryForProjectOutput() |
||||
{ |
||||
CreatePartCoverApplication(); |
||||
string expectedTargetWorkingDirectory = @"c:\projects\MyTests\bin\Debug"; |
||||
Assert.AreEqual(expectedTargetWorkingDirectory, partCoverApp.GetTargetWorkingDirectory()); |
||||
} |
||||
|
||||
[Test] |
||||
public void CodeCoverageResultsFileNameReturnsCoverageXmlFileInsidePartCoverDirectoryInsideProjectDirectory() |
||||
{ |
||||
CreatePartCoverApplication(); |
||||
string expectedOutputDirectory = |
||||
@"c:\projects\MyTests\PartCover\coverage.xml"; |
||||
|
||||
Assert.AreEqual(expectedOutputDirectory, partCoverApp.CodeCoverageResultsFileName); |
||||
} |
||||
|
||||
[Test] |
||||
public void SettingsReturnsPartCoverSettingsPassedToConstructor() |
||||
{ |
||||
CreatePartCoverApplication(); |
||||
Assert.AreEqual(partCoverSettings, partCoverApp.Settings); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProcessStartInfoReturnsStartInfoWhereFileNameIsPartCoverAppFileName() |
||||
{ |
||||
string partCoverAppFileName = @"d:\projects\partcover.exe"; |
||||
CreatePartCoverApplication(partCoverAppFileName); |
||||
ProcessStartInfo processStartInfo = partCoverApp.GetProcessStartInfo(); |
||||
|
||||
Assert.AreEqual(partCoverAppFileName, processStartInfo.FileName); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProcessStartInfoWhenNoIncludedItemsReturnsCommandLineWithIncludeForAllAssemblies() |
||||
{ |
||||
FileUtility.ApplicationRootPath = @"d:\sharpdevelop"; |
||||
CreatePartCoverApplication(); |
||||
ProcessStartInfo processStartInfo = partCoverApp.GetProcessStartInfo(); |
||||
|
||||
string expectedCommandLine = |
||||
"--target \"d:\\sharpdevelop\\bin\\Tools\\NUnit\\nunit-console-x86.exe\" " + |
||||
"--target-work-dir \"c:\\projects\\MyTests\\bin\\Debug\" " + |
||||
"--target-args \"\\\"c:\\projects\\MyTests\\bin\\Debug\\MyTests.dll\\\"\" " + |
||||
"--output \"c:\\projects\\MyTests\\PartCover\\coverage.xml\" " + |
||||
"--include [*]*"; |
||||
|
||||
Assert.AreEqual(expectedCommandLine, processStartInfo.Arguments); |
||||
} |
||||
|
||||
[Test] |
||||
public void GetProcessStartInfoWhenHaveIncludedAndExcludedItemsReturnsCommandLineWithIncludeAndExcludeCommandLineArgs() |
||||
{ |
||||
FileUtility.ApplicationRootPath = @"d:\sharpdevelop"; |
||||
CreatePartCoverApplication(); |
||||
|
||||
partCoverSettings.Include.Add("[MyTests]*"); |
||||
partCoverSettings.Include.Add("[MoreTests]*"); |
||||
|
||||
partCoverSettings.Exclude.Add("[NUnit.Framework]*"); |
||||
partCoverSettings.Exclude.Add("[MyProject]*"); |
||||
|
||||
ProcessStartInfo processStartInfo = partCoverApp.GetProcessStartInfo(); |
||||
|
||||
string expectedCommandLine = |
||||
"--target \"d:\\sharpdevelop\\bin\\Tools\\NUnit\\nunit-console-x86.exe\" " + |
||||
"--target-work-dir \"c:\\projects\\MyTests\\bin\\Debug\" " + |
||||
"--target-args \"\\\"c:\\projects\\MyTests\\bin\\Debug\\MyTests.dll\\\"\" " + |
||||
"--output \"c:\\projects\\MyTests\\PartCover\\coverage.xml\" " + |
||||
"--include [MyTests]* " + |
||||
"--include [MoreTests]* " + |
||||
"--exclude [NUnit.Framework]* " + |
||||
"--exclude [MyProject]*"; |
||||
|
||||
Assert.AreEqual(expectedCommandLine, processStartInfo.Arguments); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,259 @@
@@ -0,0 +1,259 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.UnitTesting; |
||||
using NUnit.Framework; |
||||
using ICSharpCode.CodeCoverage.Tests.Utils; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Testing |
||||
{ |
||||
[TestFixture] |
||||
public class RunTestWithCodeCoverageCommandTests |
||||
{ |
||||
DerivedRunTestWithCodeCoverageCommand command; |
||||
MockRunTestCommandContext context; |
||||
MockCodeCoverageTestRunnerFactory mockCodeCoverageTestRunnerFactory; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
context = new MockRunTestCommandContext(); |
||||
mockCodeCoverageTestRunnerFactory = new MockCodeCoverageTestRunnerFactory(); |
||||
command = new DerivedRunTestWithCodeCoverageCommand(context, mockCodeCoverageTestRunnerFactory); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnBeforeRunTestsWhenNoCodeCoverageMessageViewCreatedCreatesNewMessageViewCategory() |
||||
{ |
||||
command.CodeCoverageMessageViewCategory = null; |
||||
command.CallOnBeforeRunTests(); |
||||
|
||||
Assert.AreEqual("CodeCoverage", command.CodeCoverageMessageViewCategory.Category); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnBeforeRunTestsWhenNoCodeCoverageMessageViewCreatedCreatesNewMessageViewCategoryWithCodeCoverageDisplayCategoryName() |
||||
{ |
||||
command.CodeCoverageMessageViewCategory = null; |
||||
command.ParsedStringToReturn = "Code Coverage"; |
||||
command.CallOnBeforeRunTests(); |
||||
|
||||
string expectedDisplayCategoryName = "Code Coverage"; |
||||
Assert.AreEqual(expectedDisplayCategoryName, command.CodeCoverageMessageViewCategory.DisplayCategory); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnBeforeRunTestsWhenNoCodeCoverageMessageViewCreatedPassedStringResourceToStringParser() |
||||
{ |
||||
command.CodeCoverageMessageViewCategory = null; |
||||
command.ParsedString = null; |
||||
command.CallOnBeforeRunTests(); |
||||
|
||||
string expectedStringResourceName = "${res:ICSharpCode.UnitTesting.CodeCoverage}"; |
||||
Assert.AreEqual(expectedStringResourceName, command.ParsedString); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnBeforeRunTestsWhenCodeCoverageMessageViewCreatedPreviouslyDoesNotCreateAnotherMessageView() |
||||
{ |
||||
MessageViewCategory view = new MessageViewCategory("Test"); |
||||
command.CodeCoverageMessageViewCategory = view; |
||||
command.CallOnBeforeRunTests(); |
||||
Assert.AreEqual(view, command.CodeCoverageMessageViewCategory); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnBeforeRunTestsClearsCodeCoverageMessageViewTextWithSafeAsyncCall() |
||||
{ |
||||
MessageViewCategory view = new MessageViewCategory("Test"); |
||||
view.AppendText("abc"); |
||||
command.CodeCoverageMessageViewCategory = view; |
||||
command.CallOnBeforeRunTests(); |
||||
|
||||
Assert.AreEqual(String.Empty, view.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnBeforeRunTestsClearsCodeCoverageResults() |
||||
{ |
||||
command.CallOnBeforeRunTests(); |
||||
|
||||
Action expectedAction = CodeCoverageService.ClearResults; |
||||
Assert.AreEqual(expectedAction, context.MockUnitTestWorkbench.SafeThreadAsyncMethodCalls[0]); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnAfterRunTestsWhenNoCriticalTestErrorsCodeCoveragePadIsShown() |
||||
{ |
||||
context.MockTaskService.HasCriticalErrorsReturnValue = false; |
||||
PadDescriptor padDescriptor = AddCodeCoveragePadToMockWorkbench(); |
||||
command.CallOnAfterRunTests(); |
||||
|
||||
Action expectedAction = padDescriptor.BringPadToFront; |
||||
Assert.AreEqual(expectedAction, context.MockUnitTestWorkbench.SafeThreadAsyncMethodCalls[0]); |
||||
} |
||||
|
||||
PadDescriptor AddCodeCoveragePadToMockWorkbench() |
||||
{ |
||||
PadDescriptor padDescriptor = new PadDescriptor(typeof(CodeCoveragePad), "Code Coverage", String.Empty); |
||||
context.MockUnitTestWorkbench.AddPadDescriptor(padDescriptor); |
||||
return padDescriptor; |
||||
} |
||||
|
||||
[Test] |
||||
public void OnAfterRunTestsWhenCriticalErrorsCodeCoveragePadIsNotShown() |
||||
{ |
||||
context.MockTaskService.HasCriticalErrorsReturnValue = true; |
||||
PadDescriptor padDescriptor = AddCodeCoveragePadToMockWorkbench(); |
||||
command.CallOnAfterRunTests(); |
||||
|
||||
Assert.AreEqual(0, context.MockUnitTestWorkbench.SafeThreadAsyncMethodCalls.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void OnAfterRunTestsDoesNotTreatWarningsAsErrors() |
||||
{ |
||||
context.MockTaskService.TreatWarningsAsErrorsParameterPassedToHasCriticalErrors = true; |
||||
AddCodeCoveragePadToMockWorkbench(); |
||||
command.CallOnAfterRunTests(); |
||||
|
||||
Assert.IsFalse(context.MockTaskService.TreatWarningsAsErrorsParameterPassedToHasCriticalErrors); |
||||
} |
||||
|
||||
[Test] |
||||
public void MessageReceivedFromTestRunnerIsAddedToCodeCoverageMessageViewNotUnitTestsMessageView() |
||||
{ |
||||
command.CodeCoverageMessageViewCategory = null; |
||||
MessageReceivedEventArgs e = new MessageReceivedEventArgs("test"); |
||||
command.CallTestRunnerMessageReceived(this, e); |
||||
string expectedText = "test\r\n"; |
||||
Assert.AreEqual(expectedText, command.CodeCoverageMessageViewCategory.Text); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateTestRunnerCreatesNewCodeCoverageTestRunner() |
||||
{ |
||||
CodeCoverageTestRunner expectedTestRunner = mockCodeCoverageTestRunnerFactory.TestRunner; |
||||
Assert.AreEqual(expectedTestRunner, command.CallCreateTestRunner(null)); |
||||
} |
||||
|
||||
[Test] |
||||
public void CodeCoverageProcessExitsAndCodeCoverageFileExistsCausesCodeCoverageResultsToBeDisplayed() |
||||
{ |
||||
ActionArguments<CodeCoverageResults> actionArgs = |
||||
CreateTestRunnerAndFireCodeCoverageProcessExitEvent(); |
||||
|
||||
Action<CodeCoverageResults> expectedAction = CodeCoverageService.ShowResults; |
||||
Assert.AreEqual(expectedAction, actionArgs.Action); |
||||
} |
||||
|
||||
ActionArguments<CodeCoverageResults> CreateTestRunnerAndFireCodeCoverageProcessExitEvent() |
||||
{ |
||||
command.CallCreateTestRunner(null); |
||||
MockCSharpProject project = new MockCSharpProject(); |
||||
SelectedTests tests = new SelectedTests(project); |
||||
mockCodeCoverageTestRunnerFactory.TestRunner.Start(tests); |
||||
|
||||
mockCodeCoverageTestRunnerFactory.FileSystem.FileExistsReturnValue = true; |
||||
mockCodeCoverageTestRunnerFactory.FileSystem.CreateTextReaderReturnValue = CreateCodeCoverageResultsTextReader(); |
||||
|
||||
mockCodeCoverageTestRunnerFactory.ProcessRunner.FireProcessExitedEvent(); |
||||
|
||||
object actionArgsAsObject = context.MockUnitTestWorkbench.SafeThreadAsyncMethodCallsWithArguments[0]; |
||||
return (ActionArguments<CodeCoverageResults>)actionArgsAsObject; |
||||
} |
||||
|
||||
[Test] |
||||
public void CodeCoverageResultsFromXmlHasModuleCalledMyTests() |
||||
{ |
||||
CodeCoverageResults results = CreateCodeCoverageResults(); |
||||
string expectedName = "MyTests"; |
||||
Assert.AreEqual(expectedName, results.Modules[0].Name); |
||||
} |
||||
|
||||
CodeCoverageResults CreateCodeCoverageResults() |
||||
{ |
||||
TextReader reader = CreateCodeCoverageResultsTextReader(); |
||||
return new CodeCoverageResults(reader); |
||||
} |
||||
|
||||
TextReader CreateCodeCoverageResultsTextReader() |
||||
{ |
||||
string xml = |
||||
"<PartCoverReport>\r\n" + |
||||
" <File id='1' url='c:\\Projects\\MyTests\\MyTestFixture.cs'/>\r\n" + |
||||
" <Assembly id='1' name='MyTests' module='C:\\Projects\\MyTests\\bin\\MyTests.DLL' domain='test-domain.Tests.dll' domainIdx='1' />\r\n" + |
||||
" <Type name='MyTests.Tests.MyTestFixture' asmref='1'>\r\n" + |
||||
" <Method name='SimpleTest1'>\r\n" + |
||||
" <pt visit='12' sl='20' sc='3' el='20' ec='4' fid='1' />\r\n" + |
||||
" </Method>\r\n" + |
||||
" </Type>\r\n" + |
||||
"</PartCoverReport>"; |
||||
|
||||
return new StringReader(xml); |
||||
} |
||||
|
||||
[Test] |
||||
public void CodeCoverageProcessExitsAndCodeCoverageFileExistsCausesCodeCoverageResultsToBeReadFromFile() |
||||
{ |
||||
ActionArguments<CodeCoverageResults> actionArgs = |
||||
CreateTestRunnerAndFireCodeCoverageProcessExitEvent(); |
||||
|
||||
CodeCoverageResults result = actionArgs.Arg; |
||||
Assert.AreEqual("MyTests", result.Modules[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void CodeCoverageProcessExitsAndCodeCoverageFileDoesNotExistsAddsTaskToTaskList() |
||||
{ |
||||
ActionArguments<Task> args = CreateTestRunnerAndFirePartCoverProcessExitEventWhenNoCoverageFileProduced(); |
||||
Action<Task> expectedAction = context.MockTaskService.Add; |
||||
Assert.AreEqual(expectedAction, args.Action); |
||||
} |
||||
|
||||
ActionArguments<Task> CreateTestRunnerAndFirePartCoverProcessExitEventWhenNoCoverageFileProduced() |
||||
{ |
||||
mockCodeCoverageTestRunnerFactory.FileSystem.FileExistsReturnValue = false; |
||||
|
||||
command.CallCreateTestRunner(null); |
||||
|
||||
MockCSharpProject project = new MockCSharpProject(); |
||||
SelectedTests tests = new SelectedTests(project); |
||||
|
||||
mockCodeCoverageTestRunnerFactory.TestRunner.Start(tests); |
||||
mockCodeCoverageTestRunnerFactory.ProcessRunner.FireProcessExitedEvent(); |
||||
|
||||
object actionArgsAsObject = context.MockUnitTestWorkbench.SafeThreadAsyncMethodCallsWithArguments[0]; |
||||
return (ActionArguments<Task>)actionArgsAsObject; |
||||
} |
||||
|
||||
[Test] |
||||
public void CodeCoverageProcessExitsAndCodeCoverageFileDoesNotExistsAddsErrorTaskToTaskList() |
||||
{ |
||||
command.ParsedStringToReturn = "No code coverage results file generated."; |
||||
ActionArguments<Task> args = CreateTestRunnerAndFirePartCoverProcessExitEventWhenNoCoverageFileProduced(); |
||||
Task task = args.Arg; |
||||
|
||||
string description = @"No code coverage results file generated. c:\projects\MyTests\PartCover\coverage.xml"; |
||||
int column = 1; |
||||
int line = 1; |
||||
Task expectedTask = new Task(null, description, column, line, TaskType.Error); |
||||
|
||||
TaskComparison comparison = new TaskComparison(expectedTask, task); |
||||
|
||||
Assert.IsTrue(comparison.IsMatch, comparison.MismatchReason); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Diagnostics; |
||||
using ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.UnitTesting; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Utils |
||||
{ |
||||
public class DerivedCodeCoverageTestRunner : CodeCoverageTestRunner |
||||
{ |
||||
public string ParseStringReturnValue; |
||||
public string ParseStringParameter; |
||||
|
||||
public DerivedCodeCoverageTestRunner(IUnitTestProcessRunner processRunner, |
||||
ITestResultsMonitor testResultsMonitor, |
||||
UnitTestingOptions options, |
||||
IFileSystem fileSystem) |
||||
: base(processRunner, testResultsMonitor, options, fileSystem) |
||||
{ |
||||
} |
||||
|
||||
public ProcessStartInfo CallGetProcessStartInfo(SelectedTests selectedTests) |
||||
{ |
||||
return base.GetProcessStartInfo(selectedTests); |
||||
} |
||||
|
||||
public TestResult CallCreateTestResultForTestFramework(TestResult testResult) |
||||
{ |
||||
return base.CreateTestResultForTestFramework(testResult); |
||||
} |
||||
|
||||
protected override string ParseString(string text) |
||||
{ |
||||
ParseStringParameter = text; |
||||
return ParseStringReturnValue; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,63 @@
@@ -0,0 +1,63 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.SharpDevelop.Gui; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using ICSharpCode.UnitTesting; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Utils |
||||
{ |
||||
public class DerivedRunTestWithCodeCoverageCommand : RunTestWithCodeCoverageCommand |
||||
{ |
||||
public string ParsedStringToReturn = String.Empty; |
||||
public string ParsedString; |
||||
|
||||
public DerivedRunTestWithCodeCoverageCommand(IRunTestCommandContext context, |
||||
ICodeCoverageTestRunnerFactory factory) |
||||
: base(context, factory) |
||||
{ |
||||
} |
||||
|
||||
public void CallOnBeforeRunTests() |
||||
{ |
||||
base.OnBeforeRunTests(); |
||||
} |
||||
|
||||
public void CallOnAfterRunTests() |
||||
{ |
||||
base.OnAfterRunTests(); |
||||
} |
||||
|
||||
protected override MessageViewCategory CreateMessageViewCategory(string category, string displayCategory) |
||||
{ |
||||
return new MessageViewCategory(category, displayCategory); |
||||
} |
||||
|
||||
public MessageViewCategory CodeCoverageMessageViewCategory { |
||||
get { return base.Category; } |
||||
set { base.Category = value;} |
||||
} |
||||
|
||||
protected override string StringParse(string text) |
||||
{ |
||||
ParsedString = text; |
||||
return ParsedStringToReturn; |
||||
} |
||||
|
||||
public void CallTestRunnerMessageReceived(object source, MessageReceivedEventArgs e) |
||||
{ |
||||
base.TestRunnerMessageReceived(source, e); |
||||
} |
||||
|
||||
public ITestRunner CallCreateTestRunner(IProject project) |
||||
{ |
||||
return base.CreateTestRunner(project); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.UnitTesting; |
||||
using UnitTesting.Tests.Utils; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Utils |
||||
{ |
||||
public class MockCodeCoverageTestRunnerFactory : ICodeCoverageTestRunnerFactory |
||||
{ |
||||
public MockProcessRunner ProcessRunner; |
||||
public MockTestResultsMonitor TestResultsMonitor; |
||||
public UnitTestingOptions Options; |
||||
public CodeCoverageTestRunner TestRunner; |
||||
public MockFileSystem FileSystem; |
||||
|
||||
public MockCodeCoverageTestRunnerFactory() |
||||
{ |
||||
ProcessRunner = new MockProcessRunner(); |
||||
TestResultsMonitor = new MockTestResultsMonitor(); |
||||
Options = new UnitTestingOptions(new Properties()); |
||||
FileSystem = new MockFileSystem(); |
||||
TestRunner = new CodeCoverageTestRunner(ProcessRunner, TestResultsMonitor, Options, FileSystem); |
||||
} |
||||
|
||||
public CodeCoverageTestRunner CreateCodeCoverageTestRunner() |
||||
{ |
||||
return TestRunner; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.IO; |
||||
using ICSharpCode.CodeCoverage; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests.Utils |
||||
{ |
||||
public class MockFileSystem : IFileSystem |
||||
{ |
||||
public bool FileExistsReturnValue; |
||||
public string FileExistsPathParameter; |
||||
public string DeleteFilePathParameter; |
||||
public bool DirectoryExistsReturnValue; |
||||
public string DirectoryExistsPathParameter; |
||||
public string CreateDirectoryPathParameter; |
||||
public TextReader CreateTextReaderReturnValue; |
||||
public string CreateTextReaderPathParameter; |
||||
|
||||
public bool FileExists(string path) |
||||
{ |
||||
FileExistsPathParameter = path; |
||||
return FileExistsReturnValue; |
||||
} |
||||
|
||||
public void DeleteFile(string path) |
||||
{ |
||||
DeleteFilePathParameter = path; |
||||
} |
||||
|
||||
public bool DirectoryExists(string path) |
||||
{ |
||||
DirectoryExistsPathParameter = path; |
||||
return DirectoryExistsReturnValue; |
||||
} |
||||
|
||||
public void CreateDirectory(string path) |
||||
{ |
||||
CreateDirectoryPathParameter = path; |
||||
} |
||||
|
||||
public TextReader CreateTextReader(string path) |
||||
{ |
||||
CreateTextReaderPathParameter = path; |
||||
return CreateTextReaderReturnValue; |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue