Skip to content

Commit

Permalink
Test declaration utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
magicant committed Jan 5, 2025
1 parent 1716409 commit bb85149
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 3 deletions.
6 changes: 3 additions & 3 deletions tests/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Makefile.in for test of yash
# (C) 2007-2023 magicant
# (C) 2007-2025 magicant
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -27,9 +27,9 @@ CPPFLAGS = @CPPFLAGS@
LDFLAGS = @LDFLAGS@
LDLIBS = @LDLIBS@
SOURCES = checkfg.c ptwrap.c resetsig.c
POSIX_TEST_SOURCES = $(POSIX_SIGNAL_TEST_SOURCES) alias-p.tst andor-p.tst arith-p.tst async-p.tst bg-p.tst break-p.tst builtins-p.tst case-p.tst cd-p.tst cmdsub-p.tst command-p.tst comment-p.tst continue-p.tst dot-p.tst errexit-p.tst error-p.tst eval-p.tst exec-p.tst exit-p.tst export-p.tst fg-p.tst fnmatch-p.tst for-p.tst fsplit-p.tst function-p.tst getopts-p.tst grouping-p.tst if-p.tst input-p.tst job-p.tst kill1-p.tst kill2-p.tst kill3-p.tst kill4-p.tst lineno-p.tst nop-p.tst option-p.tst param-p.tst path-p.tst pipeline-p.tst ppid-p.tst quote-p.tst read-p.tst readonly-p.tst redir-p.tst return-p.tst set-p.tst shift-p.tst simple-p.tst startup-p.tst test-p.tst testtty-p.tst tilde-p.tst trap-p.tst umask-p.tst unset-p.tst until-p.tst wait-p.tst while-p.tst
POSIX_TEST_SOURCES = $(POSIX_SIGNAL_TEST_SOURCES) alias-p.tst andor-p.tst arith-p.tst async-p.tst bg-p.tst break-p.tst builtins-p.tst case-p.tst cd-p.tst cmdsub-p.tst command-p.tst comment-p.tst continue-p.tst declutil-p.tst dot-p.tst errexit-p.tst error-p.tst eval-p.tst exec-p.tst exit-p.tst export-p.tst fg-p.tst fnmatch-p.tst for-p.tst fsplit-p.tst function-p.tst getopts-p.tst grouping-p.tst if-p.tst input-p.tst job-p.tst kill1-p.tst kill2-p.tst kill3-p.tst kill4-p.tst lineno-p.tst nop-p.tst option-p.tst param-p.tst path-p.tst pipeline-p.tst ppid-p.tst quote-p.tst read-p.tst readonly-p.tst redir-p.tst return-p.tst set-p.tst shift-p.tst simple-p.tst startup-p.tst test-p.tst testtty-p.tst tilde-p.tst trap-p.tst umask-p.tst unset-p.tst until-p.tst wait-p.tst while-p.tst
POSIX_SIGNAL_TEST_SOURCES = sigcont1-p.tst sigcont2-p.tst sigcont3-p.tst sigcont4-p.tst sigcont5-p.tst sigcont6-p.tst sigcont7-p.tst sigcont8-p.tst sighup1-p.tst sighup2-p.tst sighup3-p.tst sighup4-p.tst sighup5-p.tst sighup6-p.tst sighup7-p.tst sighup8-p.tst sigint1-p.tst sigint2-p.tst sigint3-p.tst sigint4-p.tst sigint5-p.tst sigint6-p.tst sigint7-p.tst sigint8-p.tst sigquit1-p.tst sigquit2-p.tst sigquit3-p.tst sigquit4-p.tst sigquit5-p.tst sigquit6-p.tst sigquit7-p.tst sigquit8-p.tst sigstop3-p.tst sigstop7-p.tst sigterm1-p.tst sigterm2-p.tst sigterm3-p.tst sigterm4-p.tst sigterm5-p.tst sigterm6-p.tst sigterm7-p.tst sigterm8-p.tst sigtstp3-p.tst sigtstp4-p.tst sigtstp7-p.tst sigtstp8-p.tst sigttin3-p.tst sigttin4-p.tst sigttin7-p.tst sigttin8-p.tst sigttou3-p.tst sigttou4-p.tst sigttou7-p.tst sigttou8-p.tst sigurg1-p.tst sigurg2-p.tst sigurg3-p.tst sigurg4-p.tst sigurg5-p.tst sigurg6-p.tst sigurg7-p.tst sigurg8-p.tst
YASH_TEST_SOURCES = $(YASH_SIGNAL_TEST_SOURCES) alias-y.tst andor-y.tst arith-y.tst array-y.tst async-y.tst bg-y.tst bindkey-y.tst brace-y.tst bracket-y.tst break-y.tst builtins-y.tst case-y.tst cd-y.tst cmdprint-y.tst cmdsub-y.tst command-y.tst complete-y.tst continue-y.tst dirstack-y.tst disown-y.tst dot-y.tst echo-y.tst errexit-y.tst error-y.tst errretur-y.tst eval-y.tst exec-y.tst exit-y.tst export-y.tst fc-y.tst fg-y.tst for-y.tst fsplit-y.tst function-y.tst getopts-y.tst grouping-y.tst hash-y.tst help-y.tst history-y.tst history1-y.tst history2-y.tst if-y.tst job-y.tst jobs-y.tst kill-y.tst lineno-y.tst local-y.tst option-y.tst param-y.tst path-y.tst pipeline-y.tst printf-y.tst prompt-y.tst pwd-y.tst quote-y.tst random-y.tst read-y.tst readonly-y.tst redir-y.tst return-y.tst set-y.tst settty-y.tst shift-y.tst signal-y.tst simple-y.tst startup-y.tst suspend-y.tst test1-y.tst test2-y.tst tilde-y.tst times-y.tst trap-y.tst trap2-y.tst typeset-y.tst ulimit-y.tst umask-y.tst unset-y.tst until-y.tst wait-y.tst while-y.tst
YASH_TEST_SOURCES = $(YASH_SIGNAL_TEST_SOURCES) alias-y.tst andor-y.tst arith-y.tst array-y.tst async-y.tst bg-y.tst bindkey-y.tst brace-y.tst bracket-y.tst break-y.tst builtins-y.tst case-y.tst cd-y.tst cmdprint-y.tst cmdsub-y.tst command-y.tst complete-y.tst continue-y.tst declutil-y.tst dirstack-y.tst disown-y.tst dot-y.tst echo-y.tst errexit-y.tst error-y.tst errretur-y.tst eval-y.tst exec-y.tst exit-y.tst export-y.tst fc-y.tst fg-y.tst for-y.tst fsplit-y.tst function-y.tst getopts-y.tst grouping-y.tst hash-y.tst help-y.tst history-y.tst history1-y.tst history2-y.tst if-y.tst job-y.tst jobs-y.tst kill-y.tst lineno-y.tst local-y.tst option-y.tst param-y.tst path-y.tst pipeline-y.tst printf-y.tst prompt-y.tst pwd-y.tst quote-y.tst random-y.tst read-y.tst readonly-y.tst redir-y.tst return-y.tst set-y.tst settty-y.tst shift-y.tst signal-y.tst simple-y.tst startup-y.tst suspend-y.tst test1-y.tst test2-y.tst tilde-y.tst times-y.tst trap-y.tst trap2-y.tst typeset-y.tst ulimit-y.tst umask-y.tst unset-y.tst until-y.tst wait-y.tst while-y.tst
YASH_SIGNAL_TEST_SOURCES = sigalrm1-y.tst sigalrm2-y.tst sigalrm3-y.tst sigalrm4-y.tst sigalrm5-y.tst sigalrm6-y.tst sigalrm7-y.tst sigalrm8-y.tst sigchld1-y.tst sigchld2-y.tst sigchld3-y.tst sigchld4-y.tst sigchld5-y.tst sigchld6-y.tst sigchld7-y.tst sigchld8-y.tst sigrtmax1-y.tst sigrtmax2-y.tst sigrtmax3-y.tst sigrtmax4-y.tst sigrtmax5-y.tst sigrtmax6-y.tst sigrtmax7-y.tst sigrtmax8-y.tst sigrtmin1-y.tst sigrtmin2-y.tst sigrtmin3-y.tst sigrtmin4-y.tst sigrtmin5-y.tst sigrtmin6-y.tst sigrtmin7-y.tst sigrtmin8-y.tst sigwinch1-y.tst sigwinch2-y.tst sigwinch3-y.tst sigwinch4-y.tst sigwinch5-y.tst sigwinch6-y.tst sigwinch7-y.tst sigwinch8-y.tst
TEST_SOURCES = $(POSIX_TEST_SOURCES) $(YASH_TEST_SOURCES)
TEST_RESULTS = $(TEST_SOURCES:.tst=.trs)
Expand Down
4 changes: 4 additions & 0 deletions tests/POSIX
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ Volume 3: Shell & Utilities
2.9.1 Simple Commands

2.9.1.1 Order of Processing
* declutil-p.tst
* simple-p.tst

2.9.1.2 Variable Assignments
Expand Down Expand Up @@ -181,9 +182,11 @@ exit
* exit-p.tst

export
* declutil-p.tst
* export-p.tst

readonly
* declutil-p.tst
* readonly-p.tst
* readonly-y.tst

Expand Down Expand Up @@ -215,6 +218,7 @@ cd
* cd-p.tst

command
* declutil-p.tst
* command-p.tst

false
Expand Down
77 changes: 77 additions & 0 deletions tests/declutil-p.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# declutil-p.tst: test of declaration utilities for any POSIX-compliant shell

posix="true"

# Pathname expansion may match this dummy file in incorrect implementations.
>tmpfile

test_oE 'no pathname expansion or field splitting in export A=$a'
a="1 * 2"
export A=$a
sh -c 'printf "%s\n" "$A"'
__IN__
1 * 2
__OUT__

test_oE 'tilde expansions in export A=~:~'
HOME=/foo
export A=~:~
sh -c 'printf "%s\n" "$A"'
__IN__
/foo:/foo
__OUT__

test_oE 'pathname expansion and field splitting in export $a'
A=foo B=bar a='A B'
export $a
sh -c 'printf "%s\n" "$A" "$B"'
__IN__
foo
bar
__OUT__

test_oE 'no pathname expansion or field splitting in readonly A=$a'
a="1 * 2"
readonly A=$a
printf "%s\n" "$A"
__IN__
1 * 2
__OUT__

test_oE 'tilde expansions in readonly A=~:~'
HOME=/foo
readonly A=~:~
printf "%s\n" "$A"
__IN__
/foo:/foo
__OUT__

test_oE 'pathname expansion and field splitting in readonly $a'
A=foo B=bar a='A B'
readonly $a
printf "%s\n" "$A" "$B"
__IN__
foo
bar
__OUT__

test_oE 'command command export'
a="1 * 2"
command command export A=$a
sh -c 'printf "%s\n" "$A"'
__IN__
1 * 2
__OUT__

test_oE 'command command readonly'
a="1 * 2"
command command readonly A=$a
printf "%s\n" "$A"
__IN__
1 * 2
__OUT__

# POSIX allows any utility to be a declaration utility as an extension,
# so there are no tests to check that a utility is not a declaration utility.

# vim: set ft=sh ts=8 sts=4 sw=4 et:
51 changes: 51 additions & 0 deletions tests/declutil-y.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# declutil-y.tst: yash-specific test of declaration utilities

>tmpfile

# local is a declaration utility in yash
test_oE 'no pathname expansion or field splitting in local A=$a'
a="1 * 2"
local A=$a
printf "%s\n" "$A"
__IN__
1 * 2
__OUT__

# typeset is a declaration utility in yash
test_oE 'no pathname expansion or field splitting in typeset A=$a'
a="1 * 2"
typeset A=$a
printf "%s\n" "$A"
__IN__
1 * 2
__OUT__

# printf is not a declaration utility in yash
test_oE 'pathname expansion and field splitting in printf A=$a'
a='1 tmp* 2'
printf "%s\n" A=$a
__IN__
A=1
tmpfile
2
__OUT__

# printf is not a declaration utility in yash
test_oE 'tilde expansions in printf A=~:~'
HOME=/foo
printf "%s\n" A=~:~
__IN__
A=~:~
__OUT__

# printf is not a declaration utility in yash
test_oE 'command command printf'
a='1 tmp* 2'
command command printf "%s\n" A=$a
__IN__
A=1
tmpfile
2
__OUT__

# vim: set ft=sh ts=8 sts=4 sw=4 et:

0 comments on commit bb85149

Please sign in to comment.