Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP fix for shell script executable bit and scaffolding for template tests #1990

Merged
merged 6 commits into from
Jun 11, 2018
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
98 changes: 98 additions & 0 deletions src/test/Fake.DotNet.Cli.IntegrationTests/TemplateTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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"
let templateNupkg = GlobbingPattern.create "../../template/fake-template/bin/Release/fake-template.*.nupkg" |> 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