Skip to content

Commit

Permalink
Merge pull request #193 from cqse/ts/41104_last_segment_not_matching
Browse files Browse the repository at this point in the history
TS-41104 Fix cutting off assembly names
  • Loading branch information
stahlbauer authored Dec 5, 2024
2 parents 9c27fa9 + 190a326 commit 4be04c9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Please prefix each entry with one of:


# Next Release
- [fix] Assembly patterns could not match on full assembly name when using `@AssemblyDir` as PDB directory

# v24.5.1
- [fix] Upload Daemon uploaded to Artifactory in the wrong format
Expand Down
4 changes: 2 additions & 2 deletions UploadDaemon/Configuration/GlobPatternList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private static Regex ConvertGlobPatternToRegex(String pattern)
/// </summary>
public string Describe()
{
return $"include={string.Join(",", includePatterns)} exclude={string.Join(",", excludePatterns)}";
return $"[Pattern include={string.Join(",", includeRegexes)} exclude={string.Join(",", excludeRegexes)}]";
}

/// <summary>
Expand All @@ -82,5 +82,5 @@ public override bool Equals(object other) => other is GlobPatternList otherList

/// <inheritdoc/>
public override int GetHashCode() => (includePatterns, excludePatterns).GetHashCode();
}
}
}
6 changes: 4 additions & 2 deletions UploadDaemon/SymbolAnalysis/SymbolCollectionResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,15 @@ private void UpdateValidationInfo(ICollection<SymbolFileInfo> relevantSymbolFile
private static ICollection<SymbolFileInfo> FindRelevantSymbolFiles(string symbolDirectory, GlobPatternList assemblyPatterns)
{
return new HashSet<SymbolFileInfo>(Directory.EnumerateFiles(symbolDirectory, "*.pdb", SearchOption.AllDirectories)
.Where(file => MatchesAssemblyPattern(assemblyPatterns, file))
.Where(file => MatchesAssemblyPattern(assemblyPatterns, Path.GetFileNameWithoutExtension(file)))
.Select(file => new SymbolFileInfo { Path = file, LastWriteTime = File.GetLastWriteTimeUtc(file) }));
}

private static bool MatchesAssemblyPattern(GlobPatternList assemblyPatterns, string file)
{
return assemblyPatterns.Matches(Path.GetFileNameWithoutExtension(file));
bool isMatch = assemblyPatterns.Matches(file);
logger.Trace("Testing {file} against {assemblyPatterns}: match is {isMatch}", file, assemblyPatterns.Describe(), isMatch);
return isMatch;
}
}
}
4 changes: 2 additions & 2 deletions UploadDaemon_Test/Configuration/ConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public void NotSpecifyingIncludePatternMeansEverythingIsIncluded()
exclude: [ 'Bar' ]
").CreateConfigForProcess("foo.exe");

Assert.That(config.AssemblyPatterns.Describe(), Is.EqualTo("include=* exclude=Bar"));
Assert.That(config.AssemblyPatterns.Describe(), Is.EqualTo("[Pattern include=^.*$ exclude=^Bar$]"));
}

[Test]
Expand All @@ -473,7 +473,7 @@ public void NotSpecifyingExcludePatternMeansDefaultExcludesAreUsed()
include: [ 'Bar' ]
").CreateConfigForProcess("foo.exe");

Assert.That(config.AssemblyPatterns.Describe(), Does.StartWith("include=Bar exclude=").And.Contains("mscorlib"));
Assert.That(config.AssemblyPatterns.Describe(), Does.StartWith("[Pattern include=^Bar$ exclude=").And.Contains("^mscorlib$"));
}

[Test]
Expand Down
32 changes: 26 additions & 6 deletions UploadDaemon_Test/SymbolAnalysis/SymbolCollectionResolverTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
namespace UploadDaemon.SymbolAnalysis
{
[TestFixture]
class SymbolCollectionResolverTest
internal class SymbolCollectionResolverTest
{
private static readonly string TestSymbolDirectory = Path.Combine(Path.GetTempPath(), TestUtils.SolutionRoot.FullName, TestUtils.GetSanitizedTestClassName());
private static readonly string TestSymbolFilePath = $"{TestSymbolDirectory}\\Some.pdb";
private static readonly string TestSymbolFilePath = $"{TestSymbolDirectory}\\Cqse.Teamscale.Profiler.Commons.pdb";
private static readonly GlobPatternList includeAllAssembliesPattern = new GlobPatternList(new List<string> { "*" }, new List<string> { });

private SymbolCollectionResolver resolver;
Expand All @@ -22,7 +22,7 @@ public void SetUp()
resolver = new SymbolCollectionResolver();

Directory.CreateDirectory(TestSymbolDirectory);
File.Copy($"{TestUtils.TestDataDirectory}\\Some.pdb", TestSymbolFilePath);
File.Copy($"{TestUtils.TestDataDirectory}\\Cqse.Teamscale.Profiler.Commons.pdb", TestSymbolFilePath);
File.SetLastWriteTime(TestSymbolFilePath, new DateTime(2019, 1, 1));
}

Expand All @@ -33,19 +33,39 @@ public void TearDown()
}

[Test]
public void ConsidersSymbolFileIncludes()
public void ConsidersSymbolFileIncludesFromSymbolDirectory()
{
SymbolCollection collection = resolver.ResolveFromSymbolDirectory(TestSymbolDirectory,
new GlobPatternList(new List<string> { "DoesNotExist*" }, new List<string> {}));
new GlobPatternList(new List<string> { "DoesNotExist*" }, new List<string> { }));
Assert.That(collection.IsEmpty, Is.True);

collection = resolver.ResolveFromSymbolDirectory(TestSymbolDirectory,
new GlobPatternList(new List<string> { "Cqse.Teamscale.Profiler.Commons" }, new List<string> { }));
Assert.That(collection.IsEmpty, Is.False);
}

[Test]
public void ConsidersSymbolFileIncludesFromTraceFile()
{
ParsedTraceFile traceFile = new ParsedTraceFile(new string[]
{
$"Assembly=Cqse.Teamscale.Profiler.Commons:2 Version:1.0.0.0 Path:{TestSymbolFilePath}",
}, "cov.txt");

SymbolCollection collection = resolver.ResolveFromTraceFile(traceFile, "@AssemblyDir",
new GlobPatternList(new List<string> { "DoesNotExist*" }, new List<string> { }));
Assert.That(collection.IsEmpty, Is.True);

collection = resolver.ResolveFromTraceFile(traceFile, "@AssemblyDir",
new GlobPatternList(new List<string> { "Cqse.Teamscale.Profiler.Commons" }, new List<string> { }));
Assert.That(collection.IsEmpty, Is.False);
}

[Test]
public void ConsidersSymbolFileExcludes()
{
SymbolCollection collection = resolver.ResolveFromSymbolDirectory(TestSymbolDirectory,
new GlobPatternList(new List<string> { "*" }, new List<string> { "So*" }));
new GlobPatternList(new List<string> { "*" }, new List<string> { "Cq*" }));

Assert.That(collection.IsEmpty, Is.True);
}
Expand Down
Binary file not shown.

0 comments on commit 4be04c9

Please sign in to comment.