Add capability to only fail when running tests.

This commit is contained in:
Roel Spilker committed 2026-09-09 01:00:56 +02:00
1 parent 2cbf6f766b
commit e50d44b071
2 files changed
+22 -2

No files matched your search

+17 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2025 The Project Lombok Authors.
* Copyright (C) 2013-2026 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -57,6 +58,9 @@ import lombok.experimental.FieldDefaults;
* target platform (e.g. useful for both javac and Eclipse lombok implementations).
*/
public class HandlerUtil {
private static AtomicInteger inTest = new AtomicInteger();
private HandlerUtil() {}
public enum FieldAccess {
@@ -1051,4 +1055,16 @@ public class HandlerUtil {
}
return null;
}
public static void failIfRunningInTest(String message) throws AssertionError {
if (inTest.intValue() != 0) throw new AssertionError("In test: " + message);
}
public static void incrementRunningInTest() {
inTest.incrementAndGet();
}
public static void decrementRunningInTest() {
if (inTest.decrementAndGet() < 0) throw new IllegalStateException();
}
}
+5 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2024 The Project Lombok Authors.
* Copyright (C) 2009-2026 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -34,6 +34,7 @@ import org.junit.runner.Runner;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
import lombok.core.handlers.HandlerUtil;
import lombok.eclipse.Eclipse;
import lombok.javac.Javac;
@@ -170,9 +171,12 @@ public class DirectoryRunner extends Runner {
notifier.fireTestStarted(testDescription);
try {
HandlerUtil.incrementRunningInTest();
tester.runTest();
} catch (Throwable t) {
notifier.fireTestFailure(new Failure(testDescription, t));
} finally {
HandlerUtil.decrementRunningInTest();
}
notifier.fireTestFinished(testDescription);
}