Skip to content

Commit

Permalink
merged in static loading changes from ryan
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMarinos committed Nov 1, 2012
2 parents 9c54cdc + 7d4f30f commit 95159d4
Show file tree
Hide file tree
Showing 38 changed files with 309 additions and 227 deletions.
6 changes: 6 additions & 0 deletions .nuget/NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
Binary file added .nuget/NuGet.exe
Binary file not shown.
52 changes: 52 additions & 0 deletions .nuget/NuGet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
<NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
<NuGetExePath>$(NuGetToolsPath)\nuget.exe</NuGetExePath>
<PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
<PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>

<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
<PackageSources>""</PackageSources>

<!-- Enable the restore command to run before builds -->
<RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages>

<!-- Property that enables building a package from a project -->
<BuildPackage Condition="$(BuildPackage) == ''">false</BuildPackage>

<!-- Commands -->
<RestoreCommand>"$(NuGetExePath)" install "$(PackagesConfig)" -source $(PackageSources) -o "$(PackagesDir)"</RestoreCommand>
<BuildCommand>"$(NuGetExePath)" pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(RestorePackages) == 'true'">
RestorePackages;
$(BuildDependsOn);
</BuildDependsOn>

<!-- Make the build depend on restore packages -->
<BuildDependsOn Condition="$(BuildPackage) == 'true'">
$(BuildDependsOn);
BuildPackage;
</BuildDependsOn>
</PropertyGroup>

<Target Name="CheckPrerequisites">
<!-- Raise an error if we're unable to locate nuget.exe -->
<Error Condition="!Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
</Target>

<Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(RestoreCommand)"
LogStandardErrorAsError="true"
Condition="Exists('$(PackagesConfig)')" />
</Target>

<Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
<Exec Command="$(BuildCommand)"
LogStandardErrorAsError="true" />
</Target>
</Project>
10 changes: 7 additions & 3 deletions FSharpKoans.Core/FsharpKoans.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<Name>FSharpKoans.Core</Name>
<TargetFrameworkProfile>
</TargetFrameworkProfile>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -33,8 +35,10 @@
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\FSharpKoans.Core.XML</DocumentationFile>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="!Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition="(!Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')) And (Exists('$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets'))" />
<Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="(!Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')) And (!Exists('$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets')) And (Exists('$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets'))" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<ItemGroup>
<Compile Include="KoanAttribute.fs" />
<Compile Include="Helpers.fs" />
Expand Down Expand Up @@ -69,4 +73,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
1 change: 1 addition & 0 deletions FSharpKoans.Core/Helpers.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[<AutoOpenAttribute>]
module FSharpKoans.Core.Helpers

open System
open NUnit.Framework

Expand Down
8 changes: 6 additions & 2 deletions FSharpKoans.Core/KoanAttribute.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

open System

[<AttributeUsage(AttributeTargets.Method, AllowMultiple = false)>]
[<AttributeUsage(AttributeTargets.Class ||| AttributeTargets.Method, AllowMultiple = false)>]
type KoanAttribute () =
inherit Attribute()
inherit Attribute()
let mutable sortOrder = 0
member x.Sort
with get() = sortOrder
and set(v) = sortOrder <- v
17 changes: 9 additions & 8 deletions FSharpKoans.Core/KoanContainer.fs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
module FSharpKoans.Core.KoanContainer

open System
open System.IO
open System.Reflection

let findKoanMethods container =
let hasKoanAttribute (info:MethodInfo) =
info.GetCustomAttributes(typeof<KoanAttribute>, true)
|> Seq.isEmpty
|> not
container.GetType().GetMethods()
let hasKoanAttribute (info:MethodInfo) =
info.GetCustomAttributes(typeof<KoanAttribute>, true)
|> Seq.isEmpty
|> not

let findKoanMethods (container: Type) =
container.GetMethods(BindingFlags.Public ||| BindingFlags.Static)
|> Seq.filter hasKoanAttribute

let runKoans container =
let getKoanResult (m:MethodInfo) =
try
m.Invoke(container, [||]) |> ignore
m.Invoke(null, [||]) |> ignore
Success <| sprintf "%s passed" m.Name
with
| ex ->
Expand Down
2 changes: 1 addition & 1 deletion FSharpKoans.Core/KoanResult.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ module KoanResult =
let map f (x:KoanResult) =
match x with
| Success m -> Success <| f m
| Failure (m, e) -> Failure (f m, e)
| Failure (m, e) -> Failure (f m, e)
20 changes: 15 additions & 5 deletions FSharpKoans.Core/KoanRunner.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace FSharpKoans.Core

open System
open System.Collections.Generic
open System.Reflection

type KoanRunner(containers) =
let findFailureOrLastResult (values:seq<KoanResult>) =
Expand All @@ -19,16 +21,24 @@ type KoanRunner(containers) =
next
|> KoanResult.map (sprintf builderString current.Message)

let getContainerResult container =
let name = container.GetType().Name.ToString()
let getContainerResult (container: Type) =
let name = container.Name
let lineOne = sprintf "%s:" name

container
|> KoanContainer.runKoans
container |> KoanContainer.runKoans
|> Seq.scan (buildKoanResult "%s\n %s") (Success lineOne)
|> findFailureOrLastResult

new () =
let containers =
Assembly.GetCallingAssembly().GetTypes()
|> Array.map (fun t -> t, t.GetCustomAttributes(typeof<KoanAttribute>, true))
|> Array.filter (not << Seq.isEmpty << snd)
|> Array.sortBy (fun (t, attrs) -> (attrs.[0] :?> KoanAttribute).Sort)
|> Array.map fst
KoanRunner(containers)

member this.ExecuteKoans =
member this.ExecuteKoans() =
let result =
containers
|> Seq.map getContainerResult
Expand Down
16 changes: 11 additions & 5 deletions FSharpKoans.Test/FSharpKoans.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<AssemblyName>FSharpKoans.Test</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<Name>FSharpKoans.Test</Name>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -31,8 +33,10 @@
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\FSharpKoans.Test.XML</DocumentationFile>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="!Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" />
<Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition="(!Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')) And (Exists('$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets'))" />
<Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="(!Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')) And (!Exists('$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets')) And (Exists('$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets'))" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
<ItemGroup>
<Compile Include="FindingKoans.fs" />
<Compile Include="RunningKoans.fs" />
Expand All @@ -57,8 +61,10 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<ProjectReference Include="..\FSharpKoans.Core\FSharpKoans.Core.fsproj">
<Name>FSharpKoans.Core</Name>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FSharpKoans.Core\FsharpKoans.Core.fsproj">
<Name>FsharpKoans.Core</Name>
<Project>{71460aa5-7357-4f1c-99bc-54244b50b00e}</Project>
<Private>True</Private>
</ProjectReference>
Expand All @@ -70,4 +76,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
21 changes: 11 additions & 10 deletions FSharpKoans.Test/FindingKoans.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module KoansRunner.Test.FindingKoans

open FSharpKoans.Core
open FSharpKoans.Core.KoanContainer

Expand All @@ -8,11 +9,11 @@ open System.IO

type TestContainer() =
[<Koan>]
member this.Koan1 () =
static member Koan1 () =
()

[<Koan>]
member this.Koan2() =
static member Koan2() =
()

let getKoanNames container =
Expand All @@ -23,33 +24,33 @@ let getKoanNames container =

[<Test>]
let ``getting koans from a container`` () =
let koanNames = getKoanNames <| new TestContainer()
let koanNames = getKoanNames typeof<TestContainer>
let expected = [ "Koan1"; "Koan2" ]
Assert.AreEqual(expected, koanNames)

type TestContainer2() =
[<Koan>]
member this.Z () =
static member Z () =
()

[<Koan>]
member this.A () =
static member A () =
()

[<Koan>]
member this.a () =
static member a () =
()

[<Koan>]
member this._0 () =
static member _0 () =
()

[<Koan>]
member this.``0`` () =
static member ``0`` () =
()

[<Test>]
let ``Koans are returned in defined order regardless of name`` () =
let koanNames = getKoanNames <| new TestContainer2()
let koanNames = getKoanNames typeof<TestContainer2>
let expected = [ "Z"; "A"; "a"; "_0"; "0" ]
Assert.AreEqual(expected, koanNames)
Assert.AreEqual(expected, koanNames)
16 changes: 8 additions & 8 deletions FSharpKoans.Test/GettingTheWholeOutput.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,35 @@ open NUnit.Framework

type ContainerOne() =
[<Koan>]
member this.One() =
static member One() =
"FTW!"

[<Koan>]
member this.Two() =
static member Two() =
"FTW!"

[<Koan>]
member this.Three() =
static member Three() =
"FTW!"

type ContainerTwo() =
[<Koan>]
member this.Four() =
static member Four() =
"FTW!"

[<Koan>]
member this.Five() =
static member Five() =
Assert.Fail("Expected")


[<Koan>]
member this.Six() =
static member Six() =
"FTW!"

[<Test>]
let ``Output contains container name followed by koan results. Stops on failure`` () =
let runner = KoanRunner([ContainerOne(); ContainerTwo()])
let result = runner.ExecuteKoans
let runner = KoanRunner([| typeof<ContainerOne>; typeof<ContainerTwo> |])
let result = runner.ExecuteKoans()

let expected =
"
Expand Down
Loading

0 comments on commit 95159d4

Please sign in to comment.