Skip to content

Commit

Permalink
C# API + modifications all over for Issue #46
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Dec 22, 2018
1 parent 33da3d3 commit e06cbd0
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 47 deletions.
103 changes: 86 additions & 17 deletions AltCover.CSApi/Definitions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,70 @@
using System;
using System.Linq;

namespace AltCover
namespace AltCover.Parameters
{
public class CollectArgs
public interface ICollectArgs
{
string RecorderDirectory { get; }
string WorkingDirectory { get; }
string Executable { get; }
string LcovReport { get; }
string Threshold { get; }
string Cobertura { get; }
string OutputFile { get; }
string[] CommandLine { get; }

FSApi.CollectParams ToParameters();

string[] Validate(bool afterPreparation);
}

public interface IPrepareArgs
{
string InputDirectory { get; }
string OutputDirectory { get; }
string[] SymbolDirectories { get; }
string[] Dependencies { get; }
string[] Keys { get; }
string StrongNameKey { get; }
string XmlReport { get; }
string[] FileFilter { get; }
string[] AssemblyFilter { get; }
string[] AssemblyExcludeFilter { get; }
string[] TypeFilter { get; }
string[] MethodFilter { get; }
string[] AttributeFilter { get; }
string[] PathFilter { get; }
string[] CallContext { get; }

bool OpenCover { get; }
bool InPlace { get; }
bool Save { get; }
bool Single { get; }
bool LineCover { get; }
bool BranchCover { get; }

string[] CommandLine { get; }

FSApi.PrepareParams ToParameters();

string[] Validate();
}

public interface ILogArgs
{
Action<String> Info { get; }
Action<String> Warn { get; }
Action<String> Error { get; }
Action<String> Echo { get; }

Logging ToParameters();
}
}

namespace AltCover.Parameters.Primitive
{
public class CollectArgs : ICollectArgs
{
public string RecorderDirectory { get; set; }
public string WorkingDirectory { get; set; }
Expand All @@ -14,9 +75,9 @@ public class CollectArgs
public string OutputFile { get; set; }
public string[] CommandLine { get; set; }

internal FSApi.CollectParams ToParameters()
public FSApi.CollectParams ToParameters()
{
var primitive = new Primitive.CollectParams(
var primitive = new AltCover.Primitive.CollectParams(
RecorderDirectory,
WorkingDirectory,
Executable,
Expand Down Expand Up @@ -53,7 +114,7 @@ public string[] Validate(bool afterPreparation)
}
}

public class PrepareArgs
public class PrepareArgs : IPrepareArgs
{
public string InputDirectory { get; set; }
public string OutputDirectory { get; set; }
Expand All @@ -80,9 +141,9 @@ public class PrepareArgs

public string[] CommandLine { get; set; }

internal FSApi.PrepareParams ToParameters()
public FSApi.PrepareParams ToParameters()
{
var primitive = new Primitive.PrepareParams(
var primitive = new AltCover.Primitive.PrepareParams(
InputDirectory,
OutputDirectory,
SymbolDirectories,
Expand Down Expand Up @@ -149,14 +210,14 @@ public string[] Validate()
}
}

public class LogArgs
public class LogArgs : ILogArgs
{
public Action<String> Info { get; set; }
public Action<String> Warn { get; set; }
public Action<String> Error { get; set; }
public Action<String> Echo { get; set; }

internal Logging ToParameters()
public Logging ToParameters()
{
return new Logging(
Logging.ActionAdapter(Info),
Expand All @@ -179,15 +240,20 @@ public static LogArgs Default
}
}
}
}

namespace AltCover
{
using AltCover.Parameters;

public static class CSApi
{
public static int Prepare(PrepareArgs p, LogArgs l)
public static int Prepare(IPrepareArgs p, ILogArgs l)
{
return Api.Prepare(p.ToParameters(), l.ToParameters());
}

public static int Collect(CollectArgs c, LogArgs l)
public static int Collect(ICollectArgs c, ILogArgs l)
{
return Api.Collect(c.ToParameters(), l.ToParameters());
}
Expand All @@ -202,16 +268,19 @@ public static string Version()
return Api.Version();
}

public static string ToTestArguments(PrepareArgs p,
CollectArgs c)
public static string ToTestArguments(IPrepareArgs p,
ICollectArgs c,
bool force)
{
return DotNet.ToTestArguments(p.ToParameters(), c.ToParameters());
return DotNet.ToTestArguments(p.ToParameters(), c.ToParameters(), force);
}

public static string[] ToTestArgumentList(PrepareArgs p,
CollectArgs c)
public static string[] ToTestArgumentList(IPrepareArgs p,
ICollectArgs c,
bool force)
{
return DotNet.ToTestArgumentList(p.ToParameters(), c.ToParameters()).ToArray();
return DotNet.ToTestArgumentList(p.ToParameters(), c.ToParameters(), force).
ToArray();
}
}
}
8 changes: 5 additions & 3 deletions AltCover.Cake/Cake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
using Cake.Core.Annotations;
using LogLevel = Cake.Core.Diagnostics.LogLevel;
using Verbosity = Cake.Core.Diagnostics.Verbosity;
using AltCover.Parameters;
using AltCover.Parameters.Primitive;

namespace AltCover.Cake
{
public static class Api
{
private static LogArgs MakeLog(ICakeContext context, LogArgs l)
private static ILogArgs MakeLog(ICakeContext context, ILogArgs l)
{
if (l != null)
return l;
Expand All @@ -31,13 +33,13 @@ private static LogArgs MakeLog(ICakeContext context, LogArgs l)
}

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

[CakeMethodAlias]
public static int Collect(this ICakeContext context, CollectArgs c, LogArgs l = null)
public static int Collect(this ICakeContext context, ICollectArgs c, ILogArgs l = null)
{
return CSApi.Collect(c, MakeLog(context, l));
}
Expand Down
11 changes: 8 additions & 3 deletions AltCover.Cake/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using Cake.Core.IO;
using System;
using System.Linq;
using AltCover.Parameters;

namespace AltCover.Cake
{
public class AltCoverSettings
{
public PrepareArgs PreparationPhase { get; set; }
public CollectArgs CollectionPhase { get; set; }
public IPrepareArgs PreparationPhase { get; set; }
public ICollectArgs CollectionPhase { get; set; }
public bool Force { get; set; }
}

[CakeAliasCategory("DotNetCore")]
Expand All @@ -37,7 +39,10 @@ private static ProcessArgumentBuilder ProcessArguments(
AltCoverSettings altcover)
{
Array.ForEach(
CSApi.ToTestArgumentList(altcover.PreparationPhase, altcover.CollectionPhase),
CSApi.ToTestArgumentList(
altcover.PreparationPhase,
altcover.CollectionPhase,
altcover.Force),
t => builder.Append(t));
return builder;
}
Expand Down
17 changes: 11 additions & 6 deletions AltCover.FSApi/Definitions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ module DotNet =
#if RUNNER
let ToTestArgumentList
(prepare : AltCover.FSApi.PrepareParams)
(collect : AltCover.FSApi.CollectParams) =
(collect : AltCover.FSApi.CollectParams)
(force : bool) =
#else
let ToTestArgumentList
(prepare : AltCover_Fake.DotNet.Testing.AltCover.PrepareParams)
(collect : AltCover_Fake.DotNet.Testing.AltCover.CollectParams) =
(collect : AltCover_Fake.DotNet.Testing.AltCover.CollectParams)
(force : bool) =
#endif

[ FromArg String.Empty "true"
Expand All @@ -52,17 +54,20 @@ module DotNet =
FromArg "Cobertura" collect.Cobertura
FromArg "Threshold" collect.Threshold
(Arg "LineCover" "true", prepare.LineCover)
(Arg "BranchCover" "true", prepare.BranchCover) ]
(Arg "BranchCover" "true", prepare.BranchCover)
(Arg "Force" "true", force)]
|> List.filter snd
|> List.map fst

#if RUNNER
let ToTestArguments
(prepare : AltCover.FSApi.PrepareParams)
(collect : AltCover.FSApi.CollectParams) =
(collect : AltCover.FSApi.CollectParams)
(force : bool) =
#else
let ToTestArguments
(prepare : AltCover_Fake.DotNet.Testing.AltCover.PrepareParams)
(collect : AltCover_Fake.DotNet.Testing.AltCover.CollectParams) =
(collect : AltCover_Fake.DotNet.Testing.AltCover.CollectParams)
(force : bool) =
#endif
ToTestArgumentList prepare collect |> Join
ToTestArgumentList prepare collect force |> Join
9 changes: 6 additions & 3 deletions AltCover.Fake/Fake.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ module DotNet =
result :?> DotNet.TestOptions

#if RUNNER
member self.WithParameters (prepare : PrepareParams) (collect : CollectParams) =
member self.WithParameters (prepare : PrepareParams)
(collect : CollectParams)
(force : bool) =
#else
member self.WithParameters (prepare : AltCover_Fake.DotNet.Testing.AltCover.PrepareParams)
(collect : AltCover_Fake.DotNet.Testing.AltCover.CollectParams) =
(collect : AltCover_Fake.DotNet.Testing.AltCover.CollectParams)
(force : bool) =
#endif

DotNet.ToTestArguments prepare collect |> self.ExtendCustomParams
DotNet.ToTestArguments prepare collect force |> self.ExtendCustomParams
member self.WithImportModule() = self.ExtendCustomParams "/p:AltCoverIpmo=true"
member self.WithGetVersion() = self.ExtendCustomParams "/p:AltCoverGetVersion=true"
30 changes: 15 additions & 15 deletions Build/targets.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -2755,9 +2755,9 @@ _Target "DoIt"
let collect = FSApi.CollectParams.Primitive { AltCover.Primitive.CollectParams.Create() with LcovReport = "x" }
let prepare = FSApi.PrepareParams.Primitive { AltCover.Primitive.PrepareParams.Create() with TypeFilter = [| "a"; "b" |] }
printfn "%s" (DotNet.ToTestArguments prepare collect)
printfn "%s" (DotNet.ToTestArguments prepare collect true)
let t = DotNet.TestOptions.Create().WithParameters prepare collect
let t = DotNet.TestOptions.Create().WithParameters prepare collect true
printfn "returned '%A'" t.Common.CustomParams
let p2 = { Primitive.PrepareParams.Create() with CallContext = [| "[Fact]"; "0" |]
Expand All @@ -2777,8 +2777,8 @@ _Target "DoIt"
DotNet.test
(fun to' ->
{ to'.WithCommon(setBaseOptions).WithParameters pp2 cc2 with MSBuildParams =
cliArguments })
{ to'.WithCommon(setBaseOptions).WithParameters pp2 cc2 true with MSBuildParams =
cliArguments })
"dotnettest.fsproj"
let ipmo = AltCover.Api.Ipmo().Trim().Split().[1].Trim([| '\"' |])
let command = "$ipmo = '" + ipmo + "'; Import-Module $ipmo; ConvertTo-BarChart -?"
Expand Down Expand Up @@ -2873,7 +2873,7 @@ _Target "DotnetTestIntegration" (fun _ ->
DotNet.test
(fun to' ->
(to'.WithCommon(withWorkingDirectoryVM "_DotnetTest")
.WithGetVersion().WithImportModule()).WithParameters pp1 cc0 |> withCLIArgs)
.WithGetVersion().WithImportModule()).WithParameters pp1 cc0 true |> withCLIArgs)
"dotnettest.fsproj"

let x = Path.getFullName "./_DotnetTest/coverage.xml"
Expand Down Expand Up @@ -2903,7 +2903,7 @@ _Target "DotnetTestIntegration" (fun _ ->
DotNet.test
(fun to' ->
to'.WithCommon(withWorkingDirectoryVM "_DotnetTestLineCover").WithParameters
pp2 cc0 |> withCLIArgs) ""
pp2 cc0 true |> withCLIArgs) ""

let x = Path.getFullName "./_DotnetTestLineCover/coverage.xml"

Expand Down Expand Up @@ -2943,7 +2943,7 @@ _Target "DotnetTestIntegration" (fun _ ->
DotNet.test
(fun to' ->
(to'.WithCommon(withWorkingDirectoryVM "_DotnetTestBranchCover").WithParameters
pp3 cc0) |> withCLIArgs) ""
pp3 cc0 true) |> withCLIArgs) ""

let x = Path.getFullName "./_DotnetTestBranchCover/coverage.xml"

Expand Down Expand Up @@ -2972,7 +2972,7 @@ _Target "DotnetTestIntegration" (fun _ ->
DotNet.test
(fun to' ->
(to'.WithCommon(withWorkingDirectoryVM "RegressionTesting/issue29").WithParameters
pp0 cc0) |> withCLIArgs) ""
pp0 cc0 true) |> withCLIArgs) ""

let proj = XDocument.Load "./RegressionTesting/issue37/issue37.xml"
let pack = proj.Descendants(XName.Get("PackageReference")) |> Seq.head
Expand All @@ -2989,7 +2989,7 @@ _Target "DotnetTestIntegration" (fun _ ->
(fun to' ->
{ ((to'.WithCommon
(withWorkingDirectoryVM "RegressionTesting/issue37")).WithParameters
pp4 cc0) with Configuration = DotNet.BuildConfiguration.Release } |> withCLIArgs)
pp4 cc0 true) with Configuration = DotNet.BuildConfiguration.Release } |> withCLIArgs)
""

let cover37 = XDocument.Load "./RegressionTesting/issue37/coverage.xml"
Expand Down Expand Up @@ -3030,7 +3030,7 @@ _Target "Issue20" (fun _ ->
DotNet.BuildConfiguration.Debug
NoBuild =
false }).WithParameters
pp0 cc0
pp0 cc0 true
|> withCLIArgs) ""

//let shared =
Expand Down Expand Up @@ -3084,7 +3084,7 @@ _Target "Issue23" (fun _ ->
let cc0 = AltCover.CollectParams.Primitive c0
DotNet.test (fun p ->
(({ p.WithCommon(withWorkingDirectoryVM "_Issue23") with Configuration = DotNet.BuildConfiguration.Debug
NoBuild = false }).WithParameters pp0 cc0)
NoBuild = false }).WithParameters pp0 cc0 true)
.WithImportModule().WithGetVersion()
|> withCLIArgs) ""
finally
Expand Down Expand Up @@ -3183,10 +3183,10 @@ _Target "DotnetCLIIntegration" (fun _ ->
let c0 = Primitive.CollectParams.Create()
let cc0 = AltCover.CollectParams.Primitive c0
DotNet.test (fun to' ->
{ to'.WithCommon(withWorkingDirectoryVM "_DotnetCLITest").WithParameters pp0 cc0 with Configuration =
DotNet.BuildConfiguration.Debug
NoBuild =
false }
{ to'.WithCommon(withWorkingDirectoryVM "_DotnetCLITest").WithParameters pp0 cc0 true with Configuration =
DotNet.BuildConfiguration.Debug
NoBuild =
false }
|> withCLIArgs) ""

"./_DotnetCLITest/coverage.xml"
Expand Down

0 comments on commit e06cbd0

Please sign in to comment.