Skip to content

Commit

Permalink
Adding info to debug WindowsAlternateDataStreamOverwrite failure (#10…
Browse files Browse the repository at this point in the history
…9399)

* adding logs in tests

* adding some logs to test

* remove using

* use test output helper
  • Loading branch information
PranavSenthilnathan authored Nov 4, 2024
1 parent 004d59a commit 4362771
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Security.Cryptography;
using Xunit;
using Xunit.Abstractions;

namespace System.IO.Tests
{
Expand Down Expand Up @@ -236,6 +237,17 @@ public void WindowsAlternateDataStream(string defaultStream, string alternateStr
File.WriteAllText(testFile2DefaultStream, "Bar");
Assert.Throws<IOException>(() => Copy(testFile2DefaultStream, testFileAlternateStream));

try
{
Copy(testFile2DefaultStream, testFileAlternateStream);
Assert.Fail();
}
catch (IOException e)
{
// Error code for "the file exists".
Assert.Equal(-2147024816, e.HResult);
}

// This always throws as you can't copy an alternate stream out (oddly)
Assert.Throws<IOException>(() => Copy(testFileAlternateStream, testFile2));
Assert.Throws<IOException>(() => Copy(testFileAlternateStream, testFile2 + alternateStream));
Expand Down Expand Up @@ -275,6 +287,12 @@ public void OverwriteCopyOntoLink()

public class File_Copy_str_str_b : File_Copy_str_str
{
private ITestOutputHelper _output;
public File_Copy_str_str_b(ITestOutputHelper output)
{
_output = output;
}

protected override void Copy(string source, string dest)
{
File.Copy(source, dest, false);
Expand Down Expand Up @@ -352,6 +370,8 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt

// Copy the default stream into an alternate stream
File.WriteAllText(testFileDefaultStream, "Foo");
Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream));
_output.WriteLine("Copying default stream into alternate stream.");
Copy(testFileDefaultStream, testFileAlternateStream);
Assert.Equal(testFile, testDirectory.GetFiles().Single().FullName);
Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream));
Expand All @@ -361,6 +381,11 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt
string testFile2 = Path.Combine(testDirectory.FullName, GetTestFileName());
string testFile2DefaultStream = testFile2 + defaultStream;
File.WriteAllText(testFile2DefaultStream, "Bar");
Assert.Equal("Bar", File.ReadAllText(testFile2DefaultStream));
Assert.Equal("Foo", File.ReadAllText(testFileAlternateStream));
_output.WriteLine($"Attributes for '{testFile2DefaultStream}': {File.GetAttributes(testFile2DefaultStream)}");
_output.WriteLine($"Attributes for '{testFileAlternateStream}': {File.GetAttributes(testFileAlternateStream)}");
_output.WriteLine("Overwriting alternate stream.");
Copy(testFile2DefaultStream, testFileAlternateStream, overwrite: true);
Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream));
Assert.Equal("Bar", File.ReadAllText(testFileAlternateStream));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Xunit;
using Xunit.Abstractions;

namespace System.IO.Tests
{
Expand All @@ -16,6 +17,11 @@ protected override void Copy(string source, string dest)

public class FileInfo_CopyTo_str_b : File_Copy_str_str_b
{
public FileInfo_CopyTo_str_b(ITestOutputHelper output)
: base(output)
{
}

protected override void Copy(string source, string dest)
{
new FileInfo(source).CopyTo(dest, false);
Expand Down

0 comments on commit 4362771

Please sign in to comment.