From 5c6107f1a871a15d5ed545efe6d9671ce4a5594d Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Sun, 8 Jan 2017 13:28:39 +0200
Subject: [PATCH] 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>
---
configure.ac | 1 +
tests/src/vfs/extfs/helpers-list/Makefile.am | 1 +
tests/src/vfs/extfs/helpers-list/README | 20 +++++++++++++
tests/src/vfs/extfs/helpers-list/data/config.sh.in | 9 ++++++
tests/src/vfs/extfs/helpers-list/test_all | 34 ++++++++++++++++++----
5 files changed, 60 insertions(+), 5 deletions(-)
create mode 100644 tests/src/vfs/extfs/helpers-list/data/config.sh.in
diff --git a/configure.ac b/configure.ac
index 87576f0..28e0ebe 100644
a
|
b
|
tests/src/editor/test-data.txt |
643 | 643 | tests/src/vfs/Makefile |
644 | 644 | tests/src/vfs/extfs/Makefile |
645 | 645 | tests/src/vfs/extfs/helpers-list/Makefile |
| 646 | tests/src/vfs/extfs/helpers-list/data/config.sh |
646 | 647 | ]) |
647 | 648 | |
648 | 649 | AC_OUTPUT |
diff --git a/tests/src/vfs/extfs/helpers-list/Makefile.am b/tests/src/vfs/extfs/helpers-list/Makefile.am
index 716c3a3..f930391 100644
a
|
b
|
run: |
92 | 92 | # The 'abs_' isn't mandatory. It lets you move this script out of the build tree. |
93 | 93 | @echo '"$(abs_srcdir)"/test_all "$$@" \' >> $@ |
94 | 94 | @echo ' --data-dir "$(abs_srcdir)/data" \' >> $@ |
| 95 | @echo ' --data-build-dir "$(abs_builddir)/data" \' >> $@ |
95 | 96 | # Before installation, some helpers are in the build tree, some in the src tree. |
96 | 97 | @echo ' --helpers-dir "$(abs_top_builddir)/src/vfs/extfs/helpers" \' >> $@ |
97 | 98 | @echo ' --helpers-dir "$(abs_top_srcdir)/src/vfs/extfs/helpers"' >> $@ |
diff --git a/tests/src/vfs/extfs/helpers-list/README b/tests/src/vfs/extfs/helpers-list/README
index b9c76ff..0c3bda6 100644
a
|
b
|
Contains the path of the [input file]. You'll more commonly use |
185 | 185 | |
186 | 186 | Contains the path of [the data folder]. Use it when you need to |
187 | 187 | construct the paths of other files you store there. |
| 188 | |
| 189 | #### MC_TEST_EXTFS_DATA_BUILD_DIR #### |
| 190 | |
| 191 | Contains the path of [the data folder], but in the *build* tree. This is |
| 192 | where *.in files from the source tree end up. If you don't know what |
| 193 | these are, you can safely ignore this variable. |
| 194 | |
| 195 | #### MC_TEST_EXTFS_CONFIG_SH #### |
| 196 | |
| 197 | Contains the path of *config.sh*, a file you can "source" into shell |
| 198 | scripts (including the [environment file]) to gain access to values set |
| 199 | when Midnight Commander was compiled. Example: |
| 200 | |
| 201 | . "$MC_TEST_EXTFS_CONFIG_SH" |
| 202 | $PERL -e 'print "hello"' |
| 203 | |
| 204 | Currently, this variable is equal to |
| 205 | "[$MC_TEST_EXTFS_DATA_BUILD_DIR][MC_TEST_EXTFS_DATA_BUILD_DIR]/config.sh", |
| 206 | but you're advised to use only `$MC_TEST_EXTFS_CONFIG_SH` as we may |
| 207 | change this file's location in the future. |
diff --git a/tests/src/vfs/extfs/helpers-list/data/config.sh.in b/tests/src/vfs/extfs/helpers-list/data/config.sh.in
new file mode 100644
index 0000000..05aca06
-
|
+
|
|
| 1 | # |
| 2 | # Configure-time parameters that may be useful in tests. |
| 3 | # |
| 4 | # See README for how to use this file. |
| 5 | # |
| 6 | PERL="@PERL@" |
| 7 | AWK="@AWK@" |
| 8 | PYTHON="@PYTHON@" |
| 9 | RUBY="@RUBY@" |
diff --git a/tests/src/vfs/extfs/helpers-list/test_all b/tests/src/vfs/extfs/helpers-list/test_all
index f4dd4f1..23f8cea 100755
a
|
b
|
SYNOPSIS |
31 | 31 | |
32 | 32 | $(basename "$0") \\ |
33 | 33 | --data-dir /path/to/where/data/files/are/stored \\ |
34 | | --helpers-dir /path/to/where/helpers/are/stored |
| 34 | --helpers-dir /path/to/where/helpers/are/stored \\ |
| 35 | --data-build-dir /path/to/where/config.sh/is/stored |
35 | 36 | |
36 | 37 | (But you're more likely to invoke this program with the 'run' script |
37 | 38 | created by 'make check'; or by 'make check' itself.) |
… |
… |
their output to the expected output. |
43 | 44 | |
44 | 45 | See README for full details. |
45 | 46 | |
46 | | You need to tell this program two things: where the helpers are stored, |
47 | | and where the "data files" are stored. The data files are *.input files |
48 | | that are fed to the helpers and *.output files that are the correct |
| 47 | You need to tell this program primarily two things: where the helpers are |
| 48 | stored, and where the "data files" are stored. The data files are *.input |
| 49 | files that are fed to the helpers and *.output files that are the correct |
49 | 50 | output expected from these helpers. |
50 | 51 | |
| 52 | You also need to tell this program where the build flavor of the "data |
| 53 | files" is stored. Most notably this is where the 'config.sh' file is |
| 54 | created during build time. You do this with '--data-build-dir'. |
| 55 | |
51 | 56 | EOS |
52 | 57 | } |
53 | 58 | |
… |
… |
EOS |
57 | 62 | |
58 | 63 | # The directories used. |
59 | 64 | data_dir= |
| 65 | data_build_dir= |
60 | 66 | helpers_dir1= |
61 | 67 | helpers_dir2= |
62 | 68 | |
… |
… |
find_helper() { |
178 | 184 | } |
179 | 185 | |
180 | 186 | # |
| 187 | # Returns the path of 'config.sh'. |
| 188 | # |
| 189 | path_of_config_sh() { |
| 190 | echo "$data_build_dir/config.sh" |
| 191 | } |
| 192 | |
| 193 | # |
181 | 194 | # Export variables to be used by tests. |
182 | 195 | # |
183 | 196 | # See README for their documentation. |
… |
… |
export_useful_variables() { |
194 | 207 | export MC_TEST_EXTFS_INPUT |
195 | 208 | MC_TEST_EXTFS_DATA_DIR=$data_dir |
196 | 209 | export MC_TEST_EXTFS_DATA_DIR |
| 210 | MC_TEST_EXTFS_DATA_BUILD_DIR=$data_build_dir |
| 211 | export MC_TEST_EXTFS_DATA_BUILD_DIR |
| 212 | MC_TEST_EXTFS_CONFIG_SH=$(path_of_config_sh) |
| 213 | export MC_TEST_EXTFS_CONFIG_SH |
197 | 214 | } |
198 | 215 | |
199 | 216 | # |
… |
… |
parse_command_line_arguments() { |
346 | 363 | data_dir=$2 |
347 | 364 | shift 2 |
348 | 365 | ;; |
| 366 | --data-build-dir) |
| 367 | data_build_dir=$2 |
| 368 | shift 2 |
| 369 | ;; |
349 | 370 | --helpers-dir) |
350 | 371 | if [ -z "$helpers_dir1" ]; then |
351 | 372 | helpers_dir1=$2 |
… |
… |
parse_command_line_arguments() { |
378 | 399 | # |
379 | 400 | verify_setup() { |
380 | 401 | [ -n "$data_dir" ] || die "You didn't specify the data dir (--data-dir). Run me with --help for info." |
| 402 | [ -n "$data_build_dir" ] || die "You didn't specify the data build dir (--data-build-dir). Run me with --help for info." |
381 | 403 | [ -n "$helpers_dir1" ] || die "You didn't specify the helpers dir (--helpers-dir). Run me with --help for info." |
382 | 404 | [ -z "$helpers_dir2" ] && helpers_dir2=$helpers_dir1 # we're being lazy. |
383 | 405 | |
384 | 406 | local dir |
385 | | for dir in "$data_dir" "$helpers_dir1" "$helpers_dir2"; do |
| 407 | for dir in "$data_dir" "$data_build_dir" "$helpers_dir1" "$helpers_dir2"; do |
386 | 408 | assert_dir_exists "$dir" |
387 | 409 | has_string "$dir" " " && die "$dir: Sorry, spaces aren't allowed in pathnames." # search "reason", twice, above. |
388 | 410 | done |
389 | 411 | |
| 412 | [ -e "$(path_of_config_sh)" ] || die "Missing file $(path_of_config_sh). You probably have a mistake in the '--data-build-dir' path." |
| 413 | |
390 | 414 | local missing_progs="" |
391 | 415 | check_prog() { |
392 | 416 | if ! has_prog "$1"; then |