diff options
| author | cvs2svn <admin@example.com> | 2025-08-02 06:16:35 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2025-08-02 06:16:35 +0000 |
| commit | a397c95f8aea58533e72379d6e0de12683ecd0dc (patch) | |
| tree | 45ccaccd0ce2ea01650f0a9f5e9268a656e17e51 /src/regress/lib/libc/getopt | |
| parent | a79e90e7342954ae2287db505811ca3c1cd336d7 (diff) | |
| download | openbsd-tb_20250802.tar.gz openbsd-tb_20250802.tar.bz2 openbsd-tb_20250802.zip | |
This commit was manufactured by cvs2git to create tag 'tb_20250802'.tb_20250802
Diffstat (limited to 'src/regress/lib/libc/getopt')
| -rw-r--r-- | src/regress/lib/libc/getopt/Makefile | 10 | ||||
| -rw-r--r-- | src/regress/lib/libc/getopt/getopt-test.c | 59 | ||||
| -rw-r--r-- | src/regress/lib/libc/getopt/getopt.sh | 136 |
3 files changed, 0 insertions, 205 deletions
diff --git a/src/regress/lib/libc/getopt/Makefile b/src/regress/lib/libc/getopt/Makefile deleted file mode 100644 index bdafc965fe..0000000000 --- a/src/regress/lib/libc/getopt/Makefile +++ /dev/null | |||
| @@ -1,10 +0,0 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.1 2020/03/23 03:01:21 schwarze Exp $ | ||
| 2 | |||
| 3 | REGRESS_TARGETS = getopt | ||
| 4 | PROG = getopt-test | ||
| 5 | MAN = | ||
| 6 | |||
| 7 | getopt: ${PROG} | ||
| 8 | sh ${.CURDIR}/getopt.sh | ||
| 9 | |||
| 10 | .include <bsd.regress.mk> | ||
diff --git a/src/regress/lib/libc/getopt/getopt-test.c b/src/regress/lib/libc/getopt/getopt-test.c deleted file mode 100644 index 40901dcfcf..0000000000 --- a/src/regress/lib/libc/getopt/getopt-test.c +++ /dev/null | |||
| @@ -1,59 +0,0 @@ | |||
| 1 | /* $OpenBSD: getopt-test.c,v 1.1 2020/03/23 03:01:21 schwarze Exp $ */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | #include <stdio.h> | ||
| 18 | #include <stdlib.h> | ||
| 19 | #include <unistd.h> | ||
| 20 | |||
| 21 | /* | ||
| 22 | * Process command line options and arguments according to the | ||
| 23 | * optstring in the environment variable OPTS. Write: | ||
| 24 | * OPT(c) for an option "-c" without an option argument | ||
| 25 | * OPT(carg) for an option "-c" with an option argument "arg" | ||
| 26 | * ARG(arg) for a non-option argument "arg" | ||
| 27 | * NONE(arg) for a non-option argument "arg" processed with OPTS =~ ^- | ||
| 28 | * ERR(?c) for an invalid option "-c", or one lacking an argument | ||
| 29 | * ERR(:c) for an option "-c" lacking an argument while OPTS =~ ^: | ||
| 30 | */ | ||
| 31 | int | ||
| 32 | main(int argc, char *argv[]) | ||
| 33 | { | ||
| 34 | char *optstring; | ||
| 35 | int ch; | ||
| 36 | |||
| 37 | if ((optstring = getenv("OPTS")) == NULL) | ||
| 38 | optstring = ""; | ||
| 39 | |||
| 40 | opterr = 0; | ||
| 41 | while ((ch = getopt(argc, argv, optstring)) != -1) { | ||
| 42 | switch (ch) { | ||
| 43 | case '\1': | ||
| 44 | printf("NONE(%s)", optarg); | ||
| 45 | break; | ||
| 46 | case ':': | ||
| 47 | case '?': | ||
| 48 | printf("ERR(%c%c)", ch, optopt); | ||
| 49 | break; | ||
| 50 | default: | ||
| 51 | printf("OPT(%c%s)", ch, optarg == NULL ? "" : optarg); | ||
| 52 | break; | ||
| 53 | } | ||
| 54 | } | ||
| 55 | while (optind < argc) | ||
| 56 | printf("ARG(%s)", argv[optind++]); | ||
| 57 | putchar('\n'); | ||
| 58 | return 0; | ||
| 59 | } | ||
diff --git a/src/regress/lib/libc/getopt/getopt.sh b/src/regress/lib/libc/getopt/getopt.sh deleted file mode 100644 index 6e02163d5b..0000000000 --- a/src/regress/lib/libc/getopt/getopt.sh +++ /dev/null | |||
| @@ -1,136 +0,0 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # $OpenBSD: getopt.sh,v 1.2 2020/05/27 22:32:22 schwarze Exp $ | ||
| 4 | # | ||
| 5 | # Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org> | ||
| 6 | # | ||
| 7 | # Permission to use, copy, modify, and distribute this software for any | ||
| 8 | # purpose with or without fee is hereby granted, provided that the above | ||
| 9 | # copyright notice and this permission notice appear in all copies. | ||
| 10 | # | ||
| 11 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 12 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 13 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 14 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 15 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 16 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 17 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 18 | |||
| 19 | # Run ./getopt-test once. | ||
| 20 | # Function arguments: | ||
| 21 | # 1. optstring argument for getopt(3) | ||
| 22 | # 2. space-separated command line arguments | ||
| 23 | # 3. expected output from ./getopt-test | ||
| 24 | test1_getopt() | ||
| 25 | { | ||
| 26 | result=$(OPTS=$1 ./getopt-test $2) | ||
| 27 | test "$result" == "$3" && return | ||
| 28 | echo "OPTS=$1 ./getopt-test $2" | ||
| 29 | echo "expected: $3" | ||
| 30 | echo "result: $result" | ||
| 31 | irc=1 | ||
| 32 | } | ||
| 33 | |||
| 34 | # Test both without and with the optstring modifier "+", | ||
| 35 | # verifying that it makes no difference. | ||
| 36 | test2_getopt() | ||
| 37 | { | ||
| 38 | test1_getopt "$1" "$2" "$3" | ||
| 39 | test1_getopt "+$1" "$2" "$3" | ||
| 40 | } | ||
| 41 | |||
| 42 | # Also test with the GNU "-" optstring modifier, | ||
| 43 | # veryfying that it only changes ARG() to NONE(). | ||
| 44 | # This test function is inadequate in two situations: | ||
| 45 | # a) options follow non-option arguments that terminate option processing | ||
| 46 | # b) or any arguments follow explicit "--". | ||
| 47 | # In these cases, use test2_getopt() plus a separate test1_getopt(-...). | ||
| 48 | test3_getopt() | ||
| 49 | { | ||
| 50 | test2_getopt "$1" "$2" "$3" | ||
| 51 | test1_getopt "-$1" "$2" $(echo $3 | sed s/ARG/NONE/g) | ||
| 52 | } | ||
| 53 | |||
| 54 | irc=0 | ||
| 55 | |||
| 56 | # valid isolated options without arguments | ||
| 57 | test3_getopt ax '-a -x arg' 'OPT(a)OPT(x)ARG(arg)' | ||
| 58 | test3_getopt x- '- -x arg' 'OPT(-)OPT(x)ARG(arg)' | ||
| 59 | |||
| 60 | # invalid isolated options without arguments | ||
| 61 | test3_getopt ax '-a -y arg' 'OPT(a)ERR(?y)ARG(arg)' | ||
| 62 | test1_getopt :ax '-a -y arg' 'OPT(a)ERR(?y)ARG(arg)' | ||
| 63 | test2_getopt x '- -x arg' 'ARG(-)ARG(-x)ARG(arg)' | ||
| 64 | test1_getopt -x '- -x arg' 'NONE(-)OPT(x)NONE(arg)' | ||
| 65 | test3_getopt a- '-a - -x arg' 'OPT(a)OPT(-)ERR(?x)ARG(arg)' | ||
| 66 | test1_getopt :a- '-a - -x arg' 'OPT(a)OPT(-)ERR(?x)ARG(arg)' | ||
| 67 | |||
| 68 | # valid grouped options without arguments | ||
| 69 | test3_getopt ax '-ax arg' 'OPT(a)OPT(x)ARG(arg)' | ||
| 70 | test3_getopt ax- '-a- -x arg' 'OPT(a)OPT(-)OPT(x)ARG(arg)' | ||
| 71 | test3_getopt abx- '-a-b -x arg' 'OPT(a)OPT(-)OPT(b)OPT(x)ARG(arg)' | ||
| 72 | test3_getopt ax- '--a -x arg' 'OPT(-)OPT(a)OPT(x)ARG(arg)' | ||
| 73 | |||
| 74 | # invalid grouped options without arguments | ||
| 75 | test3_getopt ax '-ay arg' 'OPT(a)ERR(?y)ARG(arg)' | ||
| 76 | test1_getopt :ax '-ay arg' 'OPT(a)ERR(?y)ARG(arg)' | ||
| 77 | test3_getopt ax '-a- -x arg' 'OPT(a)ERR(?-)OPT(x)ARG(arg)' | ||
| 78 | test1_getopt :ax '-a- -x arg' 'OPT(a)ERR(?-)OPT(x)ARG(arg)' | ||
| 79 | test3_getopt abx '-a-b -x arg' 'OPT(a)ERR(?-)OPT(b)OPT(x)ARG(arg)' | ||
| 80 | test1_getopt :abx '-a-b -x arg' 'OPT(a)ERR(?-)OPT(b)OPT(x)ARG(arg)' | ||
| 81 | test3_getopt ax '--a -x arg' 'ERR(?-)OPT(a)OPT(x)ARG(arg)' | ||
| 82 | test1_getopt :ax '--a -x arg' 'ERR(?-)OPT(a)OPT(x)ARG(arg)' | ||
| 83 | |||
| 84 | # non-option arguments terminating option processing | ||
| 85 | test2_getopt ax '-a arg -x' 'OPT(a)ARG(arg)ARG(-x)' | ||
| 86 | test1_getopt -ax '-a arg1 -x arg2' 'OPT(a)NONE(arg1)OPT(x)NONE(arg2)' | ||
| 87 | test2_getopt ax '-a -- -x' 'OPT(a)ARG(-x)' | ||
| 88 | test1_getopt -ax '-a -- -x' 'OPT(a)ARG(-x)' | ||
| 89 | test2_getopt ax '-a - -x' 'OPT(a)ARG(-)ARG(-x)' | ||
| 90 | test1_getopt -ax '-a - -x arg' 'OPT(a)NONE(-)OPT(x)NONE(arg)' | ||
| 91 | |||
| 92 | # the ':' option never works | ||
| 93 | test1_getopt ::a '-:a arg' 'ERR(?:)OPT(a)ARG(arg)' | ||
| 94 | test1_getopt :::a '-: arg -a' 'ERR(?:)ARG(arg)ARG(-a)' | ||
| 95 | |||
| 96 | # isolated options with arguments | ||
| 97 | test3_getopt o: '-o' 'ERR(?o)' | ||
| 98 | test1_getopt :o: '-o' 'ERR(:o)' | ||
| 99 | test3_getopt o-: '-' 'ERR(?-)' | ||
| 100 | test1_getopt :-: '-' 'ERR(:-)' | ||
| 101 | test3_getopt o:x '-o arg -x arg' 'OPT(oarg)OPT(x)ARG(arg)' | ||
| 102 | test3_getopt o:x '-oarg -x arg' 'OPT(oarg)OPT(x)ARG(arg)' | ||
| 103 | test3_getopt o::x '-oarg -x arg' 'OPT(oarg)OPT(x)ARG(arg)' | ||
| 104 | test2_getopt o::x '-o arg -x' 'OPT(o)ARG(arg)ARG(-x)' | ||
| 105 | test1_getopt -o::x '-o arg1 -x arg2' 'OPT(o)NONE(arg1)OPT(x)NONE(arg2)' | ||
| 106 | test3_getopt o:x '-o -x arg' 'OPT(o-x)ARG(arg)' | ||
| 107 | test3_getopt o:x '-o -- -x arg' 'OPT(o--)OPT(x)ARG(arg)' | ||
| 108 | test3_getopt x-: '- arg -x arg' 'OPT(-arg)OPT(x)ARG(arg)' | ||
| 109 | test3_getopt x-: '--arg -x arg' 'OPT(-arg)OPT(x)ARG(arg)' | ||
| 110 | test3_getopt x-:: '--arg -x arg' 'OPT(-arg)OPT(x)ARG(arg)' | ||
| 111 | test2_getopt x-:: '- arg -x' 'OPT(-)ARG(arg)ARG(-x)' | ||
| 112 | test1_getopt --::x '- arg1 -x arg2' 'OPT(-)NONE(arg1)OPT(x)NONE(arg2)' | ||
| 113 | test3_getopt x-: '- -x arg' 'OPT(--x)ARG(arg)' | ||
| 114 | test3_getopt x-: '- -- -x arg' 'OPT(---)OPT(x)ARG(arg)' | ||
| 115 | |||
| 116 | # grouped options with arguments | ||
| 117 | test3_getopt ao: '-ao' 'OPT(a)ERR(?o)' | ||
| 118 | test1_getopt :ao: '-ao' 'OPT(a)ERR(:o)' | ||
| 119 | test3_getopt a-: '-a-' 'OPT(a)ERR(?-)' | ||
| 120 | test1_getopt :a-: '-a-' 'OPT(a)ERR(:-)' | ||
| 121 | test3_getopt ao:x '-ao arg -x arg' 'OPT(a)OPT(oarg)OPT(x)ARG(arg)' | ||
| 122 | test3_getopt ao:x '-aoarg -x arg' 'OPT(a)OPT(oarg)OPT(x)ARG(arg)' | ||
| 123 | test3_getopt ao::x '-aoarg -x arg' 'OPT(a)OPT(oarg)OPT(x)ARG(arg)' | ||
| 124 | test2_getopt ao::x '-ao arg -x' 'OPT(a)OPT(o)ARG(arg)ARG(-x)' | ||
| 125 | test1_getopt -ao::x '-ao arg1 -x arg2' 'OPT(a)OPT(o)NONE(arg1)OPT(x)NONE(arg2)' | ||
| 126 | test3_getopt ao:x '-ao -x arg' 'OPT(a)OPT(o-x)ARG(arg)' | ||
| 127 | test3_getopt ao:x '-ao -- -x arg' 'OPT(a)OPT(o--)OPT(x)ARG(arg)' | ||
| 128 | test3_getopt a-:x '-a- arg -x arg' 'OPT(a)OPT(-arg)OPT(x)ARG(arg)' | ||
| 129 | test3_getopt a-:x '-a-arg -x arg' 'OPT(a)OPT(-arg)OPT(x)ARG(arg)' | ||
| 130 | test3_getopt a-::x '-a-arg -x arg' 'OPT(a)OPT(-arg)OPT(x)ARG(arg)' | ||
| 131 | test2_getopt a-::x '-a- arg -x' 'OPT(a)OPT(-)ARG(arg)ARG(-x)' | ||
| 132 | test1_getopt -a-::x '-a- arg1 -x arg2' 'OPT(a)OPT(-)NONE(arg1)OPT(x)NONE(arg2)' | ||
| 133 | test3_getopt a-:x '-a- -x arg' 'OPT(a)OPT(--x)ARG(arg)' | ||
| 134 | test3_getopt a-:x '-a- -- -x arg' 'OPT(a)OPT(---)OPT(x)ARG(arg)' | ||
| 135 | |||
| 136 | exit $irc | ||
