Skip to content

Commit

Permalink
refactor: analyze brittle tests (#348)
Browse files Browse the repository at this point in the history
On MacOS the `GetCurrentDirectory` sometimes throws an exception. Catch
this exception in the constructor of the MockFileSystem to avoid brittle
tests.

---------

Co-authored-by: Valentin Breuß <[email protected]>
  • Loading branch information
vbreuss and vbtig authored Aug 5, 2023
1 parent af033f8 commit e5a16b7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions Source/Testably.Abstractions.Testing/MockFileSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.IO;
using Testably.Abstractions.Testing.FileSystem;
using Testably.Abstractions.Testing.Storage;

Expand Down Expand Up @@ -165,11 +166,19 @@ public MockFileSystem WithSafeFileHandleStrategy(

private void AddDriveFromCurrentDirectory()
{
string? root = Path.GetPathRoot(System.IO.Directory.GetCurrentDirectory());
if (root != null &&
root[0] != _storage.MainDrive.Name[0])
try
{
Storage.GetOrAddDrive(root);
string? root = Path.GetPathRoot(System.IO.Directory.GetCurrentDirectory());
if (root != null &&
root[0] != _storage.MainDrive.Name[0])
{
Storage.GetOrAddDrive(root);
}
}
catch (IOException)
{
// Ignore any IOException, when trying to read the current directory
// due to brittle tests on MacOS
}
}
}

0 comments on commit e5a16b7

Please sign in to comment.