From 4ff63410342634e9153c24b79d7f78d70a32a1f6 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 1 Sep 2015 16:57:16 -0700 Subject: [PATCH 1/8] implemented xunit tests for testing isHardLink using a fileSystem object --- src/ps_test/test_CorePsPlatform.cs | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index 57e58bc32f..b761c234b9 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -1,5 +1,6 @@ using Xunit; using System; +using System.IO; using System.Diagnostics; using System.Management.Automation; @@ -90,5 +91,38 @@ namespace PSTests } + + [Fact] + public static void TestIsHardLink() + { + // a file that should exist on every *nix distro + + string path = @"/tmp/MyTest"; + if (!File.Exists(path)) + { + File.Create(path); + } + + // Create a file to write to using StreamWriter. + // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. + byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); + MemoryStream stream = new MemoryStream(byteArray); + + using (StreamWriter sw = new StreamWriter(stream)) + { + sw.Write("Hello"); + } + + // Convert `path` string to FileSystemInfo data type. And now, it should return true + FileSystemInfo fd = new FileInfo(path); + Assert.True(Platform.NonWindowsIsHardLink(fd)); + } + + [Fact] + public static void TestIsHardLinkFailsWithDirectory() + { + + } + } } From 73b1a714208e03eacba185dda2bfc25c33d50d7b Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Tue, 1 Sep 2015 16:58:16 -0700 Subject: [PATCH 2/8] bringing implementation code up-to-date with the test code --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index d541b07343..01ff8a3f79 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit d541b073435e55fd96771697e5549cc9a188fa54 +Subproject commit 01ff8a3f7967503f805933d17b90ddb23402b866 From 080c734dfb93c0aa2cfd3b765b26d1affb245137 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Wed, 2 Sep 2015 11:02:09 -0700 Subject: [PATCH 3/8] added fail under directory as input unit test --- src/ps_test/test_CorePsPlatform.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index b761c234b9..bc62134ca0 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -93,7 +93,7 @@ namespace PSTests } [Fact] - public static void TestIsHardLink() + public static void TestIsHardLinkWithFileSystemInfo() { // a file that should exist on every *nix distro @@ -102,7 +102,6 @@ namespace PSTests { File.Create(path); } - // Create a file to write to using StreamWriter. // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); @@ -119,9 +118,20 @@ namespace PSTests } [Fact] - public static void TestIsHardLinkFailsWithDirectory() + public static void TestIsHardLinkFailsWithDirectoryWithFileSystemInfo() { - + // A folder that should exist on every *nix system + string path = @"/tmp"; + + // Create a file to write to using StreamWriter. + // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. + byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); + MemoryStream stream = new MemoryStream(byteArray); + + // Convert `path` string to FileSystemInfo data type. And now, it should return true + FileSystemInfo fd = new FileInfo(path); + Assert.False(Platform.NonWindowsIsHardLink(fd)); + } } From 9b02eea58dca19af87ac117b3840ab27f4a01157 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Wed, 2 Sep 2015 11:15:31 -0700 Subject: [PATCH 4/8] added unit test for additional failure cases and removed unneeded code from existing unit tests --- src/ps_test/test_CorePsPlatform.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index bc62134ca0..a8bf60eb91 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -102,6 +102,7 @@ namespace PSTests { File.Create(path); } + // Create a file to write to using StreamWriter. // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); @@ -123,16 +124,23 @@ namespace PSTests // A folder that should exist on every *nix system string path = @"/tmp"; - // Create a file to write to using StreamWriter. - // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. - byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); - MemoryStream stream = new MemoryStream(byteArray); + // Convert `path` string to FileSystemInfo data type. And now, it should return true + FileSystemInfo fd = new FileInfo(path); + Assert.False(Platform.NonWindowsIsHardLink(fd)); + } + + [Fact] + public static void TestIsHardLinkFailsWithNonexistantFileWithFileSystemInfo() + { + // A file that should *never* exist on a test machine: + string path = @"/tmp/ThisFileShouldNotExistOnTestMachines"; + + // If the file exists, then there's a larger issue that needs to be looked at + Assert.False(File.Exists(path)); // Convert `path` string to FileSystemInfo data type. And now, it should return true FileSystemInfo fd = new FileInfo(path); Assert.False(Platform.NonWindowsIsHardLink(fd)); - } - } } From 74f0a893c1dda04f2cccdcdb52968e19525baeb7 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Wed, 2 Sep 2015 15:17:35 -0700 Subject: [PATCH 5/8] Repin monad --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index 01ff8a3f79..d0697c432c 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 01ff8a3f7967503f805933d17b90ddb23402b866 +Subproject commit d0697c432c1d678e59af3ebd6320e5bc3a432b2f From f6e255310b3765ce4f15b13837bd59678bc58e2a Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 3 Sep 2015 16:40:30 -0700 Subject: [PATCH 6/8] merged upstream changes inside monad --- src/monad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/monad b/src/monad index 01ff8a3f79..d0697c432c 160000 --- a/src/monad +++ b/src/monad @@ -1 +1 @@ -Subproject commit 01ff8a3f7967503f805933d17b90ddb23402b866 +Subproject commit d0697c432c1d678e59af3ebd6320e5bc3a432b2f From d4f08a971d1822c64f266c3ddccbcdb1e66044df Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 3 Sep 2015 16:41:14 -0700 Subject: [PATCH 7/8] changed according to code review --- src/ps_test/test_CorePsPlatform.cs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index a8bf60eb91..f2fcef4560 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -93,35 +93,26 @@ namespace PSTests } [Fact] - public static void TestIsHardLinkWithFileSystemInfo() + public static void TestExistantFileIsHardLink() { - // a file that should exist on every *nix distro - string path = @"/tmp/MyTest"; if (!File.Exists(path)) { File.Create(path); } - // Create a file to write to using StreamWriter. // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); MemoryStream stream = new MemoryStream(byteArray); - using (StreamWriter sw = new StreamWriter(stream)) - { - sw.Write("Hello"); - } - // Convert `path` string to FileSystemInfo data type. And now, it should return true FileSystemInfo fd = new FileInfo(path); Assert.True(Platform.NonWindowsIsHardLink(fd)); } [Fact] - public static void TestIsHardLinkFailsWithDirectoryWithFileSystemInfo() + public static void TestDirectoryIsHardLink() { - // A folder that should exist on every *nix system string path = @"/tmp"; // Convert `path` string to FileSystemInfo data type. And now, it should return true @@ -130,7 +121,7 @@ namespace PSTests } [Fact] - public static void TestIsHardLinkFailsWithNonexistantFileWithFileSystemInfo() + public static void TestNonExistantIsHardLink() { // A file that should *never* exist on a test machine: string path = @"/tmp/ThisFileShouldNotExistOnTestMachines"; From bd6e4ef88511b80ae1860460bed2a3234aef7ea5 Mon Sep 17 00:00:00 2001 From: Zachary Folwick Date: Thu, 3 Sep 2015 16:42:28 -0700 Subject: [PATCH 8/8] fixed typo --- src/ps_test/test_CorePsPlatform.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ps_test/test_CorePsPlatform.cs b/src/ps_test/test_CorePsPlatform.cs index f2fcef4560..e11826091e 100644 --- a/src/ps_test/test_CorePsPlatform.cs +++ b/src/ps_test/test_CorePsPlatform.cs @@ -101,7 +101,8 @@ namespace PSTests File.Create(path); } // Create a file to write to using StreamWriter. - // convert string to stream. On Windows, this appears to be handled, but on *nix, we apparently need to convert to UTF8. + // convert string to stream. On Windows, this appears to be handled, but on *nix, + // we apparently need to convert to UTF8. byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(path); MemoryStream stream = new MemoryStream(byteArray);