Skip to content

Commit

Permalink
fix: brittle test on .NET 8 (#406)
Browse files Browse the repository at this point in the history
In .NET 8 a new flag was added to
[`FileAttributes`](https://learn.microsoft.com/en-us/dotnet/api/system.io.fileattributes?view=net-8.0):
`FileAttributes.None`.
When this attribute is used in the
`GetAttributes_ShouldReturnAttributes` test, the test fails.

Now the tested attributes are explicitly specified, so that the test
always succeeds.

*See [this test
run](https://github.com/Testably/Testably.Abstractions/actions/runs/6380040873/job/17313688446?pr=389)
in #389.*
  • Loading branch information
vbreuss committed Oct 6, 2023
1 parent 77b2d34 commit 76932e5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public void Attributes_ClearAllAttributes_ShouldRemainDirectory(string path)
}

[SkippableTheory]
[AutoData]
[InlineAutoData(FileAttributes.ReadOnly)]
[InlineAutoData(FileAttributes.Normal)]
public void Attributes_WhenFileIsExisting_SetterShouldChangeAttributesOnFileSystem(
string path, FileAttributes attributes)
FileAttributes attributes, string path)
{
FileSystem.Directory.CreateDirectory(path);
IDirectoryInfo sut1 = FileSystem.DirectoryInfo.New(path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ public abstract partial class GetAttributesTests<TFileSystem>
where TFileSystem : IFileSystem
{
[SkippableTheory]
[AutoData]
[InlineAutoData(FileAttributes.ReadOnly)]
[InlineAutoData(FileAttributes.Normal)]
public void GetAttributes_ShouldReturnAttributes(
string path, FileAttributes attributes)
FileAttributes attributes, string path)
{
FileSystem.File.WriteAllText(path, null);
FileSystem.File.SetAttributes(path, attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ public abstract partial class SetAttributesTests<TFileSystem>
where TFileSystem : IFileSystem
{
[SkippableTheory]
[AutoData]
public void SetAttributes_ShouldNotAdjustTimes(string path, FileAttributes attributes)
[InlineAutoData(FileAttributes.ReadOnly)]
[InlineAutoData(FileAttributes.Normal)]
public void SetAttributes_ShouldNotAdjustTimes(FileAttributes attributes, string path)
{
Test.SkipIfLongRunningTestsShouldBeSkipped(FileSystem);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ public abstract partial class CopyToTests<TFileSystem>
}

[SkippableTheory]
[AutoData]
[InlineAutoData(FileAttributes.ReadOnly)]
[InlineAutoData(FileAttributes.System)]
public void CopyTo_ShouldAddArchiveAttribute_OnWindows(
FileAttributes fileAttributes,
string sourceName,
string destinationName,
string contents,
FileAttributes fileAttributes)
string contents)
{
FileSystem.File.WriteAllText(sourceName, contents);
FileSystem.File.SetAttributes(sourceName, fileAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ public void
}

[SkippableTheory]
[AutoData]
[InlineAutoData(FileAttributes.ReadOnly)]
[InlineAutoData(FileAttributes.System)]
public void MoveTo_ShouldAddArchiveAttribute_OnWindows(
FileAttributes fileAttributes,
string sourceName,
string destinationName,
string contents,
FileAttributes fileAttributes)
string contents)
{
FileSystem.File.WriteAllText(sourceName, contents);
FileSystem.File.SetAttributes(sourceName, fileAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ public void
}

[SkippableTheory]
[AutoData]
[InlineAutoData(FileAttributes.Hidden, FileAttributes.Hidden)]
[InlineAutoData(FileAttributes.System, FileAttributes.System)]
public void Replace_ShouldAddArchiveAttribute_OnWindows(
FileAttributes sourceFileAttributes,
FileAttributes destinationFileAttributes,
string sourceName,
string destinationName,
string backupName,
string sourceContents,
string destinationContents,
FileAttributes sourceFileAttributes,
FileAttributes destinationFileAttributes)
string destinationContents)
{
FileSystem.File.WriteAllText(sourceName, sourceContents);
FileSystem.File.SetAttributes(sourceName, sourceFileAttributes);
Expand Down

0 comments on commit 76932e5

Please sign in to comment.