Ticket #3753: 3753-extfs-tester-let-test-scripts-easily-access-configure-time-parameters.patch

File 3753-extfs-tester-let-test-scripts-easily-access-configure-time-parameters.patch, 7.2 KB (added by mooffie, 7 years ago)
  • configure.ac

    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 
    643643tests/src/vfs/Makefile 
    644644tests/src/vfs/extfs/Makefile 
    645645tests/src/vfs/extfs/helpers-list/Makefile 
     646tests/src/vfs/extfs/helpers-list/data/config.sh 
    646647]) 
    647648 
    648649AC_OUTPUT 
  • tests/src/vfs/extfs/helpers-list/Makefile.am

    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: 
    9292# The 'abs_' isn't mandatory. It lets you move this script out of the build tree. 
    9393        @echo '"$(abs_srcdir)"/test_all "$$@" \' >> $@ 
    9494        @echo '  --data-dir "$(abs_srcdir)/data" \' >> $@ 
     95        @echo '  --data-build-dir "$(abs_builddir)/data" \' >> $@ 
    9596# Before installation, some helpers are in the build tree, some in the src tree. 
    9697        @echo '  --helpers-dir "$(abs_top_builddir)/src/vfs/extfs/helpers" \' >> $@ 
    9798        @echo '  --helpers-dir "$(abs_top_srcdir)/src/vfs/extfs/helpers"' >> $@ 
  • tests/src/vfs/extfs/helpers-list/README

    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 
    185185 
    186186Contains the path of [the data folder]. Use it when you need to 
    187187construct the paths of other files you store there. 
     188 
     189#### MC_TEST_EXTFS_DATA_BUILD_DIR #### 
     190 
     191Contains the path of [the data folder], but in the *build* tree. This is 
     192where *.in files from the source tree end up. If you don't know what 
     193these are, you can safely ignore this variable. 
     194 
     195#### MC_TEST_EXTFS_CONFIG_SH #### 
     196 
     197Contains the path of *config.sh*, a file you can "source" into shell 
     198scripts (including the [environment file]) to gain access to values set 
     199when Midnight Commander was compiled. Example: 
     200 
     201    . "$MC_TEST_EXTFS_CONFIG_SH" 
     202    $PERL -e 'print "hello"' 
     203 
     204Currently, this variable is equal to 
     205"[$MC_TEST_EXTFS_DATA_BUILD_DIR][MC_TEST_EXTFS_DATA_BUILD_DIR]/config.sh", 
     206but you're advised to use only `$MC_TEST_EXTFS_CONFIG_SH` as we may 
     207change this file's location in the future. 
  • new file tests/src/vfs/extfs/helpers-list/data/config.sh.in

    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# 
     6PERL="@PERL@" 
     7AWK="@AWK@" 
     8PYTHON="@PYTHON@" 
     9RUBY="@RUBY@" 
  • tests/src/vfs/extfs/helpers-list/test_all

    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 
    3131 
    3232  $(basename "$0") \\ 
    3333     --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 
    3536 
    3637(But you're more likely to invoke this program with the 'run' script 
    3738created by 'make check'; or by 'make check' itself.) 
    their output to the expected output. 
    4344 
    4445See README for full details. 
    4546 
    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 
     47You need to tell this program primarily two things: where the helpers are 
     48stored, and where the "data files" are stored. The data files are *.input 
     49files that are fed to the helpers and *.output files that are the correct 
    4950output expected from these helpers. 
    5051 
     52You also need to tell this program where the build flavor of the "data 
     53files" is stored. Most notably this is where the 'config.sh' file is 
     54created during build time. You do this with '--data-build-dir'. 
     55 
    5156EOS 
    5257} 
    5358 
    EOS 
    5762 
    5863# The directories used. 
    5964data_dir= 
     65data_build_dir= 
    6066helpers_dir1= 
    6167helpers_dir2= 
    6268 
    find_helper() { 
    178184} 
    179185 
    180186# 
     187# Returns the path of 'config.sh'. 
     188# 
     189path_of_config_sh() { 
     190  echo "$data_build_dir/config.sh" 
     191} 
     192 
     193# 
    181194# Export variables to be used by tests. 
    182195# 
    183196# See README for their documentation. 
    export_useful_variables() { 
    194207  export MC_TEST_EXTFS_INPUT 
    195208  MC_TEST_EXTFS_DATA_DIR=$data_dir 
    196209  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 
    197214} 
    198215 
    199216# 
    parse_command_line_arguments() { 
    346363        data_dir=$2 
    347364        shift 2 
    348365        ;; 
     366      --data-build-dir) 
     367        data_build_dir=$2 
     368        shift 2 
     369        ;; 
    349370      --helpers-dir) 
    350371        if [ -z "$helpers_dir1" ]; then 
    351372          helpers_dir1=$2 
    parse_command_line_arguments() { 
    378399# 
    379400verify_setup() { 
    380401  [ -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." 
    381403  [ -n "$helpers_dir1" ] || die "You didn't specify the helpers dir (--helpers-dir). Run me with --help for info." 
    382404  [ -z "$helpers_dir2" ] && helpers_dir2=$helpers_dir1  # we're being lazy. 
    383405 
    384406  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 
    386408    assert_dir_exists "$dir" 
    387409    has_string "$dir" " " && die "$dir: Sorry, spaces aren't allowed in pathnames."  # search "reason", twice, above. 
    388410  done 
    389411 
     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 
    390414  local missing_progs="" 
    391415  check_prog() { 
    392416    if ! has_prog "$1"; then