<commit_before>#! /bin/sh
# vim:et:ft=sh:sts=2:sw=2
#
# Copyright 2008 <NAME>. All Rights Reserved.
# Released under the LGPL (GNU Lesser General Public License)
#
# Author: <EMAIL> (<NAME>)
#
# shFlags unit test for the public functions

# load test helpers
. ./shflags_test_helpers

# set shwordsplit for zsh
[ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit

#------------------------------------------------------------------------------
# suite tests
#

testHelp()
{
  #
  # test short -h option
  #

  rslt=`FLAGS -h 2>&1`
  rtrn=$?
  assertFalse \
      'short request for help should have returned non-zero exit code.' \
      ${rtrn}
  echo "${rslt}" |grep -- 'show this help' >/dev/null
  rtrn=$?
  assertTrue \
      'short request for help should have produced some help output.' \
      ${rtrn}
  [ ${rtrn} -ne ${FLAGS_TRUE} ] && echo "${rslt}" >&2

  # test proper output when FLAGS_HELP set
  rslt=`FLAGS_HELP='this is a test'; FLAGS -h 2>&1`
  echo "${rslt}" |grep -- 'this is a test' >/dev/null
  rtrn=$?
  assertTrue \
      'setting FLAGS_HELP did not produce expected result' \
      ${rtrn}
  [ ${rtrn} -ne ${FLAGS_TRUE} ] && echo "${rslt}" >&2

  # test that "'" chars work in help string
  DEFINE_boolean b false "help string containing a ' char" b
  rslt=`FLAGS -h 2>&1`
  echo "${rslt}" |grep -- "help string containing a ' char" >/dev/null
  rtrn=$?
  assertTrue \
      "help strings containing apostrophes don't work" \
      ${rtrn}
  [ ${rtrn} -ne ${FLAGS_TRUE} ] && echo "${rslt}" >&2

  #
  # test long --help option
  #

  flags_getoptIsStd && startSkipping

  rslt=`FLAGS --help 2>&1`
  rtrn=$?
  assertFalse \
      'long request for help should have returned non-zero exit code.' \
      ${rtrn}
  echo "${rslt}" |grep -- 'show this help' >/dev/null
  assertTrue \
      'long request for help should have produced some help output.' \
      $?
}

testStandardHelpOutput()
{
  flags_getoptIsEnh && startSkipping

  DEFINE_boolean test_bool false 'test boolean' b
  DEFINE_integer test_int 0 'test integer' i
  DEFINE_string test_str '' 'test string' s
  DEFINE_string long_desc 'blah' \
      'testing of a long description to force wrap of default value' l
  help='USAGE: standard [flags] args'

  cat >"${expectedF}" <<EOF
USAGE: standard [flags] args
flags:
  -b  test boolean (default: false)
  -i  test integer (default: 0)
  -s  test string (default: '')
  -l  testing of a long description to force wrap of default value
      (default: 'blah')
  -h  show this help (default: false)
EOF
  ( FLAGS_HELP=${help}; FLAGS -h >"${stdoutF}" 2>"${stderrF}" )
  diff "${expectedF}" "${stderrF}" >/dev/null
  rtrn=$?
  assertTrue 'unexpected help output' ${rtrn}
  [ ${__shunit_skip} -eq ${SHUNIT_FALSE} \
    -a ${rtrn} -ne ${FLAGS_TRUE} ] \
      && cat "${stderrF}"
}

testEnhancedHelpOutput()
{
  flags_getoptIsEnh || startSkipping

  DEFINE_boolean test_bool false 'test boolean' b
  DEFINE_integer test_int 0 'test integer' i
  DEFINE_string test_str '' 'test string' s
  DEFINE_string long_desc 'blah' \
      'testing of a long description to force wrap of default value' l
  help='USAGE: enhanced [flags] args'

  cat >"${expectedF}" <<EOF
USAGE: enhanced [flags] args
flags:
  -b,--[no]test_bool:  test boolean (default: false)
  -i,--test_int:  test integer (default: 0)
  -s,--test_str:  test string (default: '')
  -l,--long_desc:  testing of a long description to force wrap of default value
                   (default: 'blah')
  -h,--[no]help:  show this help (default: false)
EOF
  ( FLAGS_HELP=${help}; FLAGS -h >"${stdoutF}" 2>"${stderrF}" )
  diff "${expectedF}" "${stderrF}" >/dev/null
  rtrn=$?
  assertTrue 'unexpected help output' ${rtrn}
  [ ${__shunit_skip} -eq ${SHUNIT_FALSE} -a ${rtrn} -ne ${FLAGS_TRUE} ] \
      && cat "${stderrF}"
}

#------------------------------------------------------------------------------
# suite functions
#

oneTimeSetUp()
{
  # load flags
  [ -n "${ZSH_VERSION:-}" ] && FLAGS_PARENT=$0
  . ${TH_SHFLAGS}

  tmpDir="${__shunit_tmpDir}/output"
  mkdir "${tmpDir}"
  stdoutF="${tmpDir}/stdout"
  stderrF="${tmpDir}/stderr"
  expectedF="${tmpDir}/expected"
}<commit_msg>line wrapping and extra code cleanup<commit_after>#! /bin/sh
# vim:et:ft=sh:sts=2:sw=2
#
# Copyright 2008 <NAME>. All Rights Reserved.
# Released under the LGPL (GNU Lesser General Public License)
#
# Author: <EMAIL> (<NAME>)
#
# shFlags unit test for the public functions

# load test helpers
. ./shflags_test_helpers

# set shwordsplit for zsh
[ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit

#------------------------------------------------------------------------------
# suite tests
#

testHelp()
{
  #
  # test short -h option
  #

  rslt=`FLAGS -h 2>&1`
  rtrn=$?
  assertFalse \
      'short request for help should have returned non-zero exit code.' \
      ${rtrn}
  echo "${rslt}" |grep -- 'show this help' >/dev/null
  rtrn=$?
  assertTrue \
      'short request for help should have produced some help output.' \
      ${rtrn}
  [ ${rtrn} -ne ${FLAGS_TRUE} ] && echo "${rslt}" >&2

  # test proper output when FLAGS_HELP set
  rslt=`FLAGS_HELP='this is a test'; FLAGS -h 2>&1`
  echo "${rslt}" |grep -- 'this is a test' >/dev/null
  rtrn=$?
  assertTrue 'setting FLAGS_HELP did not produce expected result' ${rtrn}
  [ ${rtrn} -ne ${FLAGS_TRUE} ] && echo "${rslt}" >&2

  # test that "'" chars work in help string
  DEFINE_boolean b false "help string containing a ' char" b
  rslt=`FLAGS -h 2>&1`
  echo "${rslt}" |grep -- "help string containing a ' char" >/dev/null
  rtrn=$?
  assertTrue "help strings containing apostrophes don't work" ${rtrn}
  [ ${rtrn} -ne ${FLAGS_TRUE} ] && echo "${rslt}" >&2

  #
  # test long --help option
  #

  flags_getoptIsStd && startSkipping

  rslt=`FLAGS --help 2>&1`
  assertFalse 'long help request should have returned non-zero exit code' $?
  echo "${rslt}" |grep -- 'show this help' >/dev/null
  assertTrue 'long help request should have produced some help output.' $?
}

testStandardHelpOutput()
{
  flags_getoptIsEnh && startSkipping

  DEFINE_boolean test_bool false 'test boolean' b
  DEFINE_integer test_int 0 'test integer' i
  DEFINE_string test_str '' 'test string' s
  DEFINE_string long_desc 'blah' \
      'testing of a long description to force wrap of default value' l
  help='USAGE: standard [flags] args'

  cat >"${expectedF}" <<EOF
USAGE: standard [flags] args
flags:
  -b  test boolean (default: false)
  -i  test integer (default: 0)
  -s  test string (default: '')
  -l  testing of a long description to force wrap of default value
      (default: 'blah')
  -h  show this help (default: false)
EOF
  ( FLAGS_HELP=${help}; FLAGS -h >"${stdoutF}" 2>"${stderrF}" )
  diff "${expectedF}" "${stderrF}" >/dev/null
  assertTrue 'unexpected help output' $?
  [ ${__shunit_skip} -eq ${SHUNIT_FALSE} -a ${rtrn} -ne ${FLAGS_TRUE} ] \
      && cat "${stderrF}"
}

testEnhancedHelpOutput()
{
  flags_getoptIsEnh || startSkipping

  DEFINE_boolean test_bool false 'test boolean' b
  DEFINE_integer test_int 0 'test integer' i
  DEFINE_string test_str '' 'test string' s
  DEFINE_string long_desc 'blah' \
      'testing of a long description to force wrap of default value' l
  help='USAGE: enhanced [flags] args'

  cat >"${expectedF}" <<EOF
USAGE: enhanced [flags] args
flags:
  -b,--[no]test_bool:  test boolean (default: false)
  -i,--test_int:  test integer (default: 0)
  -s,--test_str:  test string (default: '')
  -l,--long_desc:  testing of a long description to force wrap of default value
                   (default: 'blah')
  -h,--[no]help:  show this help (default: false)
EOF
  ( FLAGS_HELP=${help}; FLAGS -h >"${stdoutF}" 2>"${stderrF}" )
  diff "${expectedF}" "${stderrF}" >/dev/null
  assertTrue 'unexpected help output' $?
  [ ${__shunit_skip} -eq ${SHUNIT_FALSE} -a ${rtrn} -ne ${FLAGS_TRUE} ] \
      && cat "${stderrF}"
}

#------------------------------------------------------------------------------
# suite functions
#

oneTimeSetUp()
{
  # load flags
  [ -n "${ZSH_VERSION:-}" ] && FLAGS_PARENT=$0
  . ${TH_SHFLAGS}

  tmpDir="${__shunit_tmpDir}/output"
  mkdir "${tmpDir}"
  stdoutF="${tmpDir}/stdout"
  stderrF="${tmpDir}/stderr"
  expectedF="${tmpDir}/expected"
}
{'fraction_non_alphanumeric': 0.18507244612200172, 'fraction_numerical': 0.005844393035431633, 'mean_word_length': 2.9301435406698566, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1066285', 'n_tokens_mistral': 2914, 'n_tokens_neox': 2793, 'n_words': 869}