Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2744 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
40 changed files with 1537 additions and 1047 deletions
@ -1,39 +1,47 @@
@@ -1,39 +1,47 @@
|
||||
<Components version="1.0"> |
||||
<System.Windows.Forms.UserControl> |
||||
<Name value="CodeCoverageProjectOptionsPanel" /> |
||||
<ClientSize value="{Width=342, Height=266}" /> |
||||
<ClientSize value="{Width=342, Height=396}" /> |
||||
<Controls> |
||||
<System.Windows.Forms.TextBox> |
||||
<Name value="excludedAttributesTextBox" /> |
||||
<Name value="excludeListTextBox" /> |
||||
<TabIndex value="3" /> |
||||
<Size value="{Width=317, Height=21}" /> |
||||
<Location value="{X=12,Y=92}" /> |
||||
<Location value="12, 229" /> |
||||
<WordWrap value="False" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<ScrollBars value="Vertical" /> |
||||
<AcceptsReturn value="True" /> |
||||
<Size value="317, 154" /> |
||||
<Multiline value="True" /> |
||||
</System.Windows.Forms.TextBox> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="excludedAttributesListLabel" /> |
||||
<Location value="{X=12,Y=69}" /> |
||||
<Text value="${res:ICSharpCode.CodeCoverage.ProjectOptionsPanel.ExcludeAttributes}:" /> |
||||
<Name value="excludeListLabel" /> |
||||
<Location value="12, 206" /> |
||||
<Text value="${res:ICSharpCode.CodeCoverage.ProjectOptionsPanel.ExcludeListLabel}:" /> |
||||
<Size value="317, 20" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<Size value="{Width=317, Height=20}" /> |
||||
<TabIndex value="2" /> |
||||
</System.Windows.Forms.Label> |
||||
<System.Windows.Forms.TextBox> |
||||
<Name value="assemblyListTextBox" /> |
||||
<Name value="includeListTextBox" /> |
||||
<TabIndex value="1" /> |
||||
<Size value="{Width=317, Height=21}" /> |
||||
<Location value="{X=12,Y=36}" /> |
||||
<Location value="12, 36" /> |
||||
<WordWrap value="False" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<ScrollBars value="Vertical" /> |
||||
<AcceptsReturn value="True" /> |
||||
<Size value="317, 154" /> |
||||
<Multiline value="True" /> |
||||
</System.Windows.Forms.TextBox> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="assemblyListLabel" /> |
||||
<Location value="{X=12,Y=12}" /> |
||||
<Name value="includeListLabel" /> |
||||
<Location value="12, 12" /> |
||||
<UseCompatibleTextRendering value="True" /> |
||||
<Text value="${res:ICSharpCode.CodeCoverage.ProjectOptionsPanel.AssemblyListLabel}" /> |
||||
<Text value="${res:ICSharpCode.CodeCoverage.ProjectOptionsPanel.IncludeListLabel}" /> |
||||
<Size value="317, 21" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<Size value="{Width=317, Height=21}" /> |
||||
<TabIndex value="0" /> |
||||
</System.Windows.Forms.Label> |
||||
</Controls> |
||||
</System.Windows.Forms.UserControl> |
||||
</Components> |
||||
</Components> |
@ -1,277 +0,0 @@
@@ -1,277 +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.Text; |
||||
using ICSharpCode.SharpDevelop.Util; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
/// <summary>
|
||||
/// Runs NCover.
|
||||
/// </summary>
|
||||
public class NCoverRunner |
||||
{ |
||||
string ncoverFileName = String.Empty; |
||||
string workingDirectory = String.Empty; |
||||
string coverageResultsFileName = String.Empty; |
||||
string profiledApplicationCommand = String.Empty; |
||||
string profiledApplicationCommandLineArguments = String.Empty; |
||||
string assemblyList = String.Empty; |
||||
string logFileName = String.Empty; |
||||
string excludedAttributesList = String.Empty; |
||||
ProcessRunner runner; |
||||
|
||||
/// <summary>
|
||||
/// Triggered when NCover exits.
|
||||
/// </summary>
|
||||
public event NCoverExitEventHandler NCoverExited; |
||||
|
||||
/// <summary>
|
||||
/// The NCover runner was started.
|
||||
/// </summary>
|
||||
public event EventHandler NCoverStarted; |
||||
|
||||
/// <summary>
|
||||
/// The NCover runner was stopped. Being stopped is not the
|
||||
/// same as NCover exiting.
|
||||
/// </summary>
|
||||
public event EventHandler NCoverStopped; |
||||
|
||||
/// <summary>
|
||||
/// Triggered when an output line is received from NCover.
|
||||
/// </summary>
|
||||
public event LineReceivedEventHandler OutputLineReceived; |
||||
|
||||
public NCoverRunner() |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the NCover executable path.
|
||||
/// </summary>
|
||||
public string NCoverFileName { |
||||
get { |
||||
return ncoverFileName; |
||||
} |
||||
set { |
||||
ncoverFileName = value; |
||||
} |
||||
} |
||||
|
||||
public string WorkingDirectory { |
||||
get { |
||||
return workingDirectory; |
||||
} |
||||
set { |
||||
workingDirectory = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The list of assemblies that will be profiled.
|
||||
/// </summary>
|
||||
public string AssemblyList { |
||||
get { |
||||
return assemblyList; |
||||
} |
||||
set { |
||||
// Remove any spaces from the assembly list since
|
||||
// NCover will ignore any items after the space.
|
||||
assemblyList = value.Replace(" ", String.Empty); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The list of attributes to ignore when profiling.
|
||||
/// </summary>
|
||||
public string ExcludedAttributesList { |
||||
get { |
||||
return excludedAttributesList; |
||||
} |
||||
set { |
||||
// Remove any spaces from the assembly list since
|
||||
// NCover will ignore any items after the space.
|
||||
excludedAttributesList = value.Replace(" ", String.Empty); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the full NCover command line that will be used by
|
||||
/// the runner.
|
||||
/// </summary>
|
||||
public string CommandLine { |
||||
get { |
||||
return String.Concat(ncoverFileName, " ", GetArguments()); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets whether the NCover runner is currently running.
|
||||
/// </summary>
|
||||
public bool IsRunning { |
||||
get { |
||||
if (runner != null) { |
||||
return runner.IsRunning; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Coverage output results file.
|
||||
/// </summary>
|
||||
public string CoverageResultsFileName { |
||||
get { |
||||
return coverageResultsFileName; |
||||
} |
||||
set { |
||||
coverageResultsFileName = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Profiler log file.
|
||||
/// </summary>
|
||||
public string LogFileName { |
||||
get { |
||||
return logFileName; |
||||
} |
||||
set { |
||||
logFileName = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the command that will be used to run the
|
||||
/// profiled application.
|
||||
/// </summary>
|
||||
public string ProfiledApplicationCommand { |
||||
get { |
||||
return profiledApplicationCommand; |
||||
} |
||||
set { |
||||
profiledApplicationCommand = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The arguments that will be used with the profiled application.
|
||||
/// </summary>
|
||||
public string ProfiledApplicationCommandLineArguments { |
||||
get { |
||||
return profiledApplicationCommandLineArguments; |
||||
} |
||||
set { |
||||
profiledApplicationCommandLineArguments = value; |
||||
} |
||||
} |
||||
|
||||
public void Start() |
||||
{ |
||||
string arguments = GetArguments(); |
||||
|
||||
runner = new ProcessRunner(); |
||||
runner.WorkingDirectory = workingDirectory; |
||||
runner.ProcessExited += new EventHandler(ProcessExited); |
||||
|
||||
if (OutputLineReceived != null) { |
||||
runner.OutputLineReceived += new LineReceivedEventHandler(OnOutputLineReceived); |
||||
} |
||||
runner.Start(ncoverFileName, arguments); |
||||
OnNCoverStarted(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Stops the currently running NCover instance.
|
||||
/// </summary>
|
||||
public void Stop() |
||||
{ |
||||
if (runner != null) { |
||||
runner.Kill(); |
||||
OnNCoverStopped(); |
||||
} |
||||
} |
||||
|
||||
protected void OnNCoverExited(string output, string error, int exitCode) |
||||
{ |
||||
if (NCoverExited != null) { |
||||
NCoverExited(this, new NCoverExitEventArgs(output, error, exitCode)); |
||||
} |
||||
} |
||||
|
||||
protected void OnNCoverStarted() |
||||
{ |
||||
if (NCoverStarted != null) { |
||||
NCoverStarted(this, new EventArgs()); |
||||
} |
||||
} |
||||
|
||||
protected void OnNCoverStopped() |
||||
{ |
||||
if (NCoverStopped != null) { |
||||
NCoverStopped(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 NCover 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; |
||||
OnNCoverExited(runner.StandardOutput, runner.StandardError, runner.ExitCode); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds extra command line arguments to those specified
|
||||
/// by the user in the <see cref="Arguments"/> string.
|
||||
/// </summary>
|
||||
string GetArguments() |
||||
{ |
||||
StringBuilder ncoverArguments = new StringBuilder(); |
||||
|
||||
if (coverageResultsFileName.Length > 0) { |
||||
ncoverArguments.AppendFormat("//x \"{0}\" ", coverageResultsFileName); |
||||
} |
||||
|
||||
if (assemblyList.Length > 0) { |
||||
ncoverArguments.AppendFormat("//a \"{0}\" ", assemblyList); |
||||
} |
||||
|
||||
if (excludedAttributesList.Length > 0) { |
||||
ncoverArguments.AppendFormat("//ea \"{0}\" ", excludedAttributesList); |
||||
} |
||||
|
||||
if (logFileName.Length > 0) { |
||||
ncoverArguments.AppendFormat("//l \"{0}\" ", logFileName); |
||||
} |
||||
|
||||
ncoverArguments.AppendFormat("\"{0}\" ", profiledApplicationCommand); |
||||
|
||||
//ncoverArguments.Append(profiledApplicationCommandLineArguments);
|
||||
// HACK: Work around NCover bug: http://ncover.org/SITE/forums/thread/266.aspx
|
||||
ncoverArguments.Append(profiledApplicationCommandLineArguments.Replace("\"", "\\\"")); |
||||
|
||||
return ncoverArguments.ToString(); |
||||
} |
||||
} |
||||
} |
@ -1,116 +0,0 @@
@@ -1,116 +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.IO; |
||||
using System.Text; |
||||
using System.Xml; |
||||
|
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
/// <summary>
|
||||
/// Settings for NCover.
|
||||
/// </summary>
|
||||
public class NCoverSettings |
||||
{ |
||||
static readonly string RootElementName = "ProfilerSettings"; |
||||
static readonly string AssembliesElementName = "Assemblies"; |
||||
static readonly string ExclusionAttributesElementName = "ExclusionAttributes"; |
||||
|
||||
string assemblyList = String.Empty; |
||||
string excludedAttributesList = String.Empty; |
||||
|
||||
public NCoverSettings() |
||||
{ |
||||
} |
||||
|
||||
public NCoverSettings(string fileName) : this(new StreamReader(fileName, true)) |
||||
{ |
||||
} |
||||
|
||||
public NCoverSettings(XmlReader reader) |
||||
{ |
||||
ReadSettings(reader); |
||||
} |
||||
|
||||
public NCoverSettings(TextReader reader) : this(new XmlTextReader(reader)) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the NCover settings filename for the specified project.
|
||||
/// </summary>
|
||||
public static string GetFileName(IProject project) |
||||
{ |
||||
return Path.ChangeExtension(project.FileName, "NCover.Settings"); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// A semi-colon delimited list of assemblies.
|
||||
/// </summary>
|
||||
public string AssemblyList { |
||||
get { |
||||
return assemblyList; |
||||
} |
||||
set { |
||||
assemblyList = value; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// A semi-colon delimited list of attributes to exclude in the code coverage
|
||||
/// report.
|
||||
/// </summary>
|
||||
public string ExcludedAttributesList { |
||||
get { |
||||
return excludedAttributesList; |
||||
} |
||||
set { |
||||
excludedAttributesList = value; |
||||
} |
||||
} |
||||
|
||||
public void Save(TextWriter writer) |
||||
{ |
||||
Save(new XmlTextWriter(writer)); |
||||
} |
||||
|
||||
public void Save(string fileName) |
||||
{ |
||||
Save(new StreamWriter(fileName, false, Encoding.UTF8)); |
||||
} |
||||
|
||||
public void Save(XmlTextWriter writer) |
||||
{ |
||||
writer.Formatting = Formatting.Indented; |
||||
|
||||
using (writer) { |
||||
writer.WriteStartElement(RootElementName); |
||||
writer.WriteElementString(AssembliesElementName, assemblyList); |
||||
writer.WriteElementString(ExclusionAttributesElementName, excludedAttributesList); |
||||
writer.WriteEndElement(); |
||||
} |
||||
} |
||||
|
||||
void ReadSettings(XmlReader reader) |
||||
{ |
||||
using (reader) { |
||||
while (reader.Read()) { |
||||
if (reader.NodeType == XmlNodeType.Element) { |
||||
if (reader.Name == AssembliesElementName) { |
||||
assemblyList = reader.ReadString(); |
||||
} else if (reader.Name == ExclusionAttributesElementName) { |
||||
excludedAttributesList = reader.ReadString(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,265 @@
@@ -0,0 +1,265 @@
|
||||
// <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.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,147 @@
@@ -0,0 +1,147 @@
|
||||
// <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.IO; |
||||
using System.Text; |
||||
using System.Xml; |
||||
|
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.CodeCoverage |
||||
{ |
||||
/// <summary>
|
||||
/// File that stores PartCover settings. This file has the same format as
|
||||
/// PartCover requires, but is actually just used by the Code Coverage addin
|
||||
/// as a place to store the include and exclude regular expressions that the
|
||||
/// user may set up on a per project basis.
|
||||
/// </summary>
|
||||
public class PartCoverSettings |
||||
{ |
||||
static readonly string RootElementName = "PartCoverSettings"; |
||||
static readonly string RuleElementName = "Rule"; |
||||
StringCollection include = new StringCollection(); |
||||
StringCollection exclude = new StringCollection(); |
||||
|
||||
public PartCoverSettings() |
||||
{ |
||||
} |
||||
|
||||
public PartCoverSettings(string fileName) |
||||
: this(new StreamReader(fileName, true)) |
||||
{ |
||||
} |
||||
|
||||
public PartCoverSettings(XmlReader reader) |
||||
{ |
||||
ReadSettings(reader); |
||||
} |
||||
|
||||
public PartCoverSettings(TextReader reader) |
||||
: this(new XmlTextReader(reader)) |
||||
{ |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the NCover settings filename for the specified project.
|
||||
/// </summary>
|
||||
public static string GetFileName(IProject project) |
||||
{ |
||||
return Path.ChangeExtension(project.FileName, "PartCover.Settings"); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the list of include regular expressions.
|
||||
/// </summary>
|
||||
public StringCollection Include { |
||||
get { return include; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Gets the list of exclude regular expressions.
|
||||
/// </summary>
|
||||
public StringCollection Exclude { |
||||
get { return exclude; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes the PartCover settings to the specified text writer.
|
||||
/// </summary>
|
||||
public void Save(TextWriter writer) |
||||
{ |
||||
Save(new XmlTextWriter(writer)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Saves the PartCover settings to the specified file.
|
||||
/// </summary>
|
||||
public void Save(string fileName) |
||||
{ |
||||
Save(new StreamWriter(fileName, false, Encoding.UTF8)); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes the PartCover settings to the specified XmlTextWriter.
|
||||
/// </summary>
|
||||
public void Save(XmlTextWriter writer) |
||||
{ |
||||
writer.Formatting = Formatting.Indented; |
||||
|
||||
using (writer) { |
||||
writer.WriteStartElement(RootElementName); |
||||
WriteRuleElements(writer, "+", include); |
||||
WriteRuleElements(writer, "-", exclude); |
||||
writer.WriteEndElement(); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reads the include and exclude regular expressions from the
|
||||
/// PartCover settings xml.
|
||||
/// </summary>
|
||||
void ReadSettings(XmlReader reader) |
||||
{ |
||||
using (reader) { |
||||
while (reader.Read()) { |
||||
if (reader.NodeType == XmlNodeType.Element) { |
||||
if (reader.Name == RuleElementName) { |
||||
AddRule(reader.ReadString()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Writes the Rule elements to the writer. Each item in the collection will
|
||||
/// have be prefixed with the specified prefix string.
|
||||
/// </summary>
|
||||
void WriteRuleElements(XmlWriter writer, string prefix, StringCollection rules) |
||||
{ |
||||
foreach (string rule in rules) { |
||||
writer.WriteElementString(RuleElementName, prefix + rule); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Adds an include or exclude regular expression. The rule starts with
|
||||
/// a '+' if it is an include. It starts with a '-' if it is an exclude.
|
||||
/// </summary>
|
||||
void AddRule(string rule) |
||||
{ |
||||
if (rule.Length > 0) { |
||||
char firstCharacter = rule[0]; |
||||
if (firstCharacter == '+') { |
||||
include.Add(rule.Substring(1)); |
||||
} else if (firstCharacter == '-') { |
||||
exclude.Add(rule.Substring(1)); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,73 @@
@@ -0,0 +1,73 @@
|
||||
// <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; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// PartCover does not always put a file id in the code
|
||||
/// coverage report. We also ensure that a module that has no
|
||||
/// associated source code is not included in the final list
|
||||
/// of modules.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class CodeCoverageResultsMissingFileIdTestFixture |
||||
{ |
||||
CodeCoverageResults results; |
||||
|
||||
[SetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
string xml = "<PartCoverReport ver=\"1.0.2796.35184\">\r\n" + |
||||
"<file id=\"1\" url=\"c:\\test\\MyTests\\Class1.cs\" />\r\n" + |
||||
"<type asm=\"nunit.framework\" name=\"NUnit.Framework.NotEqualAsserter\" flags=\"1233408\">\r\n" + |
||||
" <method name=\"Fail\" sig=\"bool ()\" flags=\"134\" iflags=\"0\">\r\n" + |
||||
" <code>\r\n" + |
||||
" <pt visit=\"1\" pos=\"11\" len=\"1\" />\r\n" + |
||||
" <pt visit=\"0\" pos=\"6\" len=\"5\" />\r\n" + |
||||
" <pt visit=\"0\" pos=\"0\" len=\"6\" />\r\n" + |
||||
" </code>\r\n" + |
||||
" </method>\r\n" + |
||||
"</type>\r\n" + |
||||
"<type asm=\"MyTests.Tests\" name=\"MyClass\" flags=\"1233248\">\r\n" + |
||||
" <method name=\".ctor\" sig=\"void ()\" flags=\"6278\" iflags=\"0\">\r\n" + |
||||
" <code>\r\n" + |
||||
" <pt visit=\"0\" pos=\"8\" len=\"2\" fid=\"1\" sl=\"21\" sc=\"3\" el=\"21\" ec=\"4\" />\r\n" + |
||||
" <pt visit=\"0\" pos=\"7\" len=\"1\" fid=\"1\" sl=\"20\" sc=\"3\" el=\"20\" ec=\"4\" />\r\n" + |
||||
" <pt visit=\"0\" pos=\"0\" len=\"7\" fid=\"1\" sl=\"19\" sc=\"3\" el=\"19\" ec=\"18\" />\r\n" + |
||||
" <pt visit=\"0\" pos=\"0\" len=\"7\" sl=\"19\" sc=\"3\" el=\"19\" ec=\"18\" />\r\n" + |
||||
" </code>\r\n" + |
||||
" </method>\r\n" + |
||||
"</type>\r\n" + |
||||
"</PartCoverReport>"; |
||||
|
||||
results = new CodeCoverageResults(new StringReader(xml)); |
||||
} |
||||
|
||||
[Test] |
||||
public void OneModule() |
||||
{ |
||||
Assert.AreEqual(1, results.Modules.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void ModuleName() |
||||
{ |
||||
Assert.AreEqual("MyTests.Tests", results.Modules[0].Name); |
||||
} |
||||
|
||||
[Test] |
||||
public void MyTestsCtorHasThreeSequencePoints() |
||||
{ |
||||
Assert.AreEqual(3, results.Modules[0].Methods[0].SequencePoints.Count); |
||||
} |
||||
} |
||||
} |
@ -1,52 +0,0 @@
@@ -1,52 +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 ICSharpCode.CodeCoverage; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that results with the excluded attribute set are not included
|
||||
/// in the code coverage results.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ExcludedMethodResultsTestFixture |
||||
{ |
||||
CodeCoverageResults results; |
||||
CodeCoverageModule module; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
string xml = "<coverage>\r\n" + |
||||
"\t<module name=\"C:\\Projects\\Foo.Tests\\bin\\Debug\\Foo.Tests.dll\" assembly=\"Foo.Tests\">\r\n" + |
||||
"\t\t<method name=\"ExcludedTest\" class=\"Foo.Tests.FooTestFixture\">\r\n" + |
||||
"\t\t\t<seqpnt visitcount=\"0\" line=\"20\" column=\"3\" endline=\"20\" excluded=\"true\" endcolumn=\"4\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" + |
||||
"\t\t\t<seqpnt visitcount=\"0\" line=\"21\" column=\"13\" endline=\"21\" excluded=\"true\" endcolumn=\"32\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" + |
||||
"\t\t\t<seqpnt visitcount=\"0\" line=\"24\" column=\"3\" endline=\"24\" excluded=\"true\" endcolumn=\"4\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" + |
||||
"\t\t</method>\r\n" + |
||||
"\t\t<method name=\"SimpleTest\" class=\"Foo.Tests.FooTestFixture\">\r\n" + |
||||
"\t\t\t<seqpnt visitcount=\"0\" line=\"20\" column=\"3\" endline=\"20\" excluded=\"false\" endcolumn=\"4\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" + |
||||
"\t\t\t<seqpnt visitcount=\"0\" line=\"21\" column=\"13\" endline=\"21\" excluded=\"false\" endcolumn=\"32\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" + |
||||
"\t\t\t<seqpnt visitcount=\"0\" line=\"24\" column=\"3\" endline=\"24\" excluded=\"false\" endcolumn=\"4\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" + |
||||
"\t\t</method>\r\n" + |
||||
"\t</module>\r\n" + |
||||
"</coverage>"; |
||||
results = new CodeCoverageResults(new StringReader(xml)); |
||||
module = results.Modules[0]; |
||||
} |
||||
|
||||
[Test] |
||||
public void OneMethod() |
||||
{ |
||||
Assert.AreEqual(1, module.Methods.Count); |
||||
} |
||||
} |
||||
} |
@ -1,31 +0,0 @@
@@ -1,31 +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 ICSharpCode.CodeCoverage; |
||||
using NUnit.Framework; |
||||
using System; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Ensures that a code coverage method that has no included sequence
|
||||
/// points is flagged as excluded.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ExcludedMethodTestFixture |
||||
{ |
||||
[Test] |
||||
public void IsExcluded() |
||||
{ |
||||
CodeCoverageMethod method = new CodeCoverageMethod("Test1", "MyTestFixture"); |
||||
CodeCoverageSequencePoint pt = new CodeCoverageSequencePoint(@"c:\test\MyTestFixture.cs", 0, 10, 0, 10, 20, true); |
||||
method.SequencePoints.Add(pt); |
||||
|
||||
Assert.IsTrue(method.IsExcluded, "Method should be excluded."); |
||||
} |
||||
} |
||||
} |
@ -1,45 +1,45 @@
@@ -1,45 +1,45 @@
|
||||
// <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 ICSharpCode.CodeCoverage; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that results with the excluded attribute set are not included
|
||||
/// in the code coverage results.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class ExcludedModuleResultsTestFixture |
||||
{ |
||||
CodeCoverageResults results; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
string xml = "<coverage>\r\n" + |
||||
"\t<module name=\"C:\\Projects\\Foo.Tests\\bin\\Debug\\Foo.Tests.dll\" assembly=\"Foo.Tests\">\r\n" + |
||||
"\t\t<method name=\"SimpleTest\" class=\"Foo.Tests.FooTestFixture\">\r\n" + |
||||
"\t\t\t<seqpnt visitcount=\"0\" line=\"20\" column=\"3\" endline=\"20\" excluded=\"true\" endcolumn=\"4\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" + |
||||
"\t\t\t<seqpnt visitcount=\"0\" line=\"21\" column=\"13\" endline=\"21\" excluded=\"true\" endcolumn=\"32\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" + |
||||
"\t\t\t<seqpnt visitcount=\"0\" line=\"24\" column=\"3\" endline=\"24\" excluded=\"true\" endcolumn=\"4\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" + |
||||
"\t\t</method>\r\n" + |
||||
"\t</module>\r\n" + |
||||
"</coverage>"; |
||||
results = new CodeCoverageResults(new StringReader(xml)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoModules() |
||||
{ |
||||
Assert.AreEqual(0, results.Modules.Count, "All modules should be excluded"); |
||||
} |
||||
} |
||||
} |
||||
//// <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 ICSharpCode.CodeCoverage;
|
||||
//using NUnit.Framework;
|
||||
//using System;
|
||||
//using System.IO;
|
||||
//
|
||||
//namespace ICSharpCode.CodeCoverage.Tests
|
||||
//{
|
||||
// /// <summary>
|
||||
// /// Tests that results with the excluded attribute set are not included
|
||||
// /// in the code coverage results.
|
||||
// /// </summary>
|
||||
// [TestFixture]
|
||||
// public class ExcludedModuleResultsTestFixture
|
||||
// {
|
||||
// CodeCoverageResults results;
|
||||
//
|
||||
// [TestFixtureSetUp]
|
||||
// public void SetUpFixture()
|
||||
// {
|
||||
// string xml = "<coverage>\r\n" +
|
||||
// "\t<module name=\"C:\\Projects\\Foo.Tests\\bin\\Debug\\Foo.Tests.dll\" assembly=\"Foo.Tests\">\r\n" +
|
||||
// "\t\t<method name=\"SimpleTest\" class=\"Foo.Tests.FooTestFixture\">\r\n" +
|
||||
// "\t\t\t<seqpnt visitcount=\"0\" line=\"20\" column=\"3\" endline=\"20\" excluded=\"true\" endcolumn=\"4\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" +
|
||||
// "\t\t\t<seqpnt visitcount=\"0\" line=\"21\" column=\"13\" endline=\"21\" excluded=\"true\" endcolumn=\"32\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" +
|
||||
// "\t\t\t<seqpnt visitcount=\"0\" line=\"24\" column=\"3\" endline=\"24\" excluded=\"true\" endcolumn=\"4\" document=\"c:\\Projects\\Foo\\FooTestFixture.cs\" />\r\n" +
|
||||
// "\t\t</method>\r\n" +
|
||||
// "\t</module>\r\n" +
|
||||
// "</coverage>";
|
||||
// results = new CodeCoverageResults(new StringReader(xml));
|
||||
// }
|
||||
//
|
||||
// [Test]
|
||||
// public void NoModules()
|
||||
// {
|
||||
// Assert.AreEqual(0, results.Modules.Count, "All modules should be excluded");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
@ -1,56 +0,0 @@
@@ -1,56 +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 ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests |
||||
{ |
||||
[TestFixture] |
||||
public class NCoverSettingsTestFixture |
||||
{ |
||||
NCoverSettings settings; |
||||
NCoverSettings savedSettings; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
settings = new NCoverSettings(); |
||||
settings.AssemblyList = "MyNamespace.Foo; MyNamespace.Bar"; |
||||
settings.ExcludedAttributesList = "NUnit.Framework.TestFixtureAttribute; NUnit.Framework.TestAttribute"; |
||||
StringBuilder savedSettingsXml = new StringBuilder(); |
||||
settings.Save(new StringWriter(savedSettingsXml)); |
||||
savedSettings = new NCoverSettings(new StringReader(savedSettingsXml.ToString())); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsAssemblyListSaved() |
||||
{ |
||||
Assert.AreEqual(settings.AssemblyList, savedSettings.AssemblyList); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsExcludedAttributeListListSaved() |
||||
{ |
||||
Assert.AreEqual(settings.ExcludedAttributesList, savedSettings.ExcludedAttributesList); |
||||
} |
||||
|
||||
[Test] |
||||
public void NCoverSettingsFileName() |
||||
{ |
||||
MSBuildBasedProject project = new MSBuildBasedProject(MSBuildInternals.CreateEngine()); |
||||
project.FileName = @"C:\temp\test.csproj"; |
||||
|
||||
Assert.AreEqual(@"C:\temp\test.NCover.Settings", NCoverSettings.GetFileName(project)); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,176 @@
@@ -0,0 +1,176 @@
|
||||
// <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 |
||||
{ |
||||
/// <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()); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,49 @@
@@ -0,0 +1,49 @@
|
||||
// <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 |
||||
{ |
||||
/// <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,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.IO; |
||||
using ICSharpCode.CodeCoverage; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Tests that the PartCoverSettings class does not throw an index out of
|
||||
/// range exception when the Rule elements are empty strings.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class PartCoverSettingsMissingRulePrefixTestFixture |
||||
{ |
||||
PartCoverSettings settings; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
string xml = "<PartCoverSettings>\r\n" + |
||||
" <Rule/>\r\n" + |
||||
" <Rule></Rule>\r\n" + |
||||
"</PartCoverSettings>"; |
||||
|
||||
settings = new PartCoverSettings(new StringReader(xml)); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoIncludes() |
||||
{ |
||||
Assert.AreEqual(0, settings.Include.Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void NoExcludes() |
||||
{ |
||||
Assert.AreEqual(0, settings.Exclude.Count); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
// <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 ICSharpCode.CodeCoverage; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
using NUnit.Framework; |
||||
using System; |
||||
using System.IO; |
||||
using System.Text; |
||||
using System.Xml; |
||||
|
||||
namespace ICSharpCode.CodeCoverage.Tests |
||||
{ |
||||
/// <summary>
|
||||
/// Tests the saving and loading of the PartCover settings file. This
|
||||
/// file is used to stores the includes and excludes regular expressions
|
||||
/// that PartCover uses.
|
||||
/// </summary>
|
||||
[TestFixture] |
||||
public class PartCoverSettingsTestFixture |
||||
{ |
||||
PartCoverSettings settings; |
||||
PartCoverSettings savedSettings; |
||||
StringBuilder savedSettingsXml; |
||||
XmlDocument doc; |
||||
|
||||
[SetUp] |
||||
public void Init() |
||||
{ |
||||
settings = new PartCoverSettings(); |
||||
settings.Include.Add("[a]*"); |
||||
settings.Include.Add("[b]*"); |
||||
settings.Exclude.Add("[c]*"); |
||||
settings.Exclude.Add("[d]*"); |
||||
savedSettingsXml = new StringBuilder(); |
||||
settings.Save(new StringWriter(savedSettingsXml)); |
||||
savedSettings = new PartCoverSettings(new StringReader(savedSettingsXml.ToString())); |
||||
|
||||
doc = new XmlDocument(); |
||||
doc.LoadXml(savedSettingsXml.ToString()); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsIncludeListSaved() |
||||
{ |
||||
Assert.AreEqual(settings.Include, savedSettings.Include); |
||||
} |
||||
|
||||
[Test] |
||||
public void IsExcludedListSaved() |
||||
{ |
||||
Assert.AreEqual(settings.Exclude, savedSettings.Exclude); |
||||
} |
||||
|
||||
[Test] |
||||
public void PartCoverSettingsFileName() |
||||
{ |
||||
MSBuildBasedProject project = new MSBuildBasedProject(MSBuildInternals.CreateEngine()); |
||||
project.FileName = @"C:\temp\test.csproj"; |
||||
|
||||
Assert.AreEqual(@"C:\temp\test.PartCover.Settings", PartCoverSettings.GetFileName(project)); |
||||
} |
||||
|
||||
[Test] |
||||
public void FourRuleElements() |
||||
{ |
||||
Assert.AreEqual(4, doc.SelectNodes("/PartCoverSettings/Rule").Count); |
||||
} |
||||
|
||||
[Test] |
||||
public void FirstRuleElement() |
||||
{ |
||||
Assert.IsNotNull(doc.SelectSingleNode("/PartCoverSettings/Rule[text()='+[a]*']")); |
||||
} |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue