From 369adb2c1d84c49eb7504a2003191bf11bc98ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Derriey?= Date: Thu, 1 Sep 2016 17:48:12 +1000 Subject: [PATCH] rewrite LINQPad samples functionality in F#. fixes #1081 --- .gitignore | 1 + build.cmd | 1 + build.fsx | 76 ++++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 65 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index cd85843f..5d538ca2 100644 --- a/.gitignore +++ b/.gitignore @@ -76,6 +76,7 @@ tools/FAKE.Core tools/SourceLink.Fake tools/xunit.runner.console tools/Octokit.CodeFormatter +tools/FSharp.Data *.ncrunch* *.GhostDoc.xml diff --git a/build.cmd b/build.cmd index 02d0835e..dfefcfd4 100644 --- a/build.cmd +++ b/build.cmd @@ -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 diff --git a/build.fsx b/build.fsx index a032c94f..89e42723 100644 --- a/build.fsx +++ b/build.fsx @@ -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"] @@ -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<""" + + Octokit + Octokit.Reactive + Rx-Main + Octokit + System.Reactive.Linq + System.Threading.Tasks + +"""> + +Target "ValidateLINQPadSamples" (fun _ -> + + let splitFileContents = fun (file: FileInfo) -> + let content = File.ReadAllText(file.FullName) + let closeTag = "" + let openTagIndex = content.IndexOf("") + 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 _ ->