Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/corefx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Kuhne <jeremy.kuhne@microsoft.com>2018-02-20 08:01:21 +0300
committerGitHub <noreply@github.com>2018-02-20 08:01:21 +0300
commit597f44c5056badfb47f45731480454d698849800 (patch)
treec1d808a419c9df1c938c4bda5b087ca3e3a8cb84 /src/System.IO.FileSystem/tests
parent6993b6df87e4148e23d65ae854b945d3866f856c (diff)
Handle errors getting state in Unix (#27239)
* Handle errors getting state in Unix Throwing errors while examining extended state while enumerating isn't consistent with Windows behavior. Windows never throws past getting directory entry data as all state is already available. Ensure entry attribute state is consistent with initial construction. * Win 7 CI machines are also setting NotContentIndexed.
Diffstat (limited to 'src/System.IO.FileSystem/tests')
-rw-r--r--src/System.IO.FileSystem/tests/Enumeration/AttributeTests.netcoreapp.cs115
-rw-r--r--src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj1
2 files changed, 116 insertions, 0 deletions
diff --git a/src/System.IO.FileSystem/tests/Enumeration/AttributeTests.netcoreapp.cs b/src/System.IO.FileSystem/tests/Enumeration/AttributeTests.netcoreapp.cs
new file mode 100644
index 0000000000..d35783713f
--- /dev/null
+++ b/src/System.IO.FileSystem/tests/Enumeration/AttributeTests.netcoreapp.cs
@@ -0,0 +1,115 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System.IO.Enumeration;
+using Xunit;
+
+namespace System.IO.Tests.Enumeration
+{
+ public class AttributeTests : FileSystemTest
+ {
+ private class DefaultFileAttributes : FileSystemEnumerator<string>
+ {
+ public DefaultFileAttributes(string directory, EnumerationOptions options)
+ : base(directory, options)
+ {
+ }
+
+ protected override bool ContinueOnError(int error)
+ {
+ Assert.False(true, $"Should not have errored {error}");
+ return false;
+ }
+
+ protected override bool ShouldIncludeEntry(ref FileSystemEntry entry)
+ => !entry.IsDirectory;
+
+ protected override string TransformEntry(ref FileSystemEntry entry)
+ {
+ string path = entry.ToFullPath();
+ File.Delete(path);
+
+ // Attributes require a stat call on Unix- ensure that we have the right attributes
+ // even if the returned file is deleted.
+ Assert.Equal(FileAttributes.Normal, entry.Attributes);
+ Assert.Equal(path, entry.ToFullPath());
+ return new string(entry.FileName);
+ }
+ }
+
+ [Fact]
+ public void FileAttributesAreExpected()
+ {
+ DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
+ FileInfo fileOne = new FileInfo(Path.Combine(testDirectory.FullName, GetTestFileName()));
+
+ fileOne.Create().Dispose();
+
+ if (PlatformDetection.IsWindows)
+ {
+ // Archive should always be set on a new file. Clear it and other expected flags to
+ // see that we get "Normal" as the default when enumerating.
+
+ Assert.True((fileOne.Attributes & FileAttributes.Archive) != 0);
+ fileOne.Attributes &= ~(FileAttributes.Archive | FileAttributes.NotContentIndexed);
+ }
+
+ using (var enumerator = new DefaultFileAttributes(testDirectory.FullName, new EnumerationOptions()))
+ {
+ Assert.True(enumerator.MoveNext());
+ Assert.Equal(fileOne.Name, enumerator.Current);
+ Assert.False(enumerator.MoveNext());
+ }
+ }
+
+ private class DefaultDirectoryAttributes : FileSystemEnumerator<string>
+ {
+ public DefaultDirectoryAttributes(string directory, EnumerationOptions options)
+ : base(directory, options)
+ {
+ }
+
+ protected override bool ShouldIncludeEntry(ref FileSystemEntry entry)
+ => entry.IsDirectory;
+
+ protected override bool ContinueOnError(int error)
+ {
+ Assert.False(true, $"Should not have errored {error}");
+ return false;
+ }
+
+ protected override string TransformEntry(ref FileSystemEntry entry)
+ {
+ string path = entry.ToFullPath();
+ Directory.Delete(path);
+
+ // Attributes require a stat call on Unix- ensure that we have the right attributes
+ // even if the returned directory is deleted.
+ Assert.Equal(FileAttributes.Directory, entry.Attributes);
+ Assert.Equal(path, entry.ToFullPath());
+ return new string(entry.FileName);
+ }
+ }
+
+ [Fact]
+ public void DirectoryAttributesAreExpected()
+ {
+ DirectoryInfo testDirectory = Directory.CreateDirectory(GetTestFilePath());
+ DirectoryInfo subDirectory = Directory.CreateDirectory(Path.Combine(testDirectory.FullName, GetTestFileName()));
+
+ if (PlatformDetection.IsWindows)
+ {
+ // Clear possible extra flags to see that we get Directory
+ subDirectory.Attributes &= ~FileAttributes.NotContentIndexed;
+ }
+
+ using (var enumerator = new DefaultDirectoryAttributes(testDirectory.FullName, new EnumerationOptions()))
+ {
+ Assert.True(enumerator.MoveNext());
+ Assert.Equal(subDirectory.Name, enumerator.Current);
+ Assert.False(enumerator.MoveNext());
+ }
+ }
+ }
+}
diff --git a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
index 402489b5e8..672d5642dc 100644
--- a/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
+++ b/src/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
@@ -63,6 +63,7 @@
<Compile Include="Enumeration\IncludePredicateTests.netcoreapp.cs" />
<Compile Include="Enumeration\PatternTransformTests.netcoreapp.cs" />
<Compile Include="Enumeration\RootTests.netcoreapp.cs" />
+ <Compile Include="Enumeration\AttributeTests.netcoreapp.cs" />
</ItemGroup>
<ItemGroup>
<!-- Rewritten -->