Skip to content

Commit

Permalink
Merge pull request #1109 from hcoles/feature/relax_filename_checl
Browse files Browse the repository at this point in the history
Relax source file attribute check
  • Loading branch information
hcoles committed Nov 11, 2022
2 parents d151089 + 347dde1 commit f043493
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import java.util.Collection;
import java.util.function.Consumer;
import java.util.List;
import java.util.function.Predicate;

import org.pitest.classinfo.ClassInfo;
Expand All @@ -29,11 +29,11 @@ public class DefaultBuildVerifier implements BuildVerifier {

@Override
public void verify(final CodeSource code) {
final Collection<ClassInfo> codeClasses = FCollection.filter(code.getCode(), isNotSynthetic());
final List<ClassInfo> codeClasses = FCollection.filter(code.getCode(), isNotSynthetic());

if (hasMutableCode(codeClasses)) {
checkAtLeastOneClassHasLineNumbers(codeClasses);
codeClasses.forEach(throwErrorIfHasNoSourceFile());
checkAtLeastOneClassHasSourceFile(codeClasses);
}
}

Expand All @@ -54,6 +54,14 @@ private void checkAtLeastOneClassHasLineNumbers(
}
}

private void checkAtLeastOneClassHasSourceFile(List<ClassInfo> codeClasses) {
// perform only a weak check for line numbers as
// some jvm languages are not guaranteed to include a source file for all classes
if (!FCollection.contains(codeClasses, a -> a.getSourceFileName() != null)) {
throw new PitHelpError(Help.NO_SOURCE_FILE, codeClasses.get(0).getName().asJavaName());
}
}

private static Predicate<ClassInfo> aConcreteClass() {
return a -> !a.isInterface();
}
Expand All @@ -62,14 +70,6 @@ private static Predicate<ClassInfo> aClassWithLineNumbers() {
return a -> a.getNumberOfCodeLines() != 0;
}

private Consumer<ClassInfo> throwErrorIfHasNoSourceFile() {
return a -> {
if (a.getSourceFileName() == null) {
throw new PitHelpError(Help.NO_SOURCE_FILE, a.getName().asJavaName());
}
};
}

private static Predicate<ClassInfo> isNotSynthetic() {
return a -> !a.isSynthetic();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package org.pitest.mutationtest.verify;

import static org.assertj.core.api.Assertions.assertThatCode;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -105,6 +106,12 @@ public void shouldNotThrowAnErrorWhenOnlyInterfacesPresent() {
}
}

@Test
public void doesNotErrorWhenNoClassesProvided() {
when(this.code.getCode()).thenReturn(Collections.emptyList());
assertThatCode(() -> this.testee.verify(this.code)).doesNotThrowAnyException();
}

private void setupClassPath(final Class<?> clazz) {
this.setupClassPath(
new ClassloaderByteArraySource(IsolationUtils.getContextClassLoader()),
Expand Down

0 comments on commit f043493

Please sign in to comment.