Created
July 19, 2016 18:21
-
-
Save bj0/300e74728aa75d613068d5e90528ce42 to your computer and use it in GitHub Desktop.
A python script that downloads nuget and installs FAKE and Xunit test runner. It also creates a script for running tests.
This file contains hidden or 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
#!python | |
import os | |
import subprocess as sp | |
__build = \ | |
''' | |
// include Fake lib | |
#r @"tools/FAKE/tools/FakeLib.dll" | |
open Fake | |
open Fake.Testing | |
open Fake.NuGet.Install | |
let testDir = "{}.Tests/bin/Debug" | |
let inline getBuildOption name = match environVar name with | |
| null -> None | |
| s -> Some s | |
let runTests() = | |
!! (testDir + "/*.Tests.dll") | |
|> xUnit2 (fun p -> {{ p with | |
ToolPath = findToolInSubPath "xunit.console.x86.exe" (currentDirectory @@ "tools" @@ "xUnit") | |
Method = getBuildOption "method" | |
}} ) | |
// Default target | |
Target "RunTests" (fun _ -> | |
runTests() | |
) | |
// continuous test runner | |
Target "Watch" (fun _-> | |
use watcher = !! (testDir + "/*.dll") |> WatchChanges (fun changes -> | |
tracefn "%A" changes | |
runTests() | |
) | |
System.Console.ReadLine() |> ignore | |
watcher.Dispose() | |
) | |
// install test runner | |
Target "Setup" (fun _ -> | |
NugetInstall (fun p -> {{ p with | |
ExcludeVersion = true | |
OutputDirectory = "tools" | |
}} ) "xunit.runner.console" | |
) | |
// start build | |
RunTargetOrDefault "RunTests" | |
''' | |
def get_nuget(): | |
path = r'c:/bin/nuget.exe' | |
if os.path.exists(path): | |
print('using global nuget...') | |
return path | |
path = r'./tools/nuget.exe' | |
if os.path.exists(path): | |
print('using local nuget...') | |
return path | |
if not os.path.exists('./tools'): | |
print('creating tools directory') | |
os.makedirs('./tools') | |
cmd = r'powershell -Command "Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile .\tools\nuget.exe"' | |
print('downloading nuget...') | |
output = sp.check_output(cmd) | |
print(output) | |
return path | |
def install_fake(nuget): | |
print('installing fake...') | |
output = sp.check_output('"{}" "Install" "FAKE" "-OutputDirectory" "tools" "-ExcludeVersion"'.format(nuget)) | |
print(output) | |
def install_xunit(): | |
print('installing xunit runner...') | |
output = sp.check_output('./tools/FAKE/tools/fake.exe setup') | |
print(output) | |
def generate_build(name): | |
if not os.path.exists('build.fsx'): | |
print('creating build.fsx...') | |
with open('build.fsx', 'wt') as f: | |
f.write(__build.format(name)) | |
else: | |
print('build.fsx already exists!') | |
if __name__ == '__main__': | |
nuget = get_nuget() | |
install_fake(nuget) | |
name = os.path.basename(os.getcwd()) | |
print('project name: {}'.format(name)) | |
generate_build(name) | |
install_xunit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment