Skip to content

Commit

Permalink
Use filenames to compute set of files to publish line coverage for
Browse files Browse the repository at this point in the history
  • Loading branch information
Gautam Korlam committed May 2, 2016
1 parent b704b20 commit 448ffa1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Expand Up @@ -35,11 +35,14 @@
import com.uber.jenkins.phabricator.utils.CommonUtils;
import com.uber.jenkins.phabricator.utils.Logger;

import org.apache.commons.io.FilenameUtils;

import hudson.FilePath;
import hudson.model.AbstractBuild;
import hudson.model.Result;

import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -240,7 +243,19 @@ public void processCoverage(CoverageProvider coverageProvider, Set<String> inclu
return;
}

lineCoverage.keySet().retainAll(include);
Set<String> includeFileNames = new HashSet<String>();
for (String file : include) {
includeFileNames.add(FilenameUtils.getBaseName(file));
}

Set<String> includedLineCoverage = new HashSet<String>();
for (String file : lineCoverage.keySet()) {
if (includeFileNames.contains(FilenameUtils.getBaseName(file))) {
includedLineCoverage.add(file);
}
}

lineCoverage.keySet().retainAll(includedLineCoverage);

harbormasterCoverage = new CoverageConverter().convert(lineCoverage);
}
Expand Down
Expand Up @@ -72,6 +72,14 @@ public void testProcessCoverageWithNoIncludes() throws Exception {
assertNull(processor.getCoverage().get("file.go"));
}

@Test
public void testProcessCoverageWithNonMatchingPathIncludes() throws Exception {
CoverageProvider provider = new FakeCoverageProvider(TestUtils.getDefaultLineCoverage());
processor.processCoverage(provider, Sets.newHashSet("somePath/file.go"));
assertNotNull(processor.getCoverage());
assertEquals("NCUC", processor.getCoverage().get("file.go"));
}

@Test
public void testProcessEmptyCoverage() {
CoverageProvider provider = new FakeCoverageProvider(null);
Expand Down

0 comments on commit 448ffa1

Please sign in to comment.