dev: consolidate/update cli/addons tests

This commit is contained in:
Simon Michael 2024-07-01 11:39:34 +01:00
parent 2ab8ac31f4
commit 6af992bc3a
4 changed files with 96 additions and 92 deletions

View File

@ -486,17 +486,18 @@ SHELLTEST := 'COLUMNS=80 ' + STACK + ' exec -- shelltest --execdir --exclude=/_
&& echo $@ PASSED) || (echo $@ FAILED; false))
ADDONEXTS := 'pl py rb sh hs lhs rkt exe com bat'
ADDONSDIR := 'hledger/test/cli/addons'
# generate dummy add-ons for testing the CLI
@mktestaddons:
rm -rf hledger/test/addons/hledger-*
printf '#!/bin/sh\necho add-on: $0\necho args: $*\n' >hledger/test/addons/hledger-addon
for E in '' {{ ADDONEXTS }}; do \
cp hledger/test/addons/hledger-addon hledger/test/addons/hledger-addon.$E; done
for F in addon. addon2 addon2.hs addon3.exe addon3.lhs addon4.exe add reg; do \
cp hledger/test/addons/hledger-addon hledger/test/addons/hledger-$F; done
mkdir hledger/test/addons/hledger-addondir
chmod +x hledger/test/addons/hledger-*
mktestaddons:
#!/usr/bin/env sh
rm -rf $ADDONSDIR
mkdir -p $ADDONSDIR $ADDONSDIR/hledger-addondir
cd $ADDONSDIR
printf '#!/bin/sh\necho add-on: $0\necho args: $@\n' > hledger-addon
for E in '' {{ ADDONEXTS }}; do cp hledger-addon hledger-addon.$E; done
for F in addon. addon2 addon2.hs addon3.exe addon3.lhs addon4.exe add reg; do cp hledger-addon hledger-$F; done
chmod +x hledger-*
# compare hledger's and ledger's balance report
compare-balance:

View File

@ -1,54 +0,0 @@
# * add-on command subsystem tests
#
# "make test" sets up the dummy add-on scripts required for these tests
#
# Note because of the PATH setting these don't obey shelltest -w,
# they always run the first hledger executable in PATH
# ** 1. flags after an add-command are handled by the add-on
$ PATH=$PATH:. hledger addon --help
> /hledger-addon/
>=0
# ** 2. add-on flags which are not also defined in the main executable are a problem
$ PATH=$PATH:. hledger addon --addonflag
>2 /Unknown flag: --addonflag/
>=1
# ** 3. hledger main executable ignores anything after -- (and hides the -- from the add-on)
$ PATH=$PATH:. hledger addon --help -- --addonflag
> /hledger-addon/
>=0
# TODO how to reliably ensure no addons but still find the hledger executable ?
# ** 4. having no addons shouldn't break the commands list
# $ PATH= ~/.local/bin/stack exec -- hledger
# >=0
# ############################ issue 457 #####################################
# #
# These tests are commented out, as they are not working properly. See: #
# https://github.com/simonmichael/hledger/pull/1140#issuecomment-562793255 #
# #
# # 5. test for `>` in https://github.com/simonmichael/hledger/issues/457 #
# # note a shelltest already provides one level of quoting, so amt:>0 not 'amt:>0' #
# # #
# $ hledger -f - ui amt:>0 #
# >2 !/could not parse/ #
# >=1 #
# #
# # 6. test for `<` in https://github.com/simonmichael/hledger/issues/457 #
# $ hledger -f - ui amt:<0 #
# >2 !/could not parse/ #
# >=1 #
# #
# # 7. test for `>=` in https://github.com/simonmichael/hledger/issues/457 #
# $ hledger -f - ui amt:>=0 #
# >2 !/could not parse/ #
# >=1 #
# #
# # 8. test for `<=` in https://github.com/simonmichael/hledger/issues/457 #
# $ hledger -f - ui amt:<=0 #
# >2 !/could not parse/ #
# >=1 #
# ##################################################################################

View File

@ -0,0 +1,60 @@
# * addon command subsystem tests
# See also cli.test. These need:
# - "just mktestaddons" to be run first to set up dummy addon scripts
# - shelltest --execdir
#
# Because of the PATH setting, these don't obey shelltest -w
# (they always run the first hledger executable in PATH).
# ** 1. flags after an add-command are handled by the addon
$ PATH=$PATH:addons hledger addon --help
> /hledger-addon/
# ** 2. addon-specific flags which are not also defined in the main executable are not accepted
$ PATH=$PATH:addons hledger addon --addonflag
>2 /Unknown flag: --addonflag/
>=1
# ** 3. hledger main executable ignores anything after --, and hides the -- from the addon.
$ PATH=$PATH:addons hledger addon --help -- --addonflag
> /args: --help --addonflag/
# ** 4. --no-conf is not passed to addon.
$ PATH=$PATH:addons hledger --no-conf addon
> /args:$/
# ** 5. --conf CONFFILE is not passed to addon.
$ PATH=$PATH:addons hledger --conf /dev/null addon
> /args:$/
# ** 0. having no addons shouldn't break the commands list (how to test ?)
# $ PATH= ~/.local/bin/stack exec -- hledger
# These tests are commented out, as they are not working properly. See:
# https://github.com/simonmichael/hledger/issues/457
# https://github.com/simonmichael/hledger/pull/1140#issuecomment-562793255
#
# # 0. test for `>` in https://github.com/simonmichael/hledger/issues/457
# # note a shelltest already provides one level of quoting, so amt:>0 not 'amt:>0'
# #
# $ hledger -f - ui amt:>0
# >2 !/could not parse/
# >=1
#
# # 0. test for `<` in https://github.com/simonmichael/hledger/issues/457
# $ hledger -f - ui amt:<0
# >2 !/could not parse/
# >=1
#
# # 0. test for `>=` in https://github.com/simonmichael/hledger/issues/457
# $ hledger -f - ui amt:>=0
# >2 !/could not parse/
# >=1
#
# # 0. test for `<=` in https://github.com/simonmichael/hledger/issues/457
# $ hledger -f - ui amt:<=0
# >2 !/could not parse/
# >=1

View File

@ -1,4 +1,5 @@
# * command line interface
# * command line interface tests
# See also addons.test.
#
# Quick guide to terms used here:
#
@ -8,6 +9,8 @@
#
# - option: a command modifier. An option consists of a short flag, a
# long flag, or both, and possibly an optional or required value.
# On the command line, an option's value can be joined to the flag by
# = (long flags) or nothing (short flags), or it can be the next argument.
# Each option has some effect on program execution, and is described
# in the command line help.
#
@ -32,32 +35,23 @@
#
# - hledger command, subcommand: one of hledger's modes of operation,
# named and selected by the first parsed argument. There are two kinds:
# - internal or built-in commands are part of the main hledger executable.
# - external or add-on commands are provided by hledger-* executables in
# the PATH.
# - internal/builtin commands are part of the main hledger executable.
# - external/addon commands are provided by hledger-* executables in PATH.
#
# Description of existing/expected behaviour as of 2013/9/16:
#
# - general usage is hledger [COMMAND] [OPTIONS] [ARGS]
#
# - commands are internal (built in to the main hledger executable) or external (any hledger-* executables found in the PATH)
# - some internal commands have aliases, which are displayed in the general help
# - there are also a few hidden internal commands
# - COMMAND is an exact command (balance), an alias (bal), or any unique command prefix (inc)
# - when COMMAND is a non-unique prefix, all matched commands will be listed, including hidden ones (eg hledger c)
# - an unrecognised command shows an error and gives non-zero exit status
#
# - general usage is hledger [CMD [OPTS] [ARGS] [-- ADDONOPTS]]
# - (some?) general options may also go before the command: -f, --rules, --alias, --help, --version, --debug.
# - usually the command must come first, followed by options and arguments in any order
# - a few options may also go before the command: -f, --rules, --alias, --help, --version, --debug.
# - option flags may be written in full or as a unique prefix
# - if the command is external, options and arguments after the command are handled by that executable, not hledger
#
# - the --help flag has highest priority
# - --help before the command (or no command) shows general help, including the commands list
# - --help after an internal command shows command-specific help, including command and general flags
# - there is no internal "help" command
# version
# - options specific to an addon command, not supported by hledger cli, should be preceded by a -- argument
# - CMD is an exact command (incomestatement), one of the aliases displayed in the commands list (is), or any unique command prefix (inc)
# - there are also a few hidden builtin commands
# - when CMD is a non-unique prefix, all matched commands will be listed, including hidden ones (eg hledger c)
# - an unrecognised command shows an error and gives non-zero exit status
# - flags may be written in full or as a unique prefix
# - the help/documentation flags have highest priority
# - --help before CMD (or with no command) shows general help, including general options
# - --help after CMD shows command-specific help, including command and general options
# ** 1. --version shows version
$ hledger --version
@ -67,13 +61,11 @@ $ hledger --version
$ hledger balance --version
> /^hledger [0-9]/
# help
# ** 3. with no command, show commands list
$ hledger
> /^Commands/
# ** 4. no-command help still works if there are flags, at least the common ones
# ** 4. commands list still works if there are flags, at least the common ones
$ hledger -fsomefile
> /^Commands/
@ -81,7 +73,7 @@ $ hledger -fsomefile
$ hledger -f somefile
> /^Commands/
# ** 6. with -h, and possibly other common flags present, show general usage
# ** 6. with -h/--help, and possibly other common flags present, show general cli help
$ hledger -h --version -f/dev/null
> /^hledger \[COMMAND\]/
@ -104,8 +96,6 @@ $ hledger nosuchcommand
>2 /not recognized.*to see a list/
>= 1
# flag positions
# ** 10. general flags can go before command
$ hledger -f /dev/null --alias foo --daily register
@ -117,3 +107,10 @@ $ hledger -f /dev/null print --explicit
# ** 13. or before it
$ hledger -f /dev/null --explicit print
# ** 14. --no-conf works with builtin commands.
$ hledger --no-conf check -f/dev/null
# ** 15. --conf CONFFILE works with builtin commands.
$ hledger --conf /dev/null check -f/dev/null