#! /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. setglobal stdoutF = ""$(TMPDIR:-/tmp)/STDOUT"" setglobal stderrF = ""$(TMPDIR:-/tmp)/STDERR"" # Load test helpers. source ./shflags_test_helpers proc testColumns { setglobal cols = $[_flags_columns] setglobal 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) !2 >$(stderrF)] assertEquals 'invalid flag did not result in an error' $(FLAGS_ERROR) $Status assertErrorMsg 'missing flag info variable' } proc testItemInList { setglobal list = ''this is a test'' # shellcheck disable=SC2162 while read desc item want { _flags_itemInList $(item) $(list) setglobal got = $Status assertEquals "$(desc): itemInList($(item))" $(got) $(want) } <