Skip to content

FakeFileSystem throws on linux, when it is created on a Windows FakeEnvironment #4322

@nils-a

Description

@nils-a

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

Cake runner

Cake .NET Tool

Cake version

4.0.0

Operating system

Linux

Operating system architecture

64-Bit

CI Server

No response

What are you seeing?

demo code

using Cake.Core;
using Cake.Core.IO;
using Cake.Testing;
using Xunit;

namespace test1;

public class Tests
{
    [Fact]
    public void T1()
    {
        var fixture = new MyFixture();
        
        Assert.True(fixture.FileSystem.GetDirectory(fixture.Environment.WorkingDirectory).Exists);
    }
}

public class MyFixture
{
    public ICakeEnvironment Environment { get; }
    public IFileSystem FileSystem { get; }

    public MyFixture()
    {
        Environment = FakeEnvironment.CreateWindowsEnvironment();
        FileSystem = new FakeFileSystem(Environment);
    }
}

error

System.ArgumentException: Working directory cannot be relative.

System.ArgumentException
Working directory cannot be relative.
   at Cake.Testing.FakeFileSystemTree..ctor(ICakeEnvironment environment)
   at Cake.Testing.FakeFileSystem..ctor(ICakeEnvironment environment)
   at test1.MyFixture..ctor() in /home/nils/dev/test1/Class1.cs:line 27
   at test1.Tests.T1() in /home/nils/dev/test1/Class1.cs:line 13
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

What is expected?

I expect no error to occur.

Steps to Reproduce

  • Create a new project
  • Add references
    • Cake.Testing
    • Microsoft.NET.Test.Sdk
    • xunit
  • Use the code from above
  • run the test

Output log

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions