pkgsrc-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: pkgsrc/regress/infra-unittests



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sun May 17 13:35:35 UTC 2020

Added Files:
        pkgsrc/regress/infra-unittests: var-precedence.sh

Log Message:
regress/infra-unittests: add test for variable precedence


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 pkgsrc/regress/infra-unittests/var-precedence.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: pkgsrc/regress/infra-unittests/var-precedence.sh
diff -u /dev/null pkgsrc/regress/infra-unittests/var-precedence.sh:1.1
--- /dev/null   Sun May 17 13:35:35 2020
+++ pkgsrc/regress/infra-unittests/var-precedence.sh    Sun May 17 13:35:35 2020
@@ -0,0 +1,70 @@
+#! /bin/sh
+# $NetBSD: var-precedence.sh,v 1.1 2020/05/17 13:35:35 rillig Exp $
+#
+# Demonstrates how environment variables interact with variables defined
+# in the Makefiles and variables defined in the command line.
+#
+# Everything works exactly as documented in the bmake manual page.
+#
+
+set -eu
+
+. './test.subr'
+
+# usage: vartest <testname> <command> <expected>
+vartest() {
+       test_case_begin "$1" || return 0
+
+       create_file_lines 'var.mk'      \
+               '.if defined(DEFAULT)'  \
+               'VAR?=  default'        \
+               '.endif'                \
+               ''                      \
+               '.if defined(SET)'      \
+               'VAR=   set'            \
+               '.endif'                \
+               ''                      \
+               '.if defined(APPEND)'   \
+               'VAR+=  append'         \
+               '.endif'                \
+               ''                      \
+               '.if defined(RESET)'    \
+               '.undef VAR'            \
+               'VAR=   reset'          \
+               '.endif'                \
+               ''                      \
+               'all:'                  \
+               '       @printf '\''%s\n'\'' '\'\''${VAR:Q}'
+
+       unset DEFAULT SET APPEND VAR
+
+       eval "$2" 1> "$tmpdir/output" 2>&1 \
+       && exitcode=0 || exitcode=$?
+
+       assert_that "$exitcode" --equals '0'
+       assert_that "$tmpdir/output" --file-is-lines \
+               "$3"
+
+       test_case_end
+}
+
+vartest 'undefined'                    '        run_bmake var.mk'                      ''
+vartest 'env'                          'VAR=env run_bmake var.mk'                      'env'
+vartest 'env + flag'                   'VAR=env run_bmake var.mk VAR=flag'             'flag'
+vartest 'env + default'                        'VAR=env run_bmake var.mk DEFAULT=yes'          'env'
+vartest 'env + set'                    'VAR=env run_bmake var.mk SET=yes'              'set'
+vartest 'env + append'                 'VAR=env run_bmake var.mk APPEND=yes'           'env append'
+vartest 'env + reset'                  'VAR=env run_bmake var.mk RESET=yes'            'reset'
+vartest 'flag'                         '        run_bmake var.mk VAR=flag'             'flag'
+vartest 'flag + default'               '        run_bmake var.mk VAR=flag DEFAULT=yes' 'flag'
+vartest 'flag + set'                   '        run_bmake var.mk VAR=flag SET=yes'     'flag'
+vartest 'flag + append'                        '        run_bmake var.mk VAR=flag APPEND=yes'  'flag'
+vartest 'flag + reset'                 '        run_bmake var.mk VAR=flag RESET=yes'   'flag'
+
+# The override flag is not used in pkgsrc.
+vartest 'env + override'               'VAR=env run_bmake var.mk -e'                   'env'
+vartest 'env + override + flag'                'VAR=env run_bmake var.mk -e VAR=flag'          'flag'
+vartest 'env + override + default'     'VAR=env run_bmake var.mk -e DEFAULT=yes'       'env'
+vartest 'env + override + set'         'VAR=env run_bmake var.mk -e SET=yes'           'env'
+vartest 'env + override + append'      'VAR=env run_bmake var.mk -e APPEND=yes'        'env'
+vartest 'env + override + reset'       'VAR=env run_bmake var.mk -e RESET=yes'         'env'



Home | Main Index | Thread Index | Old Index