From e50d44b071c955d85f7b94a7cf06142c7ff2622b Mon Sep 17 00:00:00 2001 From: Roel Spilker Date: Wed, 9 Sep 2026 01:00:56 +0200 Subject: [PATCH] Add capability to only fail when running tests. --- src/core/lombok/core/handlers/HandlerUtil.java | 18 +++++++++++++++++- test/core/src/lombok/DirectoryRunner.java | 6 +++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java index f9dd3351..ca284946 100644 --- a/src/core/lombok/core/handlers/HandlerUtil.java +++ b/src/core/lombok/core/handlers/HandlerUtil.java @@ -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(); + } } diff --git a/test/core/src/lombok/DirectoryRunner.java b/test/core/src/lombok/DirectoryRunner.java index 1ed46206..eeddb369 100644 --- a/test/core/src/lombok/DirectoryRunner.java +++ b/test/core/src/lombok/DirectoryRunner.java @@ -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); }