From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19794 invoked by alias); 1 Dec 2017 09:39:14 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42065 Received: (qmail 8307 invoked by uid 1010); 1 Dec 2017 09:39:14 -0000 X-Qmail-Scanner-Diagnostics: from mail-it0-f49.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.214.49):SA:0(-1.9/5.0):. Processed in 9.289754 secs); 01 Dec 2017 09:39:14 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ZetRrbuVh6hdA/bbOUu9lf9Asgj8SPUIE2U4xTugTZ8=; b=TWboVwmdK2UBPfHWenfNG/XcB/s9X9iusno72TZIkNrAg/RfygHiGed6+/G6je4Apb UFjasNq5Q1ey6M9UI3Q1/Tgc9ZA6IbFuTtoVPee/tkPofwJn8bUXT3O9S8fpd9wu8XBV pVpH5/Gpr8W4pt+4iVJuyDX/wtCATbBRlP5papC1CCkjv9OwRO2FhYKMvcXzeYFeBl4V eAiwyGfmCLw0NlkbeINFhhOkHwW34fxocjWL/KUmmXJxMg1vC9v9EJMblzi83LgmUI/v b5qoJEu0Y8hGONqKd85my/jN3nb4g2/fXMnZy0gjhc53aIZ3h7LQcKVXoRAP9Gowa9qt 3dxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=ZetRrbuVh6hdA/bbOUu9lf9Asgj8SPUIE2U4xTugTZ8=; b=KmAyVr+a0Nvi1qeM0CyFJP0LdL0cVsBxGUpa2k4iWhPTf/KQE0E35D8TUf7wu1IbAF 8/lMuRQOw6hv1gTP3lFTh7gHuS20rmT4+WS3FtmvfFpsNp5bPOvNCZs6KuyA9NOsdUd5 itcdQZDJmBHyftJLlfptSC0hJn9kk8LLhORBqfRbJhKEaSdFE5MM+d1DqucQ8tV4Y9Ot iYQLI6zyE0PeTBmR7KRH29aTjbsZto0lOv5RfG6QRHneD+tG3o51qNRfVa46Nvj6vthG 4fxD3qMY5tf9YMYdjuHibuBTB3tFSANJ3EbPtgCnXBvIIzDRSdnZUSZnX3ISsSPl8Bm+ r7PA== X-Gm-Message-State: AJaThX5gSDZ9lNP5kMT7f6FRwwV9PGNkc66Jo9QkwA2Y9wzstG5KZP+n SwpbjAdIrF1xjMsZiZliw0qsXfPK36U= X-Google-Smtp-Source: AGs4zMa3yM9lj3Kj6m4mZ24Buf5kCRCdQFXcWsrI5+64+nzpPBxHjlj37liOk9oIMqnSwMqTpuoR6g== X-Received: by 10.36.46.1 with SMTP id i1mr1034641ita.62.1512121141891; Fri, 01 Dec 2017 01:39:01 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: [PATCH] getopts: Accurately report '-x' or '+x' in error messages From: dana In-Reply-To: <20171201092026.269c1dcb@pwslap01u.europe.root.pri> Date: Fri, 1 Dec 2017 03:39:00 -0600 Cc: Peter Stephenson Content-Transfer-Encoding: quoted-printable Message-Id: <2F0DBC74-222A-4B9C-A928-6E1A7B522A0B@dana.is> References: <733779CE-86B9-4178-B38B-7E64390BB4C6@dana.is> <20171201092026.269c1dcb@pwslap01u.europe.root.pri> To: zsh-workers@zsh.org X-Mailer: Apple Mail (2.3273) > Thanks, I've committed this. I'd be happy to add some getopts tests = if > you came up with any. I did actually come up with some, though i'm slightly unsure of their = quality. How do you feel about these? dana diff --git a/Test/B10getopts.ztst b/Test/B10getopts.ztst new file mode 100644 index 000000000..7eba5a4b1 --- /dev/null +++ b/Test/B10getopts.ztst @@ -0,0 +1,81 @@ +# Test the getopts builtin. + +%prep + + test_getopts() { + local OPTARG OPTIND opt + local -a res + while getopts abc: opt 2>&1; do + [[ $opt =3D=3D [?:] ]] || res+=3D( $opt ) + done + (( $#res )) && print -r -- $res + return $(( $#res ? 0 : 1 )) + } + +%test + + test_getopts +1:no arguments + + test_getopts foo +1:one operand + + test_getopts -a +0:one option +>a + + test_getopts -a foo +0:one option, one operand +>a + + test_getopts -a foo -b +0:one option, two operands, leading hyphen +>a + + test_getopts -ab +0:two options, single argument +>a b + + test_getopts -a -b +0:two options, separate arguments +>a b + + test_getopts -a -b +a +0:three options, + variant +>a b +a + + test_getopts -cx +0:one option with value, single argument +>c + + test_getopts +cx +0:one option with value, single argument, + variant +>+c + + test_getopts -c x +0:one option with value, separate arguments +>c + + test_getopts -acx +0:two options, one with value, single argument +>a c + + test_getopts -ac x +0:two options, one with value, separate arguments +>a c + + test_getopts -c +1:one option missing value +>test_getopts:3: argument expected after -c option + + test_getopts +c +1:one option missing value, + variant +>test_getopts:3: argument expected after +c option + + test_getopts -x +1:one illegal option +>test_getopts:3: bad option: -x + + test_getopts +x +1:one illegal option, + variant +>test_getopts:3: bad option: +x