Skip to content

Instantly share code, notes, and snippets.

@hafuu
Last active June 25, 2018 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hafuu/ea5b0140d01beb97f10ed20079cdcf72 to your computer and use it in GitHub Desktop.
Save hafuu/ea5b0140d01beb97f10ed20079cdcf72 to your computer and use it in GitHub Desktop.
fake.testing.persimmon.fsx の試作
namespace Fake.Testing
#if !FAKE
#load "../../../../.fake/build.fsx/intellisense.fsx"
#r "netstandard"
#endif
[<RequireQualifiedAccess>]
module Persimmon =
open System
open System.IO
open System.Text
open Fake.Core
open Fake.Testing.Common
open Fake.IO.Globbing
open Fake.IO.FileSystemOperators
type OutputDestination =
| Console
| PlaneTextFile of path: string
| XmlFile of path: string
type ErrorOutputDestination =
| Console
| File of path: string
type PersimmonParams = {
ToolPath: string
NoProgress: bool
Parallel: bool
Output: OutputDestination
Error: ErrorOutputDestination
TimeOut : TimeSpan
ErrorLevel: TestRunnerErrorLevel
}
let PersimmonDefaults = {
ToolPath = Tools.findToolInSubPath "Persimmon.Console.exe" (Directory.GetCurrentDirectory() @@ "tools" @@ "Persimmon.Console")
NoProgress = false
Parallel = false
Output = OutputDestination.Console
Error = Console
TimeOut = TimeSpan.FromMinutes 5.
ErrorLevel = Error
}
let buildPersimmonArgs parameters assemblies =
let output, outputText =
match parameters.Output with
| OutputDestination.Console -> false, ""
| PlaneTextFile path -> (true, sprintf "--output:%s" <| path.TrimEnd Path.DirectorySeparatorChar)
| XmlFile path -> (true, sprintf "\"--output:%s\" --format:xml" <| path.TrimEnd Path.DirectorySeparatorChar)
let error, errorText =
match parameters.Error with
| Console -> false, ""
| File path -> (true, sprintf "--error:%s" <| path.TrimEnd Path.DirectorySeparatorChar)
StringBuilder()
|> StringBuilder.appendIfTrueWithoutQuotes output outputText
|> StringBuilder.appendIfTrue error errorText
|> StringBuilder.appendIfTrue parameters.NoProgress "--no-progress"
|> StringBuilder.appendIfTrue parameters.Parallel "--parallel"
|> StringBuilder.appendFileNamesIfNotNull assemblies
|> StringBuilder.toText
let run setParams assemblies =
let details = String.separated ", " assemblies
use __ = Trace.traceTask "Persimmon" details
let parameters = setParams PersimmonDefaults
let args = buildPersimmonArgs parameters assemblies
Trace.trace (parameters.ToolPath + " " + args)
let processResult =
Process.execSimple (fun info ->
{ info with
FileName = parameters.ToolPath
Arguments = args}) parameters.TimeOut
if 0 <> processResult then
let message = sprintf "Persimmon test failed on %s." details
match parameters.ErrorLevel with
| Error | FailOnFirstError -> raise (FailedTestsException(message))
| DontFailBuild -> Trace.traceImportant message
__.MarkSuccess()
framework: netstandard2.0
source https://nuget.org/api/v2
nuget Fake.Core.Process
nuget Fake.Core.String
nuget Fake.Core.Trace
nuget Fake.Testing.Common
nuget FSharp.Core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment