mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 04:22:34 +03:00
Ticket #3753: extfs: tester: let test scripts easily access configure-time parameters.
We introduce a mechanism by which tests can easily access configure-time parameters (like @PERL@, @AWK@, ...). It works by "sourcing" a file named config.sh (residing in the build tree): . "$MC_TEST_EXTFS_CONFIG_SH" $PERL -e 'print "hello"' (Although config.sh has a shell syntax, Perl and Python programs too can benefit from it, because it can be sourced into an .env_vars file and the values exported from there.) Of course, one can also use the traditional method, of *.in files listed in configure.ac, but the mechanism introduced here is a more comfortable approach. Signed-off-by: Mooffie <mooffie@gmail.com>
This commit is contained in:
parent
0fdcfa6aa4
commit
69897e94fd
@ -643,6 +643,7 @@ tests/src/editor/test-data.txt
|
|||||||
tests/src/vfs/Makefile
|
tests/src/vfs/Makefile
|
||||||
tests/src/vfs/extfs/Makefile
|
tests/src/vfs/extfs/Makefile
|
||||||
tests/src/vfs/extfs/helpers-list/Makefile
|
tests/src/vfs/extfs/helpers-list/Makefile
|
||||||
|
tests/src/vfs/extfs/helpers-list/data/config.sh
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
@ -92,6 +92,7 @@ run:
|
|||||||
# The 'abs_' isn't mandatory. It lets you move this script out of the build tree.
|
# The 'abs_' isn't mandatory. It lets you move this script out of the build tree.
|
||||||
@echo '"$(abs_srcdir)"/test_all "$$@" \' >> $@
|
@echo '"$(abs_srcdir)"/test_all "$$@" \' >> $@
|
||||||
@echo ' --data-dir "$(abs_srcdir)/data" \' >> $@
|
@echo ' --data-dir "$(abs_srcdir)/data" \' >> $@
|
||||||
|
@echo ' --data-build-dir "$(abs_builddir)/data" \' >> $@
|
||||||
# Before installation, some helpers are in the build tree, some in the src tree.
|
# Before installation, some helpers are in the build tree, some in the src tree.
|
||||||
@echo ' --helpers-dir "$(abs_top_builddir)/src/vfs/extfs/helpers" \' >> $@
|
@echo ' --helpers-dir "$(abs_top_builddir)/src/vfs/extfs/helpers" \' >> $@
|
||||||
@echo ' --helpers-dir "$(abs_top_srcdir)/src/vfs/extfs/helpers"' >> $@
|
@echo ' --helpers-dir "$(abs_top_srcdir)/src/vfs/extfs/helpers"' >> $@
|
||||||
@ -99,6 +100,9 @@ run:
|
|||||||
# (We can alternatively create run from a run.in template
|
# (We can alternatively create run from a run.in template
|
||||||
# with 'AC_CONFIG_FILES[run, chmod +x run]'.)
|
# with 'AC_CONFIG_FILES[run, chmod +x run]'.)
|
||||||
|
|
||||||
|
# Whenever we change the recipe above, we need to regenerate the 'run' script:
|
||||||
|
run: Makefile
|
||||||
|
|
||||||
#
|
#
|
||||||
# Documentation
|
# Documentation
|
||||||
#
|
#
|
||||||
|
@ -185,3 +185,23 @@ Contains the path of the [input file]. You'll more commonly use
|
|||||||
|
|
||||||
Contains the path of [the data folder]. Use it when you need to
|
Contains the path of [the data folder]. Use it when you need to
|
||||||
construct the paths of other files you store there.
|
construct the paths of other files you store there.
|
||||||
|
|
||||||
|
#### MC_TEST_EXTFS_DATA_BUILD_DIR ####
|
||||||
|
|
||||||
|
Contains the path of [the data folder], but in the *build* tree. This is
|
||||||
|
where *.in files from the source tree end up. If you don't know what
|
||||||
|
these are, you can safely ignore this variable.
|
||||||
|
|
||||||
|
#### MC_TEST_EXTFS_CONFIG_SH ####
|
||||||
|
|
||||||
|
Contains the path of *config.sh*, a file you can "source" into shell
|
||||||
|
scripts (including the [environment file]) to gain access to values set
|
||||||
|
when Midnight Commander was compiled. Example:
|
||||||
|
|
||||||
|
. "$MC_TEST_EXTFS_CONFIG_SH"
|
||||||
|
$PERL -e 'print "hello"'
|
||||||
|
|
||||||
|
Currently, this variable is equal to
|
||||||
|
"[$MC_TEST_EXTFS_DATA_BUILD_DIR][MC_TEST_EXTFS_DATA_BUILD_DIR]/config.sh",
|
||||||
|
but you're advised to use only `$MC_TEST_EXTFS_CONFIG_SH` as we may
|
||||||
|
change this file's location in the future.
|
||||||
|
9
tests/src/vfs/extfs/helpers-list/data/config.sh.in
Normal file
9
tests/src/vfs/extfs/helpers-list/data/config.sh.in
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#
|
||||||
|
# Configure-time parameters that may be useful in tests.
|
||||||
|
#
|
||||||
|
# See README for how to use this file.
|
||||||
|
#
|
||||||
|
PERL="@PERL@"
|
||||||
|
AWK="@AWK@"
|
||||||
|
PYTHON="@PYTHON@"
|
||||||
|
RUBY="@RUBY@"
|
@ -31,7 +31,8 @@ SYNOPSIS
|
|||||||
|
|
||||||
$(basename "$0") \\
|
$(basename "$0") \\
|
||||||
--data-dir /path/to/where/data/files/are/stored \\
|
--data-dir /path/to/where/data/files/are/stored \\
|
||||||
--helpers-dir /path/to/where/helpers/are/stored
|
--helpers-dir /path/to/where/helpers/are/stored \\
|
||||||
|
--data-build-dir /path/to/where/config.sh/is/stored
|
||||||
|
|
||||||
(But you're more likely to invoke this program with the 'run' script
|
(But you're more likely to invoke this program with the 'run' script
|
||||||
created by 'make check'; or by 'make check' itself.)
|
created by 'make check'; or by 'make check' itself.)
|
||||||
@ -43,11 +44,15 @@ their output to the expected output.
|
|||||||
|
|
||||||
See README for full details.
|
See README for full details.
|
||||||
|
|
||||||
You need to tell this program two things: where the helpers are stored,
|
You need to tell this program primarily two things: where the helpers are
|
||||||
and where the "data files" are stored. The data files are *.input files
|
stored, and where the "data files" are stored. The data files are *.input
|
||||||
that are fed to the helpers and *.output files that are the correct
|
files that are fed to the helpers and *.output files that are the correct
|
||||||
output expected from these helpers.
|
output expected from these helpers.
|
||||||
|
|
||||||
|
You also need to tell this program where the build flavor of the "data
|
||||||
|
files" is stored. Most notably this is where the 'config.sh' file is
|
||||||
|
created during build time. You do this with '--data-build-dir'.
|
||||||
|
|
||||||
EOS
|
EOS
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +62,7 @@ EOS
|
|||||||
|
|
||||||
# The directories used.
|
# The directories used.
|
||||||
data_dir=
|
data_dir=
|
||||||
|
data_build_dir=
|
||||||
helpers_dir1=
|
helpers_dir1=
|
||||||
helpers_dir2=
|
helpers_dir2=
|
||||||
|
|
||||||
@ -177,6 +183,13 @@ find_helper() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Returns the path of 'config.sh'.
|
||||||
|
#
|
||||||
|
path_of_config_sh() {
|
||||||
|
echo "$data_build_dir/config.sh"
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Export variables to be used by tests.
|
# Export variables to be used by tests.
|
||||||
#
|
#
|
||||||
@ -194,6 +207,10 @@ export_useful_variables() {
|
|||||||
export MC_TEST_EXTFS_INPUT
|
export MC_TEST_EXTFS_INPUT
|
||||||
MC_TEST_EXTFS_DATA_DIR=$data_dir
|
MC_TEST_EXTFS_DATA_DIR=$data_dir
|
||||||
export MC_TEST_EXTFS_DATA_DIR
|
export MC_TEST_EXTFS_DATA_DIR
|
||||||
|
MC_TEST_EXTFS_DATA_BUILD_DIR=$data_build_dir
|
||||||
|
export MC_TEST_EXTFS_DATA_BUILD_DIR
|
||||||
|
MC_TEST_EXTFS_CONFIG_SH=$(path_of_config_sh)
|
||||||
|
export MC_TEST_EXTFS_CONFIG_SH
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -346,6 +363,10 @@ parse_command_line_arguments() {
|
|||||||
data_dir=$2
|
data_dir=$2
|
||||||
shift 2
|
shift 2
|
||||||
;;
|
;;
|
||||||
|
--data-build-dir)
|
||||||
|
data_build_dir=$2
|
||||||
|
shift 2
|
||||||
|
;;
|
||||||
--helpers-dir)
|
--helpers-dir)
|
||||||
if [ -z "$helpers_dir1" ]; then
|
if [ -z "$helpers_dir1" ]; then
|
||||||
helpers_dir1=$2
|
helpers_dir1=$2
|
||||||
@ -378,15 +399,18 @@ parse_command_line_arguments() {
|
|||||||
#
|
#
|
||||||
verify_setup() {
|
verify_setup() {
|
||||||
[ -n "$data_dir" ] || die "You didn't specify the data dir (--data-dir). Run me with --help for info."
|
[ -n "$data_dir" ] || die "You didn't specify the data dir (--data-dir). Run me with --help for info."
|
||||||
|
[ -n "$data_build_dir" ] || die "You didn't specify the data build dir (--data-build-dir). Run me with --help for info."
|
||||||
[ -n "$helpers_dir1" ] || die "You didn't specify the helpers dir (--helpers-dir). Run me with --help for info."
|
[ -n "$helpers_dir1" ] || die "You didn't specify the helpers dir (--helpers-dir). Run me with --help for info."
|
||||||
[ -z "$helpers_dir2" ] && helpers_dir2=$helpers_dir1 # we're being lazy.
|
[ -z "$helpers_dir2" ] && helpers_dir2=$helpers_dir1 # we're being lazy.
|
||||||
|
|
||||||
local dir
|
local dir
|
||||||
for dir in "$data_dir" "$helpers_dir1" "$helpers_dir2"; do
|
for dir in "$data_dir" "$data_build_dir" "$helpers_dir1" "$helpers_dir2"; do
|
||||||
assert_dir_exists "$dir"
|
assert_dir_exists "$dir"
|
||||||
has_string "$dir" " " && die "$dir: Sorry, spaces aren't allowed in pathnames." # search "reason", twice, above.
|
has_string "$dir" " " && die "$dir: Sorry, spaces aren't allowed in pathnames." # search "reason", twice, above.
|
||||||
done
|
done
|
||||||
|
|
||||||
|
[ -e "$(path_of_config_sh)" ] || die "Missing file $(path_of_config_sh). You probably have a mistake in the '--data-build-dir' path."
|
||||||
|
|
||||||
local missing_progs=""
|
local missing_progs=""
|
||||||
check_prog() {
|
check_prog() {
|
||||||
if ! has_prog "$1"; then
|
if ! has_prog "$1"; then
|
||||||
|
Loading…
Reference in New Issue
Block a user