Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Ensure FileInfo is not relative in DirectoryInfoProxy #1519

Merged
merged 2 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/Impl/IO/DirectoryInfoProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public IEnumerable<IFileSystemInfo> EnumerateFileSystemInfos(string[] includePat
var matcher = GetMatcher(includePatterns, excludePatterns);
PatternMatchingResult matchResult = SafeExecuteMatcher(matcher);
return matchResult.Files.Select((filePatternMatch) => {
var path = PathUtils.NormalizePath(filePatternMatch.Path);
var path = PathUtils.NormalizePath(Path.Combine(_directoryInfo.FullName, filePatternMatch.Path));
return CreateFileSystemInfoProxy(new FileInfo(path));
});
}
Expand Down
34 changes: 34 additions & 0 deletions src/Core/Test/AssemblySetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the License); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using Microsoft.Python.Core.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestUtilities;

namespace Microsoft.Python.Core.Tests {
[TestClass]
public sealed class AssemblySetup {
[AssemblyInitialize]
public static void Initialize(TestContext testContext) => AnalysisTestEnvironment.Initialize();

private class AnalysisTestEnvironment : TestEnvironmentImpl, ITestEnvironment {
public static void Initialize() {
var instance = new AnalysisTestEnvironment();
Instance = instance;
TestEnvironment.Current = instance;
}
}
}
}
51 changes: 51 additions & 0 deletions src/Core/Test/DirectoryInfoProxyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright(c) Microsoft Corporation
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the License); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at http://www.apache.org/licenses/LICENSE-2.0
//
// THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
// IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
// MERCHANTABILITY OR NON-INFRINGEMENT.
//
// See the Apache Version 2.0 License for specific language governing
// permissions and limitations under the License.

using System.IO;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.Python.Core.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TestUtilities;

namespace Microsoft.Python.Core.Tests {
[TestClass]
public class DirectoryInfoProxyTests {
public TestContext TestContext { get; set; }

[TestInitialize]
public void TestInitialize()
=> TestEnvironmentImpl.TestInitialize($"{TestContext.FullyQualifiedTestClassName}.{TestContext.TestName}");

[TestCleanup]
public void Cleanup() => TestEnvironmentImpl.TestCleanup();

[TestMethod, Priority(0)]
public async Task EnumerateFileSystemInfos() {
var root = TestData.GetTestSpecificPath();
await TestData.CreateTestSpecificFileAsync("a_y.py", "not important");
await TestData.CreateTestSpecificFileAsync("b_y.py", "not important");
await TestData.CreateTestSpecificFileAsync("c_z.py", "not important");

var proxy = new DirectoryInfoProxy(root);
var files = proxy.EnumerateFileSystemInfos(new[] { "*.py" }, new[] { "*z.py" }).OrderBy(x => x.FullName).ToArray();
files.Should().HaveCount(2);

files[0].FullName.Should().Be(Path.Combine(root, "a_y.py"));
files[1].FullName.Should().Be(Path.Combine(root, "b_y.py"));
}
}
}