Skip to content

Commit

Permalink
Regression tests for typeset -f fix
Browse files Browse the repository at this point in the history
Related #1436
  • Loading branch information
krader1961 committed Nov 15, 2019
1 parent 7df11de commit 7c92227
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 64 deletions.
28 changes: 28 additions & 0 deletions src/cmd/ksh93/tests/b_typeset.exp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# vim: set filetype=expect:
#
# Tests of `typeset` keyword/builtin.
set pid [spawn $ksh]
expect_prompt
# Terminal rows and columns may default to zero so ensure sane values.
send "stty rows 24 cols 80\r"
expect_prompt

# ==========
# Ensure enumerating functions works if any of them are marked autoloaded but not actually loaded.
# Regression: https://github.com/att/ast/issues/1436
log_test_entry
send "functions\r"
expect -re "\r\ntypeset -fu _cd\r\n.*\r\ntypeset -fu pushd\r\n" {
puts "typeset -f produces expected output"
}
expect_prompt

# ==========
# Exit the shell.
log_test_entry
send "\r"
expect_prompt
send [ctrl D]
catch {expect default exp_continue} output
log_debug "EOF output: $output"
wait
1 change: 1 addition & 0 deletions src/cmd/ksh93/tests/b_typeset.exp.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typeset -f produces expected output
75 changes: 56 additions & 19 deletions src/cmd/ksh93/tests/types.sh → src/cmd/ksh93/tests/b_typeset.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2014 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# http://www.eclipse.org/org/documents/epl-v10.html #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <[email protected]> #
# #
########################################################################
# Tests for `typeset` builtin.

integer n=2

Expand Down Expand Up @@ -952,6 +934,7 @@ $SHELL 2> /dev/null -c 'typeset -T a_t=(x=3 y=4); a_t b=(x=1)' || log_error 'Can
$SHELL 2> /dev/null -c 'typeset -T X=(typeset x; function x.get { :; }); X -a xs=((x=yo) (x=jo)); [[ $(typeset -p xs) == "X -a xs=((x=yo) (x=jo))" ]]' || log_error 'X -a xs=((v1) (v2)) where X is a type, not working'
# ==========
# Verify -u converts string to uppercase regardless of whether or not it is
# also exported or tagged.
typeset -u test_u=uppercase
Expand All @@ -960,3 +943,57 @@ typeset -txu test_txu=uppercase
[[ $test_u != "UPPERCASE" ]] && log_error "typeset -u failed"
[[ $test_xu != "UPPERCASE" ]] && log_error "typeset -xu failed"
[[ $test_txu != "UPPERCASE" ]] && log_error "typeset -txu failed"
# ==========
# Ensure "typeset" for "declare and assign" and "assign after declare" behaves the same.
# Regression: https://github.com/att/ast/issues/1312
typeset KEY='k1'
unset A_ASSO
typeset -A A_ASSO
actual=$(typeset -p A_ASSO)
expect='typeset -A A_ASSO=()'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
typeset -A A_ASSO[${KEY}].COMPOUND_SUBNAME="declare_and_assign_noindex_fail"
actual=$(typeset -p A_ASSO)
expect='typeset -A A_ASSO=([k1]=(typeset -A COMPOUND_SUBNAME=([0]=declare_and_assign_noindex_fail);))'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
unset B_ASSO
typeset -A B_ASSO
typeset -A B_ASSO[${KEY}].COMPOUND_SUBNAME[0]="declare_and_assign_index_succ"
actual=$(typeset -p B_ASSO)
expect='typeset -A B_ASSO=([k1]=(typeset -a COMPOUND_SUBNAME=(declare_and_assign_index_succ);))'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
unset C_ASSO
typeset -A C_ASSO
typeset -A C_ASSO[${KEY}].COMPOUND_SUBNAME
C_ASSO[${KEY}].COMPOUND_SUBNAME="assign_after_declare_noindex_succ"
actual=$(typeset -p C_ASSO)
expect='typeset -A C_ASSO=([k1]=(typeset -A COMPOUND_SUBNAME=([0]=assign_after_declare_noindex_succ);))'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
unset D_ASSO
typeset -A D_ASSO
typeset -A D_ASSO[${KEY}].COMPOUND_SUBNAME
D_ASSO[${KEY}].COMPOUND_SUBNAME[0]="assign_after_declare_index_succ"
actual=$(typeset -p D_ASSO)
expect='typeset -A D_ASSO=([k1]=(typeset -A COMPOUND_SUBNAME=([0]=assign_after_declare_index_succ);))'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
# ==========
# Ensure enumerating functions works if any of them are marked autoloaded but not actually loaded.
# Regression: https://github.com/att/ast/issues/1436
#
# Use a subshell so we don't have to worry about anything done by prior tests vis-a-vis functions.
actual=$($SHELL -c 'typeset -f')
expect='typeset -fu _cd*typeset -fu pushd'
[[ "$actual" == $expect ]] ||
log_error 'typeset -f output incorrect' "$expect" "$actual"
44 changes: 0 additions & 44 deletions src/cmd/ksh93/tests/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -710,50 +710,6 @@ set +o pipefail
foo=`false | true`
[[ $? -eq 0 ]] || log_error "Incorrect exit status from command substitution"
# ==========
# Ensure "typeset" for "declare and assign" and "assign after declare" behaves the same.
# Regression: https://github.com/att/ast/issues/1312
typeset KEY='k1'
unset A_ASSO
typeset -A A_ASSO
actual=$(typeset -p A_ASSO)
expect='typeset -A A_ASSO=()'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
typeset -A A_ASSO[${KEY}].COMPOUND_SUBNAME="declare_and_assign_noindex_fail"
actual=$(typeset -p A_ASSO)
expect='typeset -A A_ASSO=([k1]=(typeset -A COMPOUND_SUBNAME=([0]=declare_and_assign_noindex_fail);))'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
unset B_ASSO
typeset -A B_ASSO
typeset -A B_ASSO[${KEY}].COMPOUND_SUBNAME[0]="declare_and_assign_index_succ"
actual=$(typeset -p B_ASSO)
expect='typeset -A B_ASSO=([k1]=(typeset -a COMPOUND_SUBNAME=(declare_and_assign_index_succ);))'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
unset C_ASSO
typeset -A C_ASSO
typeset -A C_ASSO[${KEY}].COMPOUND_SUBNAME
C_ASSO[${KEY}].COMPOUND_SUBNAME="assign_after_declare_noindex_succ"
actual=$(typeset -p C_ASSO)
expect='typeset -A C_ASSO=([k1]=(typeset -A COMPOUND_SUBNAME=([0]=assign_after_declare_noindex_succ);))'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
unset D_ASSO
typeset -A D_ASSO
typeset -A D_ASSO[${KEY}].COMPOUND_SUBNAME
D_ASSO[${KEY}].COMPOUND_SUBNAME[0]="assign_after_declare_index_succ"
actual=$(typeset -p D_ASSO)
expect='typeset -A D_ASSO=([k1]=(typeset -A COMPOUND_SUBNAME=([0]=assign_after_declare_index_succ);))'
[[ "$actual" == "$expect" ]] ||
log_error 'typeset -p output incorrect' "$expect" "$actual"
# When `for` loop is used without `in`, it should loop over `$@`
set -- foo bar baz
actual=$(for name
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/ksh93/tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ all_tests = [
['b_test.sh'],
['b_time.exp'],
['b_times.exp'],
['b_typeset.sh'],
['b_typeset.exp'],
['b_ulimit.sh'],
['b_uname.sh'],
['b_wc.sh'],
Expand Down Expand Up @@ -94,7 +96,6 @@ all_tests = [
['tilde.sh'],
['timetype.sh'],
['treemove.sh'],
['types.sh'],
['variables.sh'],
['vartree1.sh'],
['vartree2.sh'],
Expand Down

0 comments on commit 7c92227

Please sign in to comment.