Set working directory for tests (#36)

This commit is contained in:
Patrick Stevens
2024-06-06 20:50:48 +01:00
committed by GitHub
parent edfa216809
commit c6f339c738
5 changed files with 25 additions and 7 deletions

View File

@@ -9,8 +9,15 @@ open NUnit.Framework
module TestAppDomain = module TestAppDomain =
[<Test>] [<Test>]
let ``Can load config`` () = let ``Can load config from app domain`` () =
Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "some-config.json") Path.Combine (AppDomain.CurrentDomain.BaseDirectory, "some-config.json")
|> File.ReadAllText |> File.ReadAllText
|> fun s -> s.Trim () |> fun s -> s.Trim ()
|> shouldEqual """{"hi":"bye"}""" |> shouldEqual """{"hi":"bye"}"""
[<Test>]
let ``Can load config from working dir`` () =
"some-config.json"
|> File.ReadAllText
|> fun s -> s.Trim ()
|> shouldEqual """{"hi":"bye"}"""

View File

@@ -57,6 +57,8 @@ type SingleTestMethod =
/// each of which may run many times. /// each of which may run many times.
type TestFixture = type TestFixture =
{ {
/// The assembly which contains this TestFixture, loaded into a separate context.
ContainingAssembly : Assembly
/// Fully-qualified name of this fixture (e.g. MyThing.Test.Foo for `[<TestFixture>] module Foo` in the /// Fully-qualified name of this fixture (e.g. MyThing.Test.Foo for `[<TestFixture>] module Foo` in the
/// `MyThing.Test` assembly). /// `MyThing.Test` assembly).
Name : string Name : string
@@ -80,8 +82,9 @@ type TestFixture =
} }
/// A test fixture about which we know nothing. No tests, no setup/teardown. /// A test fixture about which we know nothing. No tests, no setup/teardown.
static member Empty (name : string) = static member Empty (containingAssembly : Assembly) (name : string) =
{ {
ContainingAssembly = containingAssembly
Name = name Name = name
OneTimeSetUp = None OneTimeSetUp = None
OneTimeTearDown = None OneTimeTearDown = None

View File

@@ -161,8 +161,10 @@ TestRunner.TestFailure.NewTearDownFailed [static method]: TestRunner.UserMethodF
TestRunner.TestFailure.NewTestFailed [static method]: TestRunner.UserMethodFailure -> TestRunner.TestFailure TestRunner.TestFailure.NewTestFailed [static method]: TestRunner.UserMethodFailure -> TestRunner.TestFailure
TestRunner.TestFailure.Tag [property]: [read-only] int TestRunner.TestFailure.Tag [property]: [read-only] int
TestRunner.TestFixture inherit obj, implements TestRunner.TestFixture System.IEquatable, System.Collections.IStructuralEquatable TestRunner.TestFixture inherit obj, implements TestRunner.TestFixture System.IEquatable, System.Collections.IStructuralEquatable
TestRunner.TestFixture..ctor [constructor]: (string, System.Reflection.MethodInfo option, System.Reflection.MethodInfo option, System.Reflection.MethodInfo list, System.Reflection.MethodInfo list, TestRunner.SingleTestMethod list) TestRunner.TestFixture..ctor [constructor]: (System.Reflection.Assembly, string, System.Reflection.MethodInfo option, System.Reflection.MethodInfo option, System.Reflection.MethodInfo list, System.Reflection.MethodInfo list, TestRunner.SingleTestMethod list)
TestRunner.TestFixture.Empty [static method]: string -> TestRunner.TestFixture TestRunner.TestFixture.ContainingAssembly [property]: [read-only] System.Reflection.Assembly
TestRunner.TestFixture.Empty [static method]: System.Reflection.Assembly -> string -> TestRunner.TestFixture
TestRunner.TestFixture.get_ContainingAssembly [method]: unit -> System.Reflection.Assembly
TestRunner.TestFixture.get_Name [method]: unit -> string TestRunner.TestFixture.get_Name [method]: unit -> string
TestRunner.TestFixture.get_OneTimeSetUp [method]: unit -> System.Reflection.MethodInfo option TestRunner.TestFixture.get_OneTimeSetUp [method]: unit -> System.Reflection.MethodInfo option
TestRunner.TestFixture.get_OneTimeTearDown [method]: unit -> System.Reflection.MethodInfo option TestRunner.TestFixture.get_OneTimeTearDown [method]: unit -> System.Reflection.MethodInfo option
@@ -267,4 +269,4 @@ TestRunner.UserMethodFailure.IsThrew [property]: [read-only] bool
TestRunner.UserMethodFailure.Name [property]: [read-only] string TestRunner.UserMethodFailure.Name [property]: [read-only] string
TestRunner.UserMethodFailure.NewReturnedNonUnit [static method]: (string, obj) -> TestRunner.UserMethodFailure TestRunner.UserMethodFailure.NewReturnedNonUnit [static method]: (string, obj) -> TestRunner.UserMethodFailure
TestRunner.UserMethodFailure.NewThrew [static method]: (string, System.Exception) -> TestRunner.UserMethodFailure TestRunner.UserMethodFailure.NewThrew [static method]: (string, System.Exception) -> TestRunner.UserMethodFailure
TestRunner.UserMethodFailure.Tag [property]: [read-only] int TestRunner.UserMethodFailure.Tag [property]: [read-only] int

View File

@@ -1,6 +1,7 @@
namespace TestRunner namespace TestRunner
open System open System
open System.IO
open System.Reflection open System.Reflection
open System.Threading open System.Threading
open Microsoft.FSharp.Core open Microsoft.FSharp.Core
@@ -281,6 +282,9 @@ module TestFixture =
) )
|> Option.toObj |> Option.toObj
let oldWorkDir = Environment.CurrentDirectory
Environment.CurrentDirectory <- FileInfo(tests.ContainingAssembly.Location).Directory.FullName
let setupResult = let setupResult =
match tests.OneTimeSetUp with match tests.OneTimeSetUp with
| Some su -> | Some su ->
@@ -331,6 +335,8 @@ module TestFixture =
Some (UserMethodFailure.Threw (td.Name, e)) Some (UserMethodFailure.Threw (td.Name, e))
| _ -> None | _ -> None
Environment.CurrentDirectory <- oldWorkDir
{ {
Failed = testFailures |> Seq.toList Failed = testFailures |> Seq.toList
SuccessCount = totalTestSuccess.Value SuccessCount = totalTestSuccess.Value
@@ -346,7 +352,7 @@ module TestFixture =
|> Seq.map (fun attr -> attr.ConstructorArguments |> Seq.exactlyOne |> _.Value |> unbox<string>) |> Seq.map (fun attr -> attr.ConstructorArguments |> Seq.exactlyOne |> _.Value |> unbox<string>)
|> Seq.toList |> Seq.toList
(TestFixture.Empty parentType.Name, parentType.GetRuntimeMethods ()) (TestFixture.Empty parentType.Assembly parentType.Name, parentType.GetRuntimeMethods ())
||> Seq.fold (fun state mi -> ||> Seq.fold (fun state mi ->
((state, []), mi.CustomAttributes) ((state, []), mi.CustomAttributes)
||> Seq.fold (fun (state, unrecognisedAttrs) attr -> ||> Seq.fold (fun (state, unrecognisedAttrs) attr ->

View File

@@ -1,5 +1,5 @@
{ {
"version": "0.2", "version": "0.3",
"publicReleaseRefSpec": null, "publicReleaseRefSpec": null,
"pathFilters": [ "pathFilters": [
"./", "./",