diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 18:33:23 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 18:33:23 +0000 |
commit | 1d5cace9db9aef76f26b2d7ba54bbb76443b00b2 (patch) | |
tree | 314a15dd1aa103da13bdc83ba1d2105a290bc5ba /tests/dynvar.tests | |
parent | Initial commit. (diff) | |
download | bash-89791e9f494bebe33a9c52292a98f4f079926078.tar.xz bash-89791e9f494bebe33a9c52292a98f4f079926078.zip |
Adding upstream version 5.0.upstream/5.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/dynvar.tests')
-rw-r--r-- | tests/dynvar.tests | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/dynvar.tests b/tests/dynvar.tests new file mode 100644 index 0000000..a01f5ed --- /dev/null +++ b/tests/dynvar.tests @@ -0,0 +1,77 @@ +# specvar -- test some of the dynamic variables + +# BASHPID +pid=$$ +bpid=$BASHPID +subpid=$( (echo $BASHPID) ) + +if [ "$bpid" -ne "$subpid" ]; then echo BASHPID ok; fi + +# BASH_ARGV0 + +BASH_ARGV0=hello +case $0 in +hello) echo BASH_ARGV0 ok ;; +*) echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;; +esac + +setarg0() +{ + BASH_ARGV0="$1" +} + +setarg0 arg0 +case $0 in +arg0) echo BASH_ARGV0 ok ;; +*) echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;; +esac + +# SECONDS +before=$SECONDS +sleep 2 +after=$SECONDS + +if (( $after > $before )); then echo SECONDS ok; fi +unset before after + +# EPOCHSECONDS + +# not exact, but should work + +now1=$(perl -e 'print time') +now2=$EPOCHSECONDS + +case $now1 in +$now2) echo EPOCHSECONDS ok ;; +*) echo "current time via perl and EPOCHSECONDS possible mismatch|$now1|$now2" >&2 ;; +esac +unset now1 now2 + +LC_ALL=C # force decimal point to `.' +now1=$EPOCHREALTIME +now2=$EPOCHREALTIME +sec1=${now1%%.*} +sec2=${now2%%.*} + +msec1=${now1##*.} +msec2=${now2##*.} +# cut off leading zeros +shopt -s extglob +msec1=${msec1##*(0)} +msec2=${msec2##*(0)} + +dsec=$(( $sec2 - $sec1 )) +dmsec=$(( $msec2 - $msec1 )) +if (( $dmsec < 0 )); then + dmsec=$(( dmsec + 1000000 )) + dsec=$(( desc - 1 )) +fi + +# not a real test, but ok for a start +if (( $dmsec < 1000000 )); then echo EPOCHREALTIME ok; fi + +${THIS_SH} -c 'echo $BASH_COMMAND' + +# FUNCNAME tested in func.tests +# RANDOM tested in varenv.sh +# LINENO tested in dbg-support |