Skip to content

Commit

Permalink
Merge branch 'develop/travis/Fukurou' into develop/Genbu
Browse files Browse the repository at this point in the history
# Conflicts:
#	AltCover.Cake/DotNet.cs
#	AltCover.Tool/Program.fs
#	AltCover/Api.fs
#	Build/targets.fsx
  • Loading branch information
SteveGilham committed Feb 28, 2020
2 parents e53521f + 5c64f8d commit 49dcb64
Show file tree
Hide file tree
Showing 58 changed files with 764 additions and 607 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ Tests/TestResults/
ThirdParty/gendarme.zip
ThirdParty/gendarme/
Sample4/TestResults/
Sample18/TestResults/
*.user
40 changes: 24 additions & 16 deletions AltCover.CSApi/Definitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,18 @@ namespace AltCover

public static class CSApi
{
public static int Prepare(IPrepareArgs p, ILogArgs l)
public static int Prepare(IPrepareArgs prepareArgs, ILogArgs log)
{
return Api.Prepare(p.ToParameters(), l.ToParameters());
if (prepareArgs == null) throw new ArgumentNullException(nameof(prepareArgs));
if (log == null) throw new ArgumentNullException(nameof(log));
return Api.Prepare(prepareArgs.ToParameters(), log.ToParameters());
}

public static int Collect(ICollectArgs c, ILogArgs l)
public static int Collect(ICollectArgs collectArgs, ILogArgs log)
{
return Api.Collect(c.ToParameters(), l.ToParameters());
if (collectArgs == null) throw new ArgumentNullException(nameof(collectArgs));
if (log == null) throw new ArgumentNullException(nameof(log));
return Api.Collect(collectArgs.ToParameters(), log.ToParameters());
}

public static string Ipmo()
Expand All @@ -329,22 +333,26 @@ private static DotNet.CLIArgs ToCLIArgs(ICLIArg args)
return DotNet.CLIArgs.NewMany(new[] { force, failfast, showsummary });
}

public static string ToTestArguments(IPrepareArgs p,
ICollectArgs c,
ICLIArg force)
public static string ToTestArguments(IPrepareArgs prepareArgs,
ICollectArgs collectArgs,
ICLIArg control)
{
return DotNet.ToTestArguments(p.ToParameters(),
c.ToParameters(),
ToCLIArgs(force));
if (prepareArgs == null) throw new ArgumentNullException(nameof(prepareArgs));
if (collectArgs == null) throw new ArgumentNullException(nameof(collectArgs));
return DotNet.ToTestArguments(prepareArgs.ToParameters(),
collectArgs.ToParameters(),
ToCLIArgs(control));
}

public static string[] ToTestArgumentList(IPrepareArgs p,
ICollectArgs c,
ICLIArg force)
public static string[] ToTestArgumentList(IPrepareArgs prepareArgs,
ICollectArgs collectArgs,
ICLIArg control)
{
return DotNet.ToTestArgumentList(p.ToParameters(),
c.ToParameters(),
ToCLIArgs(force)).
if (prepareArgs == null) throw new ArgumentNullException(nameof(prepareArgs));
if (collectArgs == null) throw new ArgumentNullException(nameof(collectArgs));
return DotNet.ToTestArgumentList(prepareArgs.ToParameters(),
collectArgs.ToParameters(),
ToCLIArgs(control)).
ToArray();
}
}
Expand Down
1 change: 1 addition & 0 deletions AltCover.CSApi/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: System.CLSCompliant(true)]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand Down
1 change: 1 addition & 0 deletions AltCover.CSApi/altcover.csapi.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<DeterministicSourcePaths Condition="'$(APPVEYOR)'=='True'">true</DeterministicSourcePaths>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(ProjectDir)..\Build\Infrastructure.snk</AssemblyOriginatorKeyFile>
<SolutionDir Condition="'$(AltCoverGendarme)' == 'true'">$(ProjectDir)../</SolutionDir>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
87 changes: 45 additions & 42 deletions AltCover.Cake/Cake.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cake.Core;
using System.Diagnostics.CodeAnalysis;
using Cake.Core;
using Cake.Core.Annotations;
using LogLevel = Cake.Core.Diagnostics.LogLevel;
using Verbosity = Cake.Core.Diagnostics.Verbosity;
Expand All @@ -7,53 +8,55 @@

namespace AltCover.Cake
{
public static class Api
public static class Api
{
private static ILogArgs MakeLog(ICakeContext context, ILogArgs log)
{
private static ILogArgs MakeLog(ICakeContext context, ILogArgs l)
{
if (l != null)
return l;
if (log != null)
return log;

if (context != null)
return new LogArgs()
{
Info = x => context.Log.Write(Verbosity.Normal, LogLevel.Information, x),
Warn = x => context.Log.Write(Verbosity.Normal, LogLevel.Warning, x),
Echo = x => context.Log.Write(Verbosity.Normal, LogLevel.Error, x),
Error = x => context.Log.Write(Verbosity.Verbose, LogLevel.Information, x),
};
if (context != null)
return new LogArgs()
{
Info = x => context.Log.Write(Verbosity.Normal, LogLevel.Information, x),
Warn = x => context.Log.Write(Verbosity.Normal, LogLevel.Warning, x),
Echo = x => context.Log.Write(Verbosity.Normal, LogLevel.Error, x),
Error = x => context.Log.Write(Verbosity.Verbose, LogLevel.Information, x),
};

return new LogArgs()
{
Info = x => { },
Warn = x => { },
Echo = x => { },
Error = x => { }
};
}
return new LogArgs()
{
Info = x => { },
Warn = x => { },
Echo = x => { },
Error = x => { }
};
}

[CakeMethodAlias]
public static int Prepare(this ICakeContext context, IPrepareArgs p, ILogArgs l = null)
{
return CSApi.Prepare(p, MakeLog(context, l));
}
[CakeMethodAlias]
public static int Prepare(this ICakeContext context, IPrepareArgs prepareArgs, ILogArgs log = null)
{
return CSApi.Prepare(prepareArgs, MakeLog(context, log));
}

[CakeMethodAlias]
public static int Collect(this ICakeContext context, ICollectArgs c, ILogArgs l = null)
{
return CSApi.Collect(c, MakeLog(context, l));
}
[CakeMethodAlias]
public static int Collect(this ICakeContext context, ICollectArgs collectArgs, ILogArgs log = null)
{
return CSApi.Collect(collectArgs, MakeLog(context, log));
}

[CakeMethodAlias]
public static string Ipmo(this ICakeContext context)
{
return CSApi.Ipmo();
}
[CakeMethodAlias]
public static string Ipmo(this ICakeContext context)
{
if (context == null) throw new System.ArgumentNullException(nameof(context));
return CSApi.Ipmo();
}

[CakeMethodAlias]
public static string Version(this ICakeContext context)
{
return CSApi.Version();
}
[CakeMethodAlias]
public static string Version(this ICakeContext context)
{
if (context == null) throw new System.ArgumentNullException(nameof(context));
return CSApi.Version();
}
}
}
97 changes: 52 additions & 45 deletions AltCover.Cake/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,67 @@

namespace AltCover.Cake
{
public class AltCoverSettings
{
public IPrepareArgs PreparationPhase { get; set; }
public ICollectArgs CollectionPhase { get; set; }
public class AltCoverSettings
{
public IPrepareArgs PreparationPhase { get; set; }
public ICollectArgs CollectionPhase { get; set; }
public ICLIArg Control { get; set; }

public Func<ProcessArgumentBuilder, ProcessArgumentBuilder> Customize()
{
public Func<ProcessArgumentBuilder, ProcessArgumentBuilder> Customize()
{
return pabIn =>
{
var pabOut = new ProcessArgumentBuilder();
if (pabIn != null)
var pabOut = new ProcessArgumentBuilder();
if (pabIn != null)
{
pabIn.CopyTo(pabOut);
}
var args = CSApi.ToTestArgumentList(
this.PreparationPhase,
this.CollectionPhase,
this.Control);
Array.Reverse(args);
Array.ForEach(
args,
t => pabOut.Prepend(t));
return pabOut;
};
}

public Func<ProcessArgumentBuilder, ProcessArgumentBuilder> Concatenate(Func<ProcessArgumentBuilder, ProcessArgumentBuilder> customIn)
{
pabIn.CopyTo(pabOut);
var altcover = Customize();
if (customIn == null)
{
return altcover;
}
else
{
return args => altcover(customIn(args));
}
}
var args = CSApi.ToTestArgumentList(
this.PreparationPhase,
this.CollectionPhase,
this.Control);
Array.Reverse(args);
Array.ForEach(
args,
t => pabOut.Prepend(t));
return pabOut;
};
}

public Func<ProcessArgumentBuilder, ProcessArgumentBuilder> Concatenate(Func<ProcessArgumentBuilder, ProcessArgumentBuilder> customIn)
[CakeAliasCategory("DotNetCore")]
public static class DotNet
{
var altcover = Customize();
if (customIn == null)
{
return altcover;
}
else
{
return args => altcover(customIn(args));
}
}
}
[CakeMethodAlias]
[CakeAliasCategory("Test")]
[System.Diagnostics.CodeAnalysis.SuppressMessage(
"Gendarme.Rules.Maintainability", "AvoidUnnecessarySpecializationRule",
Justification = "AvoidSpeculativeGenerality too")]
public static void DotNetCoreTest(
this ICakeContext context,
FilePath project,
DotNetCoreTestSettings settings,
AltCoverSettings altcover)
{
if (project == null) throw new ArgumentNullException(nameof(project));
if (settings == null) throw new ArgumentNullException(nameof(settings));
if (altcover == null) throw new ArgumentNullException(nameof(altcover));

[CakeAliasCategory("DotNetCore")]
public static class DotNet
{
[CakeMethodAlias]
[CakeAliasCategory("Test")]
public static void DotNetCoreTest(
this ICakeContext context,
FilePath project,
DotNetCoreTestSettings settings,
AltCoverSettings altcover)
{
settings.ArgumentCustomization = altcover.Concatenate(settings.ArgumentCustomization);
context.DotNetCoreTest(project.FullPath, settings);
settings.ArgumentCustomization = altcover.Concatenate(settings.ArgumentCustomization);
context.DotNetCoreTest(project.GetFilename().FullPath, settings);
}
}
}
}
1 change: 1 addition & 0 deletions AltCover.Cake/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCulture("")]
[assembly: System.CLSCompliant(true)]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
Expand Down
1 change: 1 addition & 0 deletions AltCover.Cake/altcover.cake.core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<ContinuousIntegrationBuild Condition="'$(APPVEYOR)'=='True'">true</ContinuousIntegrationBuild>
<DeterministicSourcePaths Condition="'$(APPVEYOR)'=='True'">true</DeterministicSourcePaths>
<SolutionDir Condition="'$(AltCoverGendarme)' == 'true'">$(ProjectDir)../</SolutionDir>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
9 changes: 6 additions & 3 deletions AltCover.FSApi/CoverageFormats.fs
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,17 @@ module CoverageFormats =
transform.Transform(navigable, output)
XmlUtilities.PrependDeclaration rewrite

rewrite.SelectNodes("//method").OfType<XmlElement>()
use methods = rewrite.SelectNodes("//method")
methods.OfType<XmlElement>()
|> Seq.iter (fun m ->
let c = m.GetAttribute("class")
m.SetAttribute("class", c.Replace('/', '+'))
let name = m.GetAttribute("name")
let lead = name.Substring(name.LastIndexOf("::", StringComparison.Ordinal) + 2)
m.SetAttribute("name", lead.Substring(0, lead.IndexOf('('))))

rewrite.SelectNodes("//module").OfType<XmlElement>()
use modules = rewrite.SelectNodes("//module")
modules.OfType<XmlElement>()
|> Seq.iter (fun m ->
let path = m.GetAttribute("name")
let info = System.IO.FileInfo path
Expand All @@ -137,7 +139,8 @@ module CoverageFormats =
let culture = System.Threading.Thread.CurrentThread.CurrentCulture
try
System.Threading.Thread.CurrentThread.CurrentCulture <- CultureInfo.InvariantCulture
rewrite.SelectNodes("//coverage").OfType<XmlElement>()
use coverage = rewrite.SelectNodes("//coverage")
coverage.OfType<XmlElement>()
|> Seq.iter (fun c ->
let now =
DateTime.UtcNow.ToLongDateString() + ":" + DateTime.UtcNow.ToLongTimeString()
Expand Down
2 changes: 1 addition & 1 deletion AltCover.FSApi/Definitions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module DotNet =
[<NoComparison; SuppressMessage("Microsoft.Design", "CA1034",
Justification = "Idiomatic F#");
SuppressMessage("Gendarme.Rules.Smells",
"AvoidCodeDuplicatedInSameClassRule",
"RelaxedAvoidCodeDuplicatedInSameClassRule",
Justification = "Idiomatic F#") >]
type CLIArgs =
| Force of bool
Expand Down
12 changes: 8 additions & 4 deletions AltCover.FSApi/OpenCover.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ open System.Xml.XPath
module OpenCoverUtilities =

let private CompressMethod withinSequencePoint sameSpan (m : XmlElement) =
let sp = m.GetElementsByTagName("SequencePoint").OfType<XmlElement>() |> Seq.toList
let bp = m.GetElementsByTagName("BranchPoint").OfType<XmlElement>() |> Seq.toList
use sp0 = m.GetElementsByTagName("SequencePoint")
let sp = sp0.OfType<XmlElement>() |> Seq.toList
use bp0 =m.GetElementsByTagName("BranchPoint")
let bp = bp0.OfType<XmlElement>() |> Seq.toList
if sp
|> List.isEmpty
|> not
Expand Down Expand Up @@ -108,11 +110,13 @@ module OpenCoverUtilities =
let CompressBranching (navigable : IXPathNavigable) withinSequencePoint sameSpan =
// Validate
let xmlDocument = new XmlDocument()
navigable.CreateNavigator().ReadSubtree() |> xmlDocument.Load
use reader = navigable.CreateNavigator().ReadSubtree()
reader |> xmlDocument.Load
xmlDocument.Schemas <- XmlUtilities.LoadSchema AltCover.Base.ReportFormat.OpenCover
xmlDocument.Validate(null)
// Get all the methods
xmlDocument.SelectNodes("//Method")
use methods = xmlDocument.SelectNodes("//Method")
methods
|> Seq.cast<XmlElement>
|> Seq.iter (CompressMethod withinSequencePoint sameSpan)
// tidy up here
Expand Down
3 changes: 2 additions & 1 deletion AltCover.FSApi/Xhtml.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ module Xhtml =
do use output = rewrite.CreateNavigator().AppendChild()
transform.Transform(intermediate, output)

rewrite.DocumentElement.SelectNodes("//script[@language='JavaScript']").OfType<XmlNode>
use scripts = rewrite.DocumentElement.SelectNodes("//script[@language='JavaScript']")
scripts.OfType<XmlNode>
()
|> Seq.iter (fun n ->
let text = n.InnerText
Expand Down
Loading

0 comments on commit 49dcb64

Please sign in to comment.