Skip to content

Commit

Permalink
rewrite LINQPad samples functionality in F#. fixes octokit#1081
Browse files Browse the repository at this point in the history
  • Loading branch information
mderriey committed Sep 1, 2016
1 parent 4808941 commit 369adb2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ tools/FAKE.Core
tools/SourceLink.Fake
tools/xunit.runner.console
tools/Octokit.CodeFormatter
tools/FSharp.Data
*.ncrunch*
*.GhostDoc.xml

Expand Down
1 change: 1 addition & 0 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"tools\nuget\nuget.exe" "install" "FAKE.Core" "-OutputDirectory" "tools" "-ExcludeVersion" "-version" "4.28.0" -verbosity quiet
"tools\nuget\nuget.exe" "install" "SourceLink.Fake" "-OutputDirectory" "tools" "-ExcludeVersion" "-version" "1.1.0" -verbosity quiet
"tools\nuget\nuget.exe" "install" "Octokit.CodeFormatter" "-OutputDirectory" "tools" "-ExcludeVersion" "-version" "1.0.0-preview" -Pre -verbosity quiet
"tools\nuget\nuget.exe" "install" "FSharp.Data" "-OutputDirectory" "tools" "-ExcludeVersion" "-version" "2.3.2" -verbosity quiet

:Build
cls
Expand Down
76 changes: 63 additions & 13 deletions build.fsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#r @"tools/FAKE.Core/tools/FakeLib.dll"
#r @"tools/FSharp.Data/lib/net40/FSharp.Data.dll"
#r "System.Xml.Linq"
#load "tools/SourceLink.Fake/tools/SourceLink.fsx"
open Fake
open System
open System.IO
open SourceLink
open FSharp.Data

let authors = ["GitHub"]

Expand Down Expand Up @@ -148,19 +152,65 @@ Target "SourceLink" (fun _ ->
)
)

Target "ValidateLINQPadSamples"(fun _ ->
"The current LINQPad snippets reference the latest release of Octokit on NuGet, which may be very far behind what is currently on master. " +
"These tests have been ported to SelfTests in the integration test suite. If someone would like to port them to F#, have a read of the details in https://github.com/octokit/octokit.net/issues/1081."
|> traceImportant
// directoryInfo(samplesDir @@ "linqpad-samples")
// |> filesInDir
// |> Array.map(fun f -> f.FullName)
// |> Seq.iter (fun sample ->
// let result = ExecProcess (fun info ->
// info.FileName <- linqPadDir @@ "lprun.exe"
// info.Arguments <- " -compileonly " + sample) (TimeSpan.FromMinutes 5.0)
// if result <> 0 then failwithf "lprun.exe returned with a non-zero exit code for %s" sample
// )
type LinqPadSampleMetadata = XmlProvider<"""
<Query Kind="Program">
<NuGetReference>Octokit</NuGetReference>
<NuGetReference>Octokit.Reactive</NuGetReference>
<NuGetReference>Rx-Main</NuGetReference>
<Namespace>Octokit</Namespace>
<Namespace>System.Reactive.Linq</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
""">

Target "ValidateLINQPadSamples" (fun _ ->

let splitFileContents = fun (file: FileInfo) ->
let content = File.ReadAllText(file.FullName)
let closeTag = "</Query>"
let openTagIndex = content.IndexOf("<Query Kind=\"Program\">")
let closeTagIndex = content.IndexOf(closeTag)
let endOfXml = closeTagIndex + closeTag.Length
let xmlPart = content.Substring(openTagIndex, endOfXml - openTagIndex)
let rest = content.Substring(endOfXml)

(xmlPart, rest)

let createTempFile = fun(metadataString: string, rest: string) ->
let metadata = LinqPadSampleMetadata.Parse(metadataString)
let assembliesDir = buildDir @@ "Release/Net45"
let reactiveAssembliesDir = reactiveBuildDir @@ "Release/Net45"
let tempFileName = Path.GetTempFileName()
use stream = File.OpenWrite(tempFileName)
use writer = new StreamWriter(stream)

writer.WriteLine("ref {0}\\System.Reactive.Core.dll;", reactiveAssembliesDir);
writer.WriteLine("ref {0}\\System.Reactive.Interfaces.dll;", reactiveAssembliesDir);
writer.WriteLine("ref {0}\\System.Reactive.Linq.dll;", reactiveAssembliesDir);
writer.WriteLine("ref {0}\\Octokit.dll;", assembliesDir);
writer.WriteLine("ref {0}\\Octokit.Reactive.dll;", reactiveAssembliesDir);
writer.WriteLine("ref C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5\\System.Net.Http.dll;");

for metadataNamespace in metadata.Namespaces do
writer.WriteLine("using {0};", metadataNamespace)

writer.WriteLine()
writer.WriteLine(rest)

writer.Flush()

tempFileName

directoryInfo(samplesDir @@ "linqpad-samples")
|> filesInDir
|> Array.map (splitFileContents >> createTempFile)
|> Seq.iter (fun sample ->
let result = ExecProcess (fun info ->
info.FileName <- linqPadDir @@ "lprun.exe"
info.Arguments <- " -compileonly -lang=Program " + sample) (TimeSpan.FromMinutes 5.0)

if result <> 0 then failwithf "lprun.exe returned with a non-zero exit code for %s" sample
)
)

Target "CreateOctokitPackage" (fun _ ->
Expand Down

0 comments on commit 369adb2

Please sign in to comment.