1*63d4e48fSSadaf Ebrahimi#! /bin/sh 2*63d4e48fSSadaf Ebrahimi# vim:et:ft=sh:sts=2:sw=2 3*63d4e48fSSadaf Ebrahimi# 4*63d4e48fSSadaf Ebrahimi# shFlags unit test for Issue #57. 5*63d4e48fSSadaf Ebrahimi# https://github.com/kward/shflags/issues/57 6*63d4e48fSSadaf Ebrahimi# 7*63d4e48fSSadaf Ebrahimi# Copyright 2023 Kate Ward. All Rights Reserved. 8*63d4e48fSSadaf Ebrahimi# Released under the Apache 2.0 license. 9*63d4e48fSSadaf Ebrahimi# 10*63d4e48fSSadaf Ebrahimi# Author: [email protected] (Kate Ward) 11*63d4e48fSSadaf Ebrahimi# https://github.com/kward/shflags 12*63d4e48fSSadaf Ebrahimi# 13*63d4e48fSSadaf Ebrahimi### ShellCheck (http://www.shellcheck.net/) 14*63d4e48fSSadaf Ebrahimi# Disable source following. 15*63d4e48fSSadaf Ebrahimi# shellcheck disable=SC1090,SC1091 16*63d4e48fSSadaf Ebrahimi# $() are not fully portable (POSIX != portable). 17*63d4e48fSSadaf Ebrahimi# shellcheck disable=SC2006 18*63d4e48fSSadaf Ebrahimi 19*63d4e48fSSadaf Ebrahimi# These variables will be overridden by the test helpers. 20*63d4e48fSSadaf EbrahimireturnF="${TMPDIR:-/tmp}/return" 21*63d4e48fSSadaf EbrahimistdoutF="${TMPDIR:-/tmp}/STDOUT" 22*63d4e48fSSadaf EbrahimistderrF="${TMPDIR:-/tmp}/STDERR" 23*63d4e48fSSadaf Ebrahimi 24*63d4e48fSSadaf Ebrahimi# Load test helpers. 25*63d4e48fSSadaf Ebrahimi. ./shflags_test_helpers 26*63d4e48fSSadaf Ebrahimi 27*63d4e48fSSadaf Ebrahimi# Test proper functionality with 'set -o pipefail' enabled. 28*63d4e48fSSadaf EbrahimitestIssue57() { 29*63d4e48fSSadaf Ebrahimi # shellcheck disable=SC3040 30*63d4e48fSSadaf Ebrahimi set -o pipefail 31*63d4e48fSSadaf Ebrahimi 32*63d4e48fSSadaf Ebrahimi th_clearReturn 33*63d4e48fSSadaf Ebrahimi ( 34*63d4e48fSSadaf Ebrahimi FLAGS -h >"${stdoutF}" 2>"${stderrF}" 35*63d4e48fSSadaf Ebrahimi echo $? >"${returnF}" 36*63d4e48fSSadaf Ebrahimi ) 37*63d4e48fSSadaf Ebrahimi 38*63d4e48fSSadaf Ebrahimi assertFalse \ 39*63d4e48fSSadaf Ebrahimi 'short help request should have returned a false exit code.' \ 40*63d4e48fSSadaf Ebrahimi "$(th_queryReturn)" 41*63d4e48fSSadaf Ebrahimi ( grep 'show this help' "${stderrF}" >/dev/null ) 42*63d4e48fSSadaf Ebrahimi r3turn=$? 43*63d4e48fSSadaf Ebrahimi assertTrue \ 44*63d4e48fSSadaf Ebrahimi 'short request for help should have produced some help output.' \ 45*63d4e48fSSadaf Ebrahimi ${r3turn} 46*63d4e48fSSadaf Ebrahimi [ ${r3turn} -eq "${FLAGS_TRUE}" ] || th_showOutput 47*63d4e48fSSadaf Ebrahimi} 48*63d4e48fSSadaf Ebrahimi 49*63d4e48fSSadaf EbrahimioneTimeSetUp() { 50*63d4e48fSSadaf Ebrahimi th_oneTimeSetUp 51*63d4e48fSSadaf Ebrahimi 52*63d4e48fSSadaf Ebrahimi if flags_getoptIsStd; then 53*63d4e48fSSadaf Ebrahimi th_warn 'Standard version of getopt found. Enhanced tests will be skipped.' 54*63d4e48fSSadaf Ebrahimi return 55*63d4e48fSSadaf Ebrahimi fi 56*63d4e48fSSadaf Ebrahimi th_warn 'Enhanced version of getopt found. Standard tests will be skipped.' 57*63d4e48fSSadaf Ebrahimi} 58*63d4e48fSSadaf Ebrahimi 59*63d4e48fSSadaf EbrahimisetUp() { 60*63d4e48fSSadaf Ebrahimi flags_reset 61*63d4e48fSSadaf Ebrahimi} 62*63d4e48fSSadaf Ebrahimi 63*63d4e48fSSadaf Ebrahimi# Load and run shUnit2. 64*63d4e48fSSadaf Ebrahimi# shellcheck disable=SC2034 65*63d4e48fSSadaf Ebrahimi[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 66*63d4e48fSSadaf Ebrahimi. "${TH_SHUNIT}" 67