From 67f8bb54f9bfc47dc8b9dc1f16487fefde4d5abf Mon Sep 17 00:00:00 2001 From: "Pranav Senthilnathan (from Dev Box)" Date: Wed, 30 Oct 2024 16:18:59 -0700 Subject: [PATCH 1/4] adding logs in tests --- .../System.IO.FileSystem.Tests/File/Copy.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs index d58fd95cfae3d..6c76055614178 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using System.Security.Cryptography; using Xunit; @@ -337,6 +338,44 @@ public void OverwriteFalse() } } + [Theory, + InlineData("", ":bar"), + InlineData("", ":bar:$DATA"), + InlineData("::$DATA", ":bar"), + InlineData("::$DATA", ":bar:$DATA")] + [PlatformSpecific(TestPlatforms.Windows)] + public void WindowsAlternateDataStreamOverwriteFat32(string defaultStream, string alternateStream) + { + Console.WriteLine($"Platform: {PlatformDetection.IsNativeAot}"); + Console.WriteLine($"Process Architecture: {RuntimeInformation.ProcessArchitecture}"); + Console.WriteLine($"OS Architecture: {RuntimeInformation.OSArchitecture}"); + + string testDir = Path.Combine("F:\\tests", GetTestFileName()); + DirectoryInfo testDirectory = Directory.CreateDirectory(testDir); + string testFile = Path.Combine(testDirectory.FullName, GetTestFileName()); + string testFileDefaultStream = testFile + defaultStream; + string testFileAlternateStream = testFile + alternateStream; + + // Copy the default stream into an alternate stream + File.WriteAllText(testFileDefaultStream, "Foo"); + Copy(testFileDefaultStream, testFileAlternateStream); + Assert.Equal(testFile, testDirectory.GetFiles().Single().FullName); + Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); + Assert.Equal("Foo", File.ReadAllText(testFileAlternateStream)); + + // Copy another file over the alternate stream + string testFile2 = Path.Combine(testDirectory.FullName, GetTestFileName()); + string testFile2DefaultStream = testFile2 + defaultStream; + File.WriteAllText(testFile2DefaultStream, "Bar"); + Copy(testFile2DefaultStream, testFileAlternateStream, overwrite: true); + Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); + Assert.Equal("Bar", File.ReadAllText(testFileAlternateStream)); + + // This always throws as you can't copy an alternate stream out (oddly) + Assert.Throws(() => Copy(testFileAlternateStream, testFile2, overwrite: true)); + Assert.Throws(() => Copy(testFileAlternateStream, testFile2 + alternateStream, overwrite: true)); + } + [Theory, InlineData("", ":bar"), InlineData("", ":bar:$DATA"), From 5cc582b75172b0163e16c1d595ef6aebdf7cd0d9 Mon Sep 17 00:00:00 2001 From: "Pranav Senthilnathan (from Dev Box)" Date: Wed, 30 Oct 2024 19:46:58 -0700 Subject: [PATCH 2/4] adding some logs to test --- .../System.IO.FileSystem.Tests/File/Copy.cs | 56 ++++++------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs index 6c76055614178..cfd2586e206af 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs @@ -237,6 +237,17 @@ public void WindowsAlternateDataStream(string defaultStream, string alternateStr File.WriteAllText(testFile2DefaultStream, "Bar"); Assert.Throws(() => 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(() => Copy(testFileAlternateStream, testFile2)); Assert.Throws(() => Copy(testFileAlternateStream, testFile2 + alternateStream)); @@ -338,44 +349,6 @@ public void OverwriteFalse() } } - [Theory, - InlineData("", ":bar"), - InlineData("", ":bar:$DATA"), - InlineData("::$DATA", ":bar"), - InlineData("::$DATA", ":bar:$DATA")] - [PlatformSpecific(TestPlatforms.Windows)] - public void WindowsAlternateDataStreamOverwriteFat32(string defaultStream, string alternateStream) - { - Console.WriteLine($"Platform: {PlatformDetection.IsNativeAot}"); - Console.WriteLine($"Process Architecture: {RuntimeInformation.ProcessArchitecture}"); - Console.WriteLine($"OS Architecture: {RuntimeInformation.OSArchitecture}"); - - string testDir = Path.Combine("F:\\tests", GetTestFileName()); - DirectoryInfo testDirectory = Directory.CreateDirectory(testDir); - string testFile = Path.Combine(testDirectory.FullName, GetTestFileName()); - string testFileDefaultStream = testFile + defaultStream; - string testFileAlternateStream = testFile + alternateStream; - - // Copy the default stream into an alternate stream - File.WriteAllText(testFileDefaultStream, "Foo"); - Copy(testFileDefaultStream, testFileAlternateStream); - Assert.Equal(testFile, testDirectory.GetFiles().Single().FullName); - Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); - Assert.Equal("Foo", File.ReadAllText(testFileAlternateStream)); - - // Copy another file over the alternate stream - string testFile2 = Path.Combine(testDirectory.FullName, GetTestFileName()); - string testFile2DefaultStream = testFile2 + defaultStream; - File.WriteAllText(testFile2DefaultStream, "Bar"); - Copy(testFile2DefaultStream, testFileAlternateStream, overwrite: true); - Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); - Assert.Equal("Bar", File.ReadAllText(testFileAlternateStream)); - - // This always throws as you can't copy an alternate stream out (oddly) - Assert.Throws(() => Copy(testFileAlternateStream, testFile2, overwrite: true)); - Assert.Throws(() => Copy(testFileAlternateStream, testFile2 + alternateStream, overwrite: true)); - } - [Theory, InlineData("", ":bar"), InlineData("", ":bar:$DATA"), @@ -391,6 +364,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)); + Console.WriteLine($"Copying default stream into alternate stream."); Copy(testFileDefaultStream, testFileAlternateStream); Assert.Equal(testFile, testDirectory.GetFiles().Single().FullName); Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); @@ -400,6 +375,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)); + Console.WriteLine($"Attributes for {testFile2DefaultStream}:{File.GetAttributes(testFile2DefaultStream)}"); + Console.WriteLine($"Attributes for {testFileAlternateStream}:{File.GetAttributes(testFileAlternateStream)}"); + Console.WriteLine($"Overwriting alternate stream."); Copy(testFile2DefaultStream, testFileAlternateStream, overwrite: true); Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); Assert.Equal("Bar", File.ReadAllText(testFileAlternateStream)); From c161ac45fd4b40da9f60c777d57fecea76678a7d Mon Sep 17 00:00:00 2001 From: "Pranav Senthilnathan (from Dev Box)" Date: Wed, 30 Oct 2024 19:51:08 -0700 Subject: [PATCH 3/4] remove using --- .../System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs index cfd2586e206af..a81dbc432b07b 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; -using System.Runtime.InteropServices; using System.Security.Cryptography; using Xunit; From 5b59ae10fede313304726dda6a88a996ce30fab9 Mon Sep 17 00:00:00 2001 From: "Pranav Senthilnathan (from Dev Box)" Date: Thu, 31 Oct 2024 14:51:13 -0700 Subject: [PATCH 4/4] use test output helper --- .../tests/System.IO.FileSystem.Tests/File/Copy.cs | 15 +++++++++++---- .../System.IO.FileSystem.Tests/FileInfo/CopyTo.cs | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs index a81dbc432b07b..7abc7ac3a286e 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/File/Copy.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Security.Cryptography; using Xunit; +using Xunit.Abstractions; namespace System.IO.Tests { @@ -286,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); @@ -364,7 +371,7 @@ 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)); - Console.WriteLine($"Copying default stream into alternate stream."); + _output.WriteLine("Copying default stream into alternate stream."); Copy(testFileDefaultStream, testFileAlternateStream); Assert.Equal(testFile, testDirectory.GetFiles().Single().FullName); Assert.Equal("Foo", File.ReadAllText(testFileDefaultStream)); @@ -376,9 +383,9 @@ public void WindowsAlternateDataStreamOverwrite(string defaultStream, string alt File.WriteAllText(testFile2DefaultStream, "Bar"); Assert.Equal("Bar", File.ReadAllText(testFile2DefaultStream)); Assert.Equal("Foo", File.ReadAllText(testFileAlternateStream)); - Console.WriteLine($"Attributes for {testFile2DefaultStream}:{File.GetAttributes(testFile2DefaultStream)}"); - Console.WriteLine($"Attributes for {testFileAlternateStream}:{File.GetAttributes(testFileAlternateStream)}"); - Console.WriteLine($"Overwriting alternate stream."); + _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)); diff --git a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/CopyTo.cs b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/CopyTo.cs index 49625c1f0c193..1899a98fea411 100644 --- a/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/CopyTo.cs +++ b/src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileInfo/CopyTo.cs @@ -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 { @@ -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);