Skip to content
This repository was archived by the owner on Nov 6, 2018. It is now read-only.

Commit 229edc3

Browse files
committed
* Don't throw if test clean up fails
* Minor FunctionalTests refactoring
1 parent 56d1df9 commit 229edc3

File tree

4 files changed

+20
-74
lines changed

4 files changed

+20
-74
lines changed

test/Microsoft.Framework.FileSystemGlobbing.Tests/FunctionalTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Microsoft.Framework.FileSystemGlobbing.Tests
1212
{
1313
public class FunctionalTests : IDisposable
1414
{
15-
private DisposableFileSystem _context;
15+
private readonly DisposableFileSystem _context;
1616

1717
public FunctionalTests()
1818
{
@@ -21,10 +21,7 @@ public FunctionalTests()
2121

2222
public void Dispose()
2323
{
24-
if (_context != null)
25-
{
26-
_context.Dispose();
27-
}
24+
_context.Dispose();
2825
}
2926

3027
[Theory]
@@ -78,11 +75,11 @@ public void IncludeCaseInsensitive(string root, string includePattern, string[]
7875
"sub/preprocess-source2.cs",
7976
"sub/sub/preprocess-source3.cs",
8077
"sub/sub/preprocess-source3.txt" })]
81-
[InlineData("src/project/compiler/preprocess/", "preprocess-source1.cs", new string[] {
78+
[InlineData("src/project/compiler/preprocess/", "preprocess-source1.cs", new string[] {
8279
"sub/preprocess-source2.cs",
8380
"sub/sub/preprocess-source3.cs",
8481
"sub/sub/preprocess-source3.txt" })]
85-
[InlineData("src/project/compiler/preprocess/", "preprocesS-source1.cs", new string[] {
82+
[InlineData("src/project/compiler/preprocess/", "preprocesS-source1.cs", new string[] {
8683
"preprocess-source1.cs",
8784
"sub/preprocess-source2.cs",
8885
"sub/sub/preprocess-source3.cs",
@@ -118,11 +115,11 @@ public void ExcludeCaseSensitive(string root, string excludePattern, string[] ex
118115
"sub/preprocess-source2.cs",
119116
"sub/sub/preprocess-source3.cs",
120117
"sub/sub/preprocess-source3.txt" })]
121-
[InlineData("src/project/compiler/preprocess/", "preprocess-source1.cs", new string[] {
118+
[InlineData("src/project/compiler/preprocess/", "preprocess-source1.cs", new string[] {
122119
"sub/preprocess-source2.cs",
123120
"sub/sub/preprocess-source3.cs",
124121
"sub/sub/preprocess-source3.txt" })]
125-
[InlineData("src/project/compiler/preprocess/", "preprocesS-source1.cs", new string[] {
122+
[InlineData("src/project/compiler/preprocess/", "preprocesS-source1.cs", new string[] {
126123
"sub/preprocess-source2.cs",
127124
"sub/sub/preprocess-source3.cs",
128125
"sub/sub/preprocess-source3.txt" })]
@@ -405,9 +402,12 @@ private void ExecuteAndVerify(Matcher matcher, string directoryPath, params stri
405402
var results = matcher.Execute(new DirectoryInfoWrapper(new DirectoryInfo(directoryPath)));
406403

407404
var actual = results.Files.Select(match => Path.GetFullPath(Path.Combine(_context.RootPath, directoryPath, match.Path)));
408-
var expect = expectFiles.Select(relativePath => Path.GetFullPath(Path.Combine(_context.RootPath, relativePath)));
405+
var expected = expectFiles.Select(relativePath => Path.GetFullPath(Path.Combine(_context.RootPath, relativePath)));
409406

410-
AssertHelpers.SortAndEqual(expect, actual, StringComparer.OrdinalIgnoreCase);
407+
Assert.Equal(
408+
expected.OrderBy(e => e),
409+
actual.OrderBy(e => e),
410+
StringComparer.OrdinalIgnoreCase);
411411
}
412412
}
413413
}

test/Microsoft.Framework.FileSystemGlobbing.Tests/TestUtility/AssertHelpers.cs

Lines changed: 0 additions & 48 deletions
This file was deleted.

test/Microsoft.Framework.FileSystemGlobbing.Tests/TestUtility/DisposableFileSystem.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@ namespace Microsoft.Framework.FileSystemGlobbing.Tests.TestUtility
99
{
1010
public class DisposableFileSystem : IDisposable
1111
{
12-
private readonly bool _automaticCleanup;
13-
14-
public DisposableFileSystem(bool automaticCleanup = true)
12+
public DisposableFileSystem()
1513
{
16-
_automaticCleanup = automaticCleanup;
17-
18-
RootPath = Path.GetTempFileName();
19-
File.Delete(RootPath);
14+
RootPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
2015
Directory.CreateDirectory(RootPath);
2116
DirectoryInfo = new DirectoryInfoWrapper(new DirectoryInfo(RootPath));
2217
}
@@ -46,18 +41,22 @@ public DisposableFileSystem CreateFiles(params string[] fileRelativePaths)
4641

4742
File.WriteAllText(
4843
fullPath,
49-
string.Format("Automatically generated for testing on {0:yyyy}/{0:MM}/{0:dd} {0:hh}:{0:mm}:{0:ss}", DateTime.Now));
44+
string.Format("Automatically generated for testing on {0:yyyy}/{0:MM}/{0:dd} {0:hh}:{0:mm}:{0:ss}", DateTime.UtcNow));
5045
}
5146

5247
return this;
5348
}
5449

5550
public void Dispose()
5651
{
57-
if (_automaticCleanup)
52+
try
5853
{
5954
Directory.Delete(RootPath, true);
6055
}
56+
catch
57+
{
58+
// Don't throw if this fails.
59+
}
6160
}
6261
}
6362
}

test/Microsoft.Framework.FileSystemGlobbing.Tests/project.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@
55
"Microsoft.Framework.FileSystemGlobbing": "1.0.0-*",
66
"Microsoft.AspNet.Testing": "1.0.0-*"
77
},
8-
98
"frameworks": {
109
"dnx451": { },
11-
"dnxcore50": {
12-
"dependencies": {
13-
"System.Runtime": "4.0.21-beta-*"
14-
}
15-
}
10+
"dnxcore50": { }
1611
},
1712
"commands": {
1813
"test": "xunit.runner.aspnet"

0 commit comments

Comments
 (0)