This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-cli.git


The following commit(s) were added to refs/heads/master by this push:
     new 859d5e5e [CLI-343] OptionFormatter.getBothOpt() lacks validation for 
Options without opt or longOpt
859d5e5e is described below

commit 859d5e5e749c1ec6a4c7f7ead88a587f316d8065
Author: Gary D. Gregory <[email protected]>
AuthorDate: Wed Jul 30 08:45:13 2025 -0400

    [CLI-343] OptionFormatter.getBothOpt() lacks validation for Options
    without opt or longOpt
    
    Add tests
---
 .../org/apache/commons/cli/help/OptionFormatterTest.java    | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/src/test/java/org/apache/commons/cli/help/OptionFormatterTest.java 
b/src/test/java/org/apache/commons/cli/help/OptionFormatterTest.java
index c9e041c5..dbb59e3e 100644
--- a/src/test/java/org/apache/commons/cli/help/OptionFormatterTest.java
+++ b/src/test/java/org/apache/commons/cli/help/OptionFormatterTest.java
@@ -17,6 +17,7 @@
 package org.apache.commons.cli.help;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -132,6 +133,18 @@ class OptionFormatterTest {
         assertEquals("[-ot <arg>]", underTest.toSyntaxOption(), "optional 
multi char opt arg failed");
     }
 
+    @Test
+    void testCli343Part1() {
+        assertThrows(IllegalStateException.class, () -> 
Option.builder().required(false).build());
+        assertThrows(IllegalStateException.class, () -> 
Option.builder().required(false).get());
+    }
+
+    @Test
+    void testCli343Part2() {
+        assertThrows(IllegalStateException.class, () -> 
Option.builder().desc("description").build());
+        assertThrows(IllegalStateException.class, () -> 
Option.builder().desc("description").get());
+    }
+
     @ParameterizedTest(name = "{index} {0}")
     @MethodSource("deprecatedAttributesData")
     void testComplexDeprecationFormat(final DeprecatedAttributes da, final 
String expected) {

Reply via email to