#! /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. setvar stdoutF = ""${TMPDIR:-/tmp}/STDOUT"" setvar stderrF = ""${TMPDIR:-/tmp}/STDERR"" # Load test helpers. source ./shflags_test_helpers proc testColumns { setvar cols = $(_flags_columns) setvar value = $(expr ${cols} : '\([0-9]*\)) assertNotNull "unexpected screen width (${cols})" ${value} } proc testGetoptVers { # shellcheck disable=SC2162 while read desc mock want { assertEquals ${desc} $(_flags_getopt_vers "${mock}") ${want} } <"${stdoutF}" ) assertEquals 'invalid flag did not result in an error' ${FLAGS_ERROR} $? assertErrorMsg 'missing flag info variable' } proc testItemInList { setvar list = ''this is a test'' # shellcheck disable=SC2162 while read desc item want { _flags_itemInList ${item} ${list} setvar got = ""$? assertEquals "${desc}: itemInList(${item})" ${got} ${want} } <