From a0090c06b9f324866fa0da82fb5e91df28f71912 Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 8 Dec 2024 14:17:06 -0500 Subject: [PATCH] Add a test for the "load" command --- configure.ac | 4 +++- test/unit/.gitignore | 5 +++-- test/unit/Makefile.am | 1 + test/unit/test-cmd-load.sh.in | 37 +++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) create mode 100755 test/unit/test-cmd-load.sh.in diff --git a/configure.ac b/configure.ac index 543b479e..3308b7ba 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script. # Copyright (C) 2002-2012, -# 2014-2019, 2023 Rocky Bernstein +# 2014-2019, 2023-2024 Rocky Bernstein # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -231,6 +231,8 @@ AC_CONFIG_FILES([test/unit/test-cmd-info-variables.sh], [chmod +x test/unit/test-cmd-info-variables.sh]) AC_CONFIG_FILES([test/unit/test-cmd-eval.sh], [chmod +x test/unit/test-cmd-eval.sh]) +AC_CONFIG_FILES([test/unit/test-cmd-load.sh], + [chmod +x test/unit/test-cmd-load.sh]) AC_CONFIG_FILES([test/unit/test-columns.sh], [chmod +x test/unit/test-columns.sh]) AC_CONFIG_FILES([test/unit/test-file.sh], diff --git a/test/unit/.gitignore b/test/unit/.gitignore index 485dc26f..1439e1c6 100644 --- a/test/unit/.gitignore +++ b/test/unit/.gitignore @@ -1,6 +1,6 @@ -/*~ -/*.trs /*.log +/*.trs +/*~ /Makefile /Makefile.in /require_me.sh @@ -11,6 +11,7 @@ /test-cmd-complete.sh /test-cmd-eval.sh /test-cmd-info-variables.sh +/test-cmd-load.sh /test-columns.sh /test-eval.sh /test-file.sh diff --git a/test/unit/Makefile.am b/test/unit/Makefile.am index 11fcb3ff..47c6b819 100644 --- a/test/unit/Makefile.am +++ b/test/unit/Makefile.am @@ -8,6 +8,7 @@ TESTS = test-action.sh \ test-cmd-complete.sh \ test-cmd-eval.sh \ test-cmd-info-variables.sh \ + test-cmd-load.sh \ test-columns.sh \ test-filecache.sh \ test-file.sh \ diff --git a/test/unit/test-cmd-load.sh.in b/test/unit/test-cmd-load.sh.in new file mode 100755 index 00000000..5b22aea3 --- /dev/null +++ b/test/unit/test-cmd-load.sh.in @@ -0,0 +1,37 @@ +#!@SH_PROG@ +# -*- shell-script -*- + +typeset -a messages=() + +test_cmd_load() +{ + # Check that load_file caches mapping from short name + # to fully-resolved file name + local find_file="./test-cmd-load.sh.in" + cd $(dirname ${BASH_SOURCE[0]}) + _Dbg_init_cwd=$(pwd) + _Dbg_do_load "$find_file" + assertEquals ${#messages[@]} 0 + typeset cached_file="${_Dbg_file2canonic[$find_file]}" + assertEquals "$cached_file" $(_Dbg_resolve_expand_filename "$find_file") +} + +abs_top_srcdir=@abs_top_srcdir@ +# Make sure $abs_top_srcdir has a trailing slash +abs_top_srcdir=${abs_top_srcdir%%/}/ +. ${abs_top_srcdir}test/unit/helper.sh +. ${abs_top_srcdir}init/pre.sh +for file in alias help fns ; do + . ${abs_top_srcdir}lib/${file}.sh +done +. ${abs_top_srcdir}lib/filecache.sh +. ${abs_top_srcdir}lib/file.sh +. ${abs_top_srcdir}lib/unescape.sh +. ${abs_top_srcdir}command/load.sh +set -- # reset $# so shunit2 doesn't get confused. +[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file} + +# Replace lib/msg _Dbg_msg with sothing to track. +function _Dbg_msg { + messages+=("$@) +}