Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 92afa6e

Browse files
authored
Update tests for Path changes (#27348)
* Update tests for Path changes Updates for dotnet/coreclr#16478 * Add back Unix active issue (wishful thinking that this would get the same error on Unix) * Address feedback
1 parent fecb772 commit 92afa6e

File tree

27 files changed

+516
-193
lines changed

27 files changed

+516
-193
lines changed

src/System.ComponentModel.Composition/tests/System/ComponentModel/Composition/Hosting/AssemblyCatalogTests.cs

Lines changed: 68 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -78,71 +78,53 @@ public static void Constructor_LockedFileAsCodeBaseArgument_ShouldThrowFileLoad(
7878
string filename = Path.GetTempFileName();
7979
using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.None))
8080
{
81-
Assert.Throws<FileLoadException>(() =>
82-
{
83-
var catalog = catalogCreator(filename);
84-
});
81+
Assert.Throws<FileLoadException>(() => catalogCreator(filename));
8582
}
8683
}
8784

8885
public static void Constructor_NullFileNameAsCodeBaseArgument_ShouldThrowArgumentNull(Func<string, AssemblyCatalog> catalogCreator)
8986
{
90-
Assert.Throws<ArgumentNullException>("codeBase", () =>
91-
{
92-
var catalog = catalogCreator((string)null);
93-
});
87+
Assert.Throws<ArgumentNullException>("codeBase", () => catalogCreator(null));
9488
}
9589

9690
public static void Constructor_EmptyFileNameAsCodeBaseArgument_ShouldThrowArgument(Func<string, AssemblyCatalog> catalogCreator)
9791
{
98-
Assert.Throws<ArgumentException>("codeBase", () =>
99-
{
100-
var catalog = catalogCreator("");
101-
});
92+
Assert.Throws<ArgumentException>("codeBase", () => catalogCreator(""));
10293
}
10394

10495
public static void Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument(Func<string, AssemblyCatalog> catalogCreator)
10596
{
106-
Assert.Throws<ArgumentException>(() =>
107-
{
108-
var catalog = catalogCreator("??||>");
109-
});
97+
Assert.Throws<ArgumentException>(() => catalogCreator("??||>"));
98+
}
99+
100+
public static void Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowIO(Func<string, AssemblyCatalog> catalogCreator)
101+
{
102+
Assert.ThrowsAny<IOException>(() => catalogCreator("??||>"));
110103
}
111104

112105
public static void Constructor_DirectoryAsCodeBaseArgument_ShouldThrowFileLoad(Func<string, AssemblyCatalog> catalogCreator)
113106
{
114107
string directory = Environment.GetFolderPath(Environment.SpecialFolder.System);
115108
Assert.True(Directory.Exists(directory));
116109

117-
Assert.Throws<FileLoadException>(() =>
118-
{
119-
var catalog = catalogCreator(directory);
120-
});
110+
Assert.Throws<FileLoadException>(() => catalogCreator(directory));
121111
}
122112

123113
public static void Constructor_TooLongFileNameAsCodeBaseArgument_ShouldThrowPathTooLong(Func<string, AssemblyCatalog> catalogCreator)
124114
{
125115
Assert.Throws<PathTooLongException>(() =>
126-
{
127-
var catalog = catalogCreator(@"c:\This is a very long path\And Just to make sure\We will continue to make it very long\This is a very long path\And Just to make sure\We will continue to make it very long\This is a very long path\And Just to make sure\We will continue to make it very long\myassembly.dll");
128-
});
116+
catalogCreator(@"c:\This is a very long path\And Just to make sure\We will continue to make it very long\This is a very long path\And Just to make sure\We will continue to make it very long\This is a very long path\And Just to make sure\We will continue to make it very long\myassembly.dll"));
129117
}
130118

131119
public static void Constructor_NonAssemblyFileNameAsCodeBaseArgument_ShouldThrowBadImageFormat(Func<string, AssemblyCatalog> catalogCreator)
132120
{
133121
string filename = Path.GetTempFileName();
134-
Assert.Throws<BadImageFormatException>(() =>
135-
{
136-
var catalog = catalogCreator(filename);
137-
});
122+
Assert.Throws<BadImageFormatException>(() => catalogCreator(filename));
138123
}
139124

140125
public static void Constructor_NonExistentFileNameAsCodeBaseArgument_ShouldThrowFileNotFound(Func<string, AssemblyCatalog> catalogCreator)
141126
{
142-
Assert.Throws<FileNotFoundException>(() =>
143-
{
144-
var catalog = catalogCreator(@"FileThat should not ever exist");
145-
});
127+
Assert.Throws<FileNotFoundException>(() => catalogCreator(@"FileThat should not ever exist"));
146128
}
147129

148130
// Test Assembly variant of the APIs
@@ -160,18 +142,12 @@ public static void Constructor_ValueAsAssemblyArgument_ShouldSetAssemblyProperty
160142

161143
public static void Constructor_NullReflectionContextArgument_ShouldThrowArgumentNull(Func<ReflectionContext, AssemblyCatalog> catalogCreator)
162144
{
163-
AssertExtensions.Throws<ArgumentNullException>("reflectionContext", () =>
164-
{
165-
var catalog = catalogCreator(null);
166-
});
145+
AssertExtensions.Throws<ArgumentNullException>("reflectionContext", () => catalogCreator(null));
167146
}
168147

169148
public static void Constructor_NullDefinitionOriginArgument_ShouldThrowArgumentNull(Func<ICompositionElement, AssemblyCatalog> catalogCreator)
170149
{
171-
AssertExtensions.Throws<ArgumentNullException>("definitionOrigin", () =>
172-
{
173-
var catalog = catalogCreator(null);
174-
});
150+
AssertExtensions.Throws<ArgumentNullException>("definitionOrigin", () => catalogCreator(null));
175151
}
176152

177153
//=========================================================================================================================================
@@ -215,15 +191,26 @@ public void Constructor1_EmptyFileNameAsCodeBaseArgument_ShouldThrowArgument()
215191
}
216192

217193
[Fact]
218-
[ActiveIssue(25498, TestPlatforms.AnyUnix)]
219-
public void Constructor1_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument()
194+
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
195+
public void Constructor1_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument_Desktop()
220196
{
221197
AssemblyCatalogConstructorTests.Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument((s) =>
222198
{
223199
return new AssemblyCatalog(s);
224200
});
225201
}
226202

203+
[Fact]
204+
[ActiveIssue(25498)] // Also see https://github.com/dotnet/corefx/issues/27269
205+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
206+
public void Constructor1_InvalidFileNameAsCodeBaseArgument_ShouldThrowIO_Core()
207+
{
208+
AssemblyCatalogConstructorTests.Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowIO((s) =>
209+
{
210+
return new AssemblyCatalog(s);
211+
});
212+
}
213+
227214
[Fact]
228215
[ActiveIssue(25498)]
229216
public void Constructor1_DirectoryAsCodeBaseArgument_ShouldThrowFileLoad()
@@ -314,15 +301,26 @@ public void Constructor2_EmptyFileNameAsCodeBaseArgument_ShouldThrowArgument()
314301
}
315302

316303
[Fact]
317-
[ActiveIssue(25498, TestPlatforms.AnyUnix)]
318-
public void Constructor2_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument()
304+
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
305+
public void Constructor2_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument_Desktop()
319306
{
320307
AssemblyCatalogConstructorTests.Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument((s) =>
321308
{
322309
return new AssemblyCatalog(s, new AssemblyCatalogTestsReflectionContext());
323310
});
324311
}
325312

313+
[Fact]
314+
[ActiveIssue(25498)] // Also see https://github.com/dotnet/corefx/issues/27269
315+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
316+
public void Constructor2_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument()
317+
{
318+
AssemblyCatalogConstructorTests.Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowIO((s) =>
319+
{
320+
return new AssemblyCatalog(s, new AssemblyCatalogTestsReflectionContext());
321+
});
322+
}
323+
326324
[Fact]
327325
[ActiveIssue(25498)]
328326
public void Constructor2_DirectoryAsCodeBaseArgument_ShouldThrowFileLoad()
@@ -412,7 +410,7 @@ public void Constructor3_EmptyFileNameAsCodeBaseArgument_ShouldThrowArgument()
412410
}
413411

414412
[Fact]
415-
[ActiveIssue(25498, TestPlatforms.AnyUnix)]
413+
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
416414
public void Constructor3_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument()
417415
{
418416
AssemblyCatalogConstructorTests.Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument((s) =>
@@ -421,6 +419,17 @@ public void Constructor3_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument()
421419
});
422420
}
423421

422+
[Fact]
423+
[ActiveIssue(25498)] // // Also see https://github.com/dotnet/corefx/issues/27269
424+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
425+
public void Constructor3_InvalidFileNameAsCodeBaseArgument_ShouldThrowIO_Core()
426+
{
427+
AssemblyCatalogConstructorTests.Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowIO((s) =>
428+
{
429+
return new AssemblyCatalog(s, (ICompositionElement)new AssemblyCatalog(s));
430+
});
431+
}
432+
424433
[Fact]
425434
[ActiveIssue(25498)]
426435
public void Constructor3_DirectoryAsCodeBaseArgument_ShouldThrowFileLoad()
@@ -509,15 +518,26 @@ public void Constructor4_EmptyFileNameAsCodeBaseArgument_ShouldThrowArgument()
509518
}
510519

511520
[Fact]
512-
[ActiveIssue(25498, TestPlatforms.AnyUnix)]
513-
public void Constructor4_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument()
521+
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
522+
public void Constructor4_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument_Desktop()
514523
{
515524
AssemblyCatalogConstructorTests.Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowArgument((s) =>
516525
{
517526
return new AssemblyCatalog(s, new AssemblyCatalogTestsReflectionContext(), (ICompositionElement)new AssemblyCatalog(s));
518527
});
519528
}
520529

530+
[Fact]
531+
[ActiveIssue(25498)] // Also see https://github.com/dotnet/corefx/issues/27269
532+
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework)]
533+
public void Constructor4_InvalidFileNameAsCodeBaseArgument_ShouldThrowIO_Core()
534+
{
535+
AssemblyCatalogConstructorTests.Constructor_InvalidFileNameAsCodeBaseArgument_ShouldThrowIO((s) =>
536+
{
537+
return new AssemblyCatalog(s, new AssemblyCatalogTestsReflectionContext(), (ICompositionElement)new AssemblyCatalog(s));
538+
});
539+
}
540+
521541
[Fact]
522542
[ActiveIssue(25498)]
523543
public void Constructor4_DirectoryAsCodeBaseArgument_ShouldThrowFileLoad()
@@ -780,10 +800,7 @@ public void GetExports_WhenCatalogDisposed_ShouldThrowObjectDisposed()
780800
catalog.Dispose();
781801
var definition = ImportDefinitionFactory.Create();
782802

783-
ExceptionAssert.ThrowsDisposed(catalog, () =>
784-
{
785-
catalog.GetExports(definition);
786-
});
803+
ExceptionAssert.ThrowsDisposed(catalog, () => catalog.GetExports(definition));
787804
}
788805

789806
[Fact]
@@ -792,10 +809,7 @@ public void GetExports_NullAsConstraintArgument_ShouldThrowArgumentNull()
792809
{
793810
var catalog = CreateAssemblyCatalog();
794811

795-
AssertExtensions.Throws<ArgumentNullException>("definition", () =>
796-
{
797-
catalog.GetExports((ImportDefinition)null);
798-
});
812+
AssertExtensions.Throws<ArgumentNullException>("definition", () => catalog.GetExports(null));
799813
}
800814

801815
[Fact]

src/System.ComponentModel.Composition/tests/System/ComponentModel/Composition/Hosting/DirectoryCatalogTests.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -228,16 +228,6 @@ public void Dispose_CanBeCalledMultipleTimes()
228228
catalog.Dispose();
229229
}
230230

231-
[Fact]
232-
[ActiveIssue(25498, TestPlatforms.AnyUnix)] // typeof(System.IO.DirectoryNotFoundException): Could not find a part of the path '/HOME/HELIXBOT/DOTNETBUILD/WORK/E77C2FB6-5244-4437-8E27-6DD709101152/WORK/D9EBA0EA-A511-4F42-AC8B-AC8054AAF606/UNZIP/HTTP:/MICROSOFT.COM/MYASSEMBLY.DLL'.
233-
public void AddAssembly1_NonExistentUriAsAssemblyFileNameArgument_ShouldNotSupportedException()
234-
{
235-
Assert.Throws<NotSupportedException>(() =>
236-
{
237-
var catalog = new DirectoryCatalog("http://microsoft.com/myassembly.dll");
238-
});
239-
}
240-
241231
[Fact]
242232
public void AddAssembly1_NullPathArgument_ShouldThrowArugmentNull()
243233
{
@@ -252,16 +242,6 @@ public void AddAssembly1_EmptyPathArgument_ShouldThrowArugment()
252242
new DirectoryCatalog(""));
253243
}
254244

255-
[Fact]
256-
[ActiveIssue(25498, TestPlatforms.AnyUnix)] // typeof(System.IO.DirectoryNotFoundException): Could not find a part of the path '/HOME/HELIXBOT/DOTNETBUILD/WORK/E77C2FB6-5244-4437-8E27-6DD709101152/WORK/D9EBA0EA-A511-4F42-AC8B-AC8054AAF606/UNZIP/*'.
257-
public void AddAssembly1_InvalidPathName_ShouldThrowDirectoryNotFound()
258-
{
259-
Assert.Throws<ArgumentException>(() =>
260-
{
261-
var c1 = new DirectoryCatalog("*");
262-
});
263-
}
264-
265245
[Fact]
266246
[ActiveIssue(25498)]
267247
public void AddAssembly1_TooLongPathNameArgument_ShouldThrowPathTooLongException()

src/System.Drawing.Common/tests/Imaging/MetafileTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static IEnumerable<object[]> InvalidPath_TestData()
9090

9191
[ActiveIssue(20884, TestPlatforms.AnyUnix)]
9292
[ConditionalTheory(Helpers.GdiplusIsAvailable)]
93-
[InlineData(@"fileNo*-//\\#@(found")]
93+
[InlineData("bad\0name")]
9494
[InlineData("")]
9595
public void Ctor_InvalidPath_ThrowsArgumentException(string path)
9696
{
@@ -464,7 +464,7 @@ public void Ctor_NullPath_ThrowsArgumentNullException()
464464

465465
[ActiveIssue(20884, TestPlatforms.AnyUnix)]
466466
[ConditionalTheory(Helpers.GdiplusIsAvailable)]
467-
[InlineData(@"fileNo*-//\\#@(found")]
467+
[InlineData("bad\0path")]
468468
[InlineData("")]
469469
public void Ctor_InvalidPathI_ThrowsArgumentException(string fileName)
470470
{
@@ -749,7 +749,7 @@ public void Ctor_NullPathI_ThrowsArgumentNullException()
749749

750750
[ActiveIssue(20884, TestPlatforms.AnyUnix)]
751751
[ConditionalTheory(Helpers.GdiplusIsAvailable)]
752-
[InlineData(@"fileNo*-//\\#@(found")]
752+
[InlineData("bad\0path")]
753753
[InlineData("")]
754754
public void Ctor_InvalidPathII_ThrowsArgumentException(string fileName)
755755
{
@@ -940,7 +940,7 @@ public void Static_GetMetafileHeader_IntPtr_ThrowsArgumentException()
940940

941941
[ActiveIssue(20884, TestPlatforms.AnyUnix)]
942942
[ConditionalTheory(Helpers.GdiplusIsAvailable)]
943-
[InlineData(@"fileNo*-//\\#@(found")]
943+
[InlineData("bad\0path")]
944944
[InlineData("")]
945945
public void Static_GetMetafileHeader_InvalidPath_ThrowsArgumentException(string fileName)
946946
{

src/System.IO.Compression.ZipFile/tests/ZipFileInvalidFileTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ public void Unix_ZipWithOSSpecificFileNames(string zipName, string fileName)
243243
/// when an attempt is made to extract them.
244244
/// </summary>
245245
[Theory]
246+
[ActiveIssue(27269)]
246247
[InlineData("WindowsInvalid_FromUnix", null)]
247248
[InlineData("WindowsInvalid_FromWindows", null)]
248249
[InlineData("NullCharFileName_FromWindows", "path")]

src/System.IO.FileSystem.DriveInfo/tests/DriveInfo.Windows.Tests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class DriveInfoWindowsTests
2929
[InlineData(@"\\share", null)]
3030
[InlineData(@"\\", null)]
3131
[InlineData("c ", null)]
32-
[InlineData("", "path")]
32+
// [InlineData("", "path")] // https://github.com/dotnet/corefx/issues/27269
3333
[InlineData(" c", null)]
3434
public void Ctor_InvalidPath_ThrowsArgumentException(string driveName, string paramName)
3535
{

src/System.IO.FileSystem/src/System/IO/DirectoryInfo.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ private void Init(string originalPath, string fullPath = null, string fileName =
2929
OriginalPath = originalPath ?? throw new ArgumentNullException("path");
3030

3131
fullPath = fullPath ?? originalPath;
32-
Debug.Assert(!isNormalized || !PathInternal.IsPartiallyQualified(fullPath), $"'{fullPath}' should be fully qualified if normalized");
3332
fullPath = isNormalized ? fullPath : Path.GetFullPath(fullPath);
3433

3534
_name = fileName ?? (PathHelpers.IsRoot(fullPath) ?

src/System.IO.FileSystem/src/System/IO/FileSystemInfo.Unix.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Diagnostics;
6+
57
namespace System.IO
68
{
79
partial class FileSystemInfo
@@ -19,6 +21,8 @@ internal static unsafe FileSystemInfo Create(string fullPath, string fileName, r
1921
? (FileSystemInfo)new DirectoryInfo(fullPath, fileName: fileName, isNormalized: true)
2022
: new FileInfo(fullPath, fileName: fileName, isNormalized: true);
2123

24+
Debug.Assert(!PathInternal.IsPartiallyQualified(fullPath), $"'{fullPath}' should be fully qualified when constructed from directory enumeration");
25+
2226
info.Init(ref fileStatus);
2327
return info;
2428
}

src/System.IO.FileSystem/src/System/IO/FileSystemInfo.Windows.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5+
using System.Diagnostics;
56
using System.IO.Enumeration;
67

78
namespace System.IO
@@ -27,6 +28,8 @@ internal static unsafe FileSystemInfo Create(string fullPath, ref FileSystemEntr
2728
? (FileSystemInfo) new DirectoryInfo(fullPath, fileName: new string(findData.FileName), isNormalized: true)
2829
: new FileInfo(fullPath, fileName: new string(findData.FileName), isNormalized: true);
2930

31+
Debug.Assert(!PathInternal.IsPartiallyQualified(fullPath), $"'{fullPath}' should be fully qualified when constructed from directory enumeration");
32+
3033
info.Init(findData._info);
3134
return info;
3235
}

0 commit comments

Comments
 (0)