Module Name: src
Committed By: kre
Date: Wed Dec 12 11:52:05 UTC 2018
Modified Files:
src/tests/bin/sh: t_builtins.sh
Log Message:
Add a new test case for NetBSD specific readonly tests.
Add more sub-tests to the export_nbsd test case.
In both cases the new -q and -p VAR options are tested.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/bin/sh/t_builtins.sh
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/bin/sh/t_builtins.sh
diff -u src/tests/bin/sh/t_builtins.sh:1.3 src/tests/bin/sh/t_builtins.sh:1.4
--- src/tests/bin/sh/t_builtins.sh:1.3 Wed Dec 12 08:10:39 2018
+++ src/tests/bin/sh/t_builtins.sh Wed Dec 12 11:52:05 2018
@@ -1,4 +1,4 @@
-# $NetBSD: t_builtins.sh,v 1.3 2018/12/12 08:10:39 kre Exp $
+# $NetBSD: t_builtins.sh,v 1.4 2018/12/12 11:52:05 kre Exp $
#
# Copyright (c) 2018 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -416,6 +416,45 @@ export_nbsd_body() {
atf_check -s not-exit:0 -e not-empty -o empty ${TEST_SH} -c \
'export VAR=exported; export -x VAR; export VAR=FOO'
+
+ have_builtin export '' 'export VAR;' '-q VAR' ' -q' || return 0
+
+ atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+ 'unset VAR; VAR=set; export -q VAR'
+ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+ 'export VAR=set; export -q VAR'
+ atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+ 'VAR=set; RW=set; export -q VAR RW'
+ atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+ 'VAR=set; export RO=set; export -q VAR RO'
+ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+ 'export VAR=set RO=set; export -q VAR RO'
+
+ atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+ 'unset VAR; export -q VAR'
+ # next one is the same as the have_builtin test, so "cannot" fail...
+ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+ 'unset VAR; export VAR; export -q VAR'
+
+ # if we have -q we should also have -p var...
+ # What's more, we are testing NetBSD sh, so we know output format.
+
+ atf_check -s exit:0 -e empty -o match:VAR=foobar \
+ ${TEST_SH} -c \
+ 'VAR=foobar ; export VAR ; export -p VAR'
+ atf_check -s exit:0 -e empty -o inline:1 \
+ ${TEST_SH} -c \
+ 'VAR=foobar ; export VAR ;
+ printf %d $(export -p VAR | wc -l)'
+ atf_check -s exit:0 -e empty \
+ -o inline:'export VAR=foobar\nexport OTHER\n' \
+ ${TEST_SH} -c \
+ 'VAR=foobar; export VAR OTHER; export -p VAR OTHER'
+ atf_check -s exit:0 -e empty \
+ -o inline:'export A=aaa\nexport B\nexport D='"''"'\n' \
+ ${TEST_SH} -c \
+ 'A=aaa D= C=foo; unset B; export A B D;
+ export -p A B C D'
}
atf_test_case getopts
@@ -516,6 +555,51 @@ readonly_body() {
'unset VAR; readonly VAR=set; unset VAR; printf %s ${VAR-unset}'
}
+atf_test_case readonly_nbsd
+readonly_nbsd_head() {
+ atf_set "descr" "Tests NetBSD extensions to 'readonly'"
+}
+readonly_nbsd_body() {
+ have_builtin readonly '' 'readonly VAR;' '-q VAR' ' -q' || return 0
+
+ atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+ 'VAR=set; readonly -q VAR'
+ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+ 'readonly VAR=set; readonly -q VAR'
+ atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+ 'VAR=set; RW=set; readonly -q VAR RW'
+ atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+ 'VAR=set; readonly RO=set; readonly -q VAR RO'
+ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+ 'readonly VAR=set RO=set; readonly -q VAR RO'
+
+ atf_check -s exit:1 -o empty -e empty ${TEST_SH} -c \
+ 'unset VAR; readonly -q VAR'
+ # next one is the same as the have_builtin test, so "cannot" fail...
+ atf_check -s exit:0 -o empty -e empty ${TEST_SH} -c \
+ 'unset VAR; readonly VAR; readonly -q VAR'
+
+ # if we have -q we should also have -p var...
+ # What's more, we are testing NetBSD sh, so we know output format.
+
+ atf_check -s exit:0 -e empty -o match:VAR=foobar \
+ ${TEST_SH} -c \
+ 'VAR=foobar ; readonly VAR ; readonly -p VAR'
+ atf_check -s exit:0 -e empty -o inline:1 \
+ ${TEST_SH} -c \
+ 'VAR=foobar ; readonly VAR ;
+ printf %d $(readonly -p VAR | wc -l)'
+ atf_check -s exit:0 -e empty \
+ -o inline:'readonly VAR=foobar\nreadonly OTHER\n' \
+ ${TEST_SH} -c \
+ 'VAR=foobar; readonly VAR OTHER; readonly -p VAR OTHER'
+ atf_check -s exit:0 -e empty \
+ -o inline:'readonly A=aaa\nreadonly B\nreadonly D='"''"'\n' \
+ ${TEST_SH} -c \
+ 'A=aaa D= C=foo; unset B; readonly A B D;
+ readonly -p A B C D'
+}
+
atf_test_case cd_pwd
cd_pwd_head() {
atf_set "descr" "Tests the shell builtins 'cd' & 'pwd'"
@@ -830,6 +914,7 @@ atf_init_test_cases() {
atf_add_test_case jobid
atf_add_test_case let
atf_add_test_case local
+ atf_add_test_case readonly_nbsd
atf_add_test_case setvar
# inputrc should probably be tested in libedit tests (somehow)