Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax source file attribute check #1109

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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