Skip to content

Commit

Permalink
Merge pull request #1990 from baronfel/executable_scripts
Browse files Browse the repository at this point in the history
WIP fix for shell script executable bit and scaffolding for template tests
  • Loading branch information
matthid authored Jun 11, 2018
2 parents 4ec9191 + db9327e commit 8064d42
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Fake.sln
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "template", "template", "{87
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "fake-template", "src\template\fake-template\fake-template.fsproj", "{29B66A06-1A45-4D65-AC31-7D746449E5D6}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fake.DotNet.Cli.IntegrationTests", "src\test\Fake.DotNet.Cli.IntegrationTests\Fake.DotNet.Cli.IntegrationTests.fsproj", "{48ECC58D-468C-4D44-98B3-854C21EB0D40}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -944,6 +946,18 @@ Global
{29B66A06-1A45-4D65-AC31-7D746449E5D6}.Release|x64.Build.0 = Release|Any CPU
{29B66A06-1A45-4D65-AC31-7D746449E5D6}.Release|x86.ActiveCfg = Release|Any CPU
{29B66A06-1A45-4D65-AC31-7D746449E5D6}.Release|x86.Build.0 = Release|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Debug|x64.ActiveCfg = Debug|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Debug|x64.Build.0 = Debug|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Debug|x86.ActiveCfg = Debug|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Debug|x86.Build.0 = Debug|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Release|Any CPU.Build.0 = Release|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Release|x64.ActiveCfg = Release|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Release|x64.Build.0 = Release|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Release|x86.ActiveCfg = Release|Any CPU
{48ECC58D-468C-4D44-98B3-854C21EB0D40}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1016,6 +1030,7 @@ Global
{9E26B2AE-856A-42B6-9670-8766919F7D25} = {901F162F-8925-4390-89C5-9EE2C343F744}
{872B282D-8A3E-459A-B63D-C43C5D73506D} = {539D7B9A-18A1-4D79-86AB-C8B48090CA84}
{29B66A06-1A45-4D65-AC31-7D746449E5D6} = {872B282D-8A3E-459A-B63D-C43C5D73506D}
{48ECC58D-468C-4D44-98B3-854C21EB0D40} = {E09B72E4-D890-46A8-8D14-7367C2E23E9D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {058A0C5E-2216-4306-8AFB-0AE28320C26A}
Expand Down
6 changes: 6 additions & 0 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,11 @@ Target.create "DotNetCoreIntegrationTests" (fun _ ->
if processResult.ExitCode <> 0 then failwithf "DotNet Core Integration tests failed."
)

Target.create "TemplateIntegrationTests" (fun _ ->
let processResult =
DotNet.exec (dtntWorkDir (srcDir </> "test" </> "Fake.DotNet.Cli.IntegrationTests")) "bin/Release/netcoreapp2.1/Fake.DotNet.Cli.IntegrationTests.dll" "--summary"
if processResult.ExitCode <> 0 then failwithf "DotNet CLI Template Integration tests failed."
)

Target.create "DotNetCoreUnitTests" (fun _ ->
// dotnet run -p src/test/Fake.Core.UnitTests/Fake.Core.UnitTests.fsproj
Expand Down Expand Up @@ -1536,6 +1541,7 @@ let prevDocs =
==> "RunTests"

"DotNetPackage"
==> "TemplateIntegrationTests"
==> "DotNetCoreCreateZipPackages"
==> "FullDotNetCore"
==> "Default"
Expand Down
14 changes: 14 additions & 0 deletions src/template/fake-template/Content/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,19 @@
"condition": "(dependencies != \"file\")"
}
]
}],
"postActions": [{
"condition": "(OS != \"Windows_NT\")",
"description": "Make scripts executable",
"manualInstructions": [{
"text": "Run 'chmod +x *.sh'"
}],
"actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2",
"args": {
"executable": "/bin/sh",
"args": "-c \"chmod +x *.sh\""

},
"continueOnError": false
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\app\Fake.DotNet.Cli\Fake.DotNet.Cli.fsproj" />
<ProjectReference Include="..\..\app\Fake.IO.FileSystem\Fake.IO.FileSystem.fsproj" />
<ProjectReference Include="..\..\app\Fake.Core.Process\Fake.Core.Process.fsproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="TemplateTests.fs" />
<Compile Include="Main.fs" />
<None Include="paket.references" />
</ItemGroup>
<Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>
6 changes: 6 additions & 0 deletions src/test/Fake.DotNet.Cli.IntegrationTests/Main.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Main.Tests
open Expecto

[<EntryPoint>]
let main argv =
Tests.runTestsInAssembly { defaultConfig with parallel = false } argv
99 changes: 99 additions & 0 deletions src/test/Fake.DotNet.Cli.IntegrationTests/TemplateTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module Fake.DotNet.Cli.IntegrationTests.TemplateTests

open Expecto
open System
open System.IO

open Fake.Core
open Fake.DotNet
open Fake.IO
open Fake.IO.Globbing

let templateProj = "fake-template.fsproj"
let templatePackageName = "fake-template"
let templateName = "fake"

//TODO: add DotNetCli helpers for the `new` command

let uninstallTemplate () =
DotNet.exec id "new" (sprintf "-u %s" templatePackageName)

let installTemplateFrom pathToNupkg =
DotNet.exec id "new" (sprintf "-i %s" pathToNupkg)

type BootstrapKind =
| Tool
| Project
| None
with override x.ToString () = match x with | Tool -> "tool" | Project -> "project" | None -> "none"

let shouldSucceed message (r: ProcessResult) =
Expect.isTrue r.OK (sprintf "%s. Results:\n:%A" message r)

let runTemplate rootDir kind =
Directory.ensure rootDir
let dotnet = DotNet.Options.Create().DotNetCliPath
Process.execWithResult (fun p ->
p.WithWorkingDirectory(rootDir)
.WithFileName(dotnet)
.WithArguments(sprintf "new %s --allow-scripts yes --bootstrap %s" templateName (string kind))) (System.TimeSpan.FromSeconds 60.)
|> shouldSucceed "should have run the template successfully"

let invokeScript dir scriptName args =
let fullScriptPath = Path.Combine(dir, scriptName)
Process.execWithResult
(fun x ->
x.WithWorkingDirectory(dir)
.WithFileName(fullScriptPath)
.WithArguments args ) (System.TimeSpan.FromSeconds 60.)

let missingTarget targetName (r: ProcessResult) =
r.Errors |> Seq.exists (fun err -> err.Contains (sprintf "Target \"%s\" is not defined" targetName))

[<Tests>]
let tests =
// we need to (uninstall) the template, install the packed version, and then execute that template
testList "Fake.DotNet.Cli.IntegrationTests.Template tests" [
testList "can install and run the template" [
uninstallTemplate () |> shouldSucceed "should clear out preexisting templates"
printfn "%s" Environment.CurrentDirectory
let templateNupkg = GlobbingPattern.create "../../../nuget/dotnetcore/fake-template.*.nupkg" |> GlobbingPattern.setBaseDir __SOURCE_DIRECTORY__ |> Seq.head
installTemplateFrom templateNupkg |> shouldSucceed "should install new FAKE template"

let scriptFile =
if Environment.isUnix
then "fake.sh"
else "fake.cmd"

yield test "can install a project-style template" {
let tempDir = Path.Combine(Path.GetTempPath (), Path.GetRandomFileName())
Directory.ensure tempDir
runTemplate tempDir Project
invokeScript tempDir scriptFile "--help" |> shouldSucceed "should invoke help"
}

yield test "can build with the project-style template" {
let tempDir = Path.Combine(Path.GetTempPath (), Path.GetRandomFileName())
Directory.ensure tempDir
runTemplate tempDir Project
invokeScript tempDir scriptFile "build -t All" |> shouldSucceed "should build successfully"
}

yield test "fails to build a target that doesn't exist" {
let tempDir = Path.Combine(Path.GetTempPath (), Path.GetRandomFileName())
Directory.ensure tempDir
runTemplate tempDir Project
let result = invokeScript tempDir scriptFile "build -t Nonexistent"
Expect.isFalse result.OK "the script should have failed"
Expect.isTrue (missingTarget "Nonexistent" result) "The script should recognize the target doesn't exist"
}

/// ignored because the .net tool install to a subdirectory is broken: https://github.com/fsharp/FAKE/pull/1989#issuecomment-396057330
yield ptest "can install a tool-style template" {
let tempDir = Path.Combine(Path.GetTempPath (), Path.GetRandomFileName())
Directory.ensure tempDir
runTemplate tempDir Tool
invokeScript tempDir scriptFile "--help" |> shouldSucceed "should invoke help"
}
]
]
5 changes: 5 additions & 0 deletions src/test/Fake.DotNet.Cli.IntegrationTests/paket.references
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
group netcore

FSharp.Core
NETStandard.Library
Expecto

0 comments on commit 8064d42

Please sign in to comment.