Skip to content

Commit

Permalink
Move building projects to an assert
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Byrd committed Jan 23, 2020
1 parent 4ff1533 commit 420b27e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
4 changes: 4 additions & 0 deletions tests/MiniScaffold.Tests/Asserts.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace MiniScaffold.Tests
open System.IO
open Expecto
open Infrastructure

module Assert =
open System
Expand All @@ -16,6 +17,9 @@ module Assert =
|> Seq.tryFind(fun x -> x.Name = file)
|> failIfNoneWithMsg (sprintf "Could not find %s in %s" file d.FullName)

let ``project can build target`` target (d : DirectoryInfo) =
Builds.executeBuild d.FullName target

let ``.editorconfig exists`` (d : DirectoryInfo) =
tryFindFile ".editorconfig" d

Expand Down
24 changes: 24 additions & 0 deletions tests/MiniScaffold.Tests/Infrastructure.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Infrastructure



module Dotnet =
open Fake.Core
open Fake.DotNet
Expand Down Expand Up @@ -46,3 +47,26 @@ module Disposables =
interface IDisposable with
member x.Dispose() =
IO.Directory.Delete(x.Directory, true)

module Builds =
open Fake.Core
let executeBuild workingDir testTarget =
let cmd, args =
if Environment.isUnix then
"bash", [
sprintf "./build.sh"
testTarget
]
else
"cmd.exe", [
"/c"
".\\build.cmd"
testTarget
]
// printfn "running %s" cmd
let result =
CreateProcess.fromRawCommand cmd args
|> CreateProcess.withWorkingDirectory workingDir
|> CreateProcess.ensureExitCode
|> Proc.run
()
52 changes: 22 additions & 30 deletions tests/MiniScaffold.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ namespace MiniScaffold.Tests
module Tests =
open System
open Fake.Core
open Fake.DotNet
open Expecto
open Infrastructure
open Expecto.Logging
open Fake.SystemHelper

let logger = Expecto.Logging.Log.create "setup"
let nugetPkgName = "MiniScaffold"
Expand All @@ -36,55 +33,50 @@ module Tests =

Dotnet.New.uninstall nugetPkgName
Dotnet.New.install nugetPkgPath
let executeBuild workingDir testTarget =
let cmd, args =
if Environment.isUnix then
"bash", [
sprintf "./build.sh"
testTarget
]
else
"cmd.exe", [
"/c"
".\\build.cmd"
testTarget
]
// printfn "running %s" cmd
let result =
CreateProcess.fromRawCommand cmd args
|> CreateProcess.withWorkingDirectory workingDir
|> CreateProcess.ensureExitCode
|> Proc.run
()




let commonAsserts = [
Assert.``.editorconfig exists``
Assert.``.gitattributes exists``
Assert.``paket.dependencies exists``
Assert.``paket.lock exists``
]

[<Tests>]
let tests =
testSequenced <|
// testSequenced <| // uncomment to get better logs
testList "samples" [
do setup ()
yield! [
"-n MyCoolLib --githubUsername CoolPersonNo2", "DotnetPack", [yield! commonAsserts]
"-n MyCoolLib --githubUsername CoolPersonNo2", [
yield! commonAsserts
Assert.``project can build target`` "DotnetPack"
Assert.``project can build target`` "BuildDocs"
]
// test for dashes in name https://github.com/dotnet/templating/issues/1168#issuecomment-364592031
"-n fsharp-data-sample --githubUsername CoolPersonNo2", "DotnetPack", [yield! commonAsserts]
"-n MyCoolApp --githubUsername CoolPersonNo2 --outputType Console", "CreatePackages", [yield! commonAsserts]
"-n fsharp-data-sample --githubUsername CoolPersonNo2", [
yield! commonAsserts
Assert.``project can build target`` "DotnetPack"
]
"-n MyCoolApp --githubUsername CoolPersonNo2 --outputType Console", [
yield! commonAsserts
Assert.``project can build target`` "CreatePackages"
]

] |> Seq.map(fun (args,target, additionalAsserts) -> testCase args <| fun _ ->
] |> Seq.map(fun (args, additionalAsserts) -> testCase args <| fun _ ->
use d = Disposables.DisposableDirectory.Create()
let newArgs = [
sprintf "mini-scaffold -lang F# %s" args
]
Dotnet.New.cmd (fun opt -> { opt with WorkingDirectory = d.Directory}) newArgs

// The project we just generated is the only one in here
let projectDir =
d.DirectoryInfo.GetDirectories ()
|> Seq.head

executeBuild projectDir.FullName target

additionalAsserts
|> Seq.iter(fun asserter -> asserter projectDir)
)
Expand Down

0 comments on commit 420b27e

Please sign in to comment.