#! /bin/sh # vim:et:ft=sh:sts=2:sw=2 # # shFlags unit tests for the internal functions. # # # Copyright 2008-2017 Kate Ward. All Rights Reserved. # Released under the Apache 2.0 license. # # Author: kate.ward@forestent.com (Kate Ward) # https://github.com/kward/shflags # ### ShellCheck (http://www.shellcheck.net/) # Disable source following. # shellcheck disable=SC1090,SC1091 # expr may be antiquated, but it is the only solution in some cases. # shellcheck disable=SC2003 # $() are not fully portable (POSIX != portable). # shellcheck disable=SC2006 # These variables will be overridden by the test helpers. stdoutF="${TMPDIR:-/tmp}/STDOUT" stderrF="${TMPDIR:-/tmp}/STDERR" # Load test helpers. . ./shflags_test_helpers testColumns() { cols=`_flags_columns` value=`expr "${cols}" : '\([0-9]*\)'` assertNotNull "unexpected screen width (${cols})" "${value}" } testGetoptVers() { # shellcheck disable=SC2162 while read desc mock want; do assertEquals "${desc}" "$(_flags_getopt_vers "${mock}")" "${want}" done <"${stdoutF}" 2>"${stderrF}"` assertEquals 'invalid flag did not result in an error' "${FLAGS_ERROR}" $? assertErrorMsg 'missing flag info variable' } testItemInList() { list='this is a test' # shellcheck disable=SC2162 while read desc item want; do _flags_itemInList "${item}" "${list}" got=$? assertEquals "${desc}: itemInList(${item})" "${got}" "${want}" done <