-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1990 from baronfel/executable_scripts
WIP fix for shell script executable bit and scaffolding for template tests
- Loading branch information
Showing
7 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/test/Fake.DotNet.Cli.IntegrationTests/Fake.DotNet.Cli.IntegrationTests.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
99
src/test/Fake.DotNet.Cli.IntegrationTests/TemplateTests.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
group netcore | ||
|
||
FSharp.Core | ||
NETStandard.Library | ||
Expecto |