Skip to content

Commit 76ffde3

Browse files
authored
Improves unexpected packages folder state error (#1304)
Improves unexpected packages folder state error
1 parent 03ff455 commit 76ffde3

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

test/coverlet.integration.tests/BaseTest.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,30 @@ protected BuildConfiguration GetAssemblyBuildConfiguration()
3939

4040
private protected string GetPackageVersion(string filter)
4141
{
42-
if (!Directory.Exists($"../../../../../bin/{GetAssemblyBuildConfiguration()}/Packages"))
42+
string packagesPath = $"../../../../../bin/{GetAssemblyBuildConfiguration()}/Packages";
43+
44+
if (!Directory.Exists(packagesPath))
4345
{
4446
throw new DirectoryNotFoundException("Package directory not found, run 'dotnet pack' on repository root");
4547
}
4648

47-
using Stream pkg = File.OpenRead(Directory.GetFiles($"../../../../../bin/{GetAssemblyBuildConfiguration()}/Packages", filter).Single());
48-
using var reader = new PackageArchiveReader(pkg);
49-
using Stream nuspecStream = reader.GetNuspec();
50-
var manifest = Manifest.ReadFrom(nuspecStream, false);
51-
return manifest.Metadata.Version.OriginalVersion;
49+
var files = Directory.GetFiles(packagesPath, filter).ToList();
50+
if (files.Count == 0)
51+
{
52+
throw new InvalidOperationException($"Could not find any package using filter '{filter}' in folder '{Path.GetFullPath(packagesPath)}'. Make sure 'dotnet pack' was called.");
53+
}
54+
else if (files.Count > 1)
55+
{
56+
throw new InvalidOperationException($"Found more than one package using filter '{filter}' in folder '{Path.GetFullPath(packagesPath)}'. Make sure 'dotnet pack' was only called once.");
57+
}
58+
else
59+
{
60+
using Stream pkg = File.OpenRead(files[0]);
61+
using var reader = new PackageArchiveReader(pkg);
62+
using Stream nuspecStream = reader.GetNuspec();
63+
var manifest = Manifest.ReadFrom(nuspecStream, false);
64+
return manifest.Metadata.Version.OriginalVersion;
65+
}
5266
}
5367

5468
private protected ClonedTemplateProject CloneTemplateProject(bool cleanupOnDispose = true, string testSDKVersion = "16.5.0")

0 commit comments

Comments
 (0)