]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/dynvar.tests
bash-5.1 distribution sources and documentation
[thirdparty/bash.git] / tests / dynvar.tests
CommitLineData
8868edaf
CR
1# This program is free software: you can redistribute it and/or modify
2# it under the terms of the GNU General Public License as published by
3# the Free Software Foundation, either version 3 of the License, or
4# (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU General Public License for more details.
10#
11# You should have received a copy of the GNU General Public License
12# along with this program. If not, see <http://www.gnu.org/licenses/>.
13#
d233b485
CR
14# specvar -- test some of the dynamic variables
15
16# BASHPID
17pid=$$
18bpid=$BASHPID
19subpid=$( (echo $BASHPID) )
20
21if [ "$bpid" -ne "$subpid" ]; then echo BASHPID ok; fi
22
23# BASH_ARGV0
24
25BASH_ARGV0=hello
26case $0 in
27hello) echo BASH_ARGV0 ok ;;
28*) echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;;
29esac
30
31setarg0()
32{
33 BASH_ARGV0="$1"
34}
35
36setarg0 arg0
37case $0 in
38arg0) echo BASH_ARGV0 ok ;;
39*) echo "BASH_ARGV0 mismatch: $BASH_ARGV0 ($0)" >&2 ;;
40esac
41
42# SECONDS
43before=$SECONDS
44sleep 2
45after=$SECONDS
46
47if (( $after > $before )); then echo SECONDS ok; fi
48unset before after
49
50# EPOCHSECONDS
51
52# not exact, but should work
8868edaf 53# could also use python -c 'import time; ts = int(time.time()); print(ts)'
d233b485
CR
54now1=$(perl -e 'print time')
55now2=$EPOCHSECONDS
56
57case $now1 in
58$now2) echo EPOCHSECONDS ok ;;
59*) echo "current time via perl and EPOCHSECONDS possible mismatch|$now1|$now2" >&2 ;;
60esac
61unset now1 now2
62
63LC_ALL=C # force decimal point to `.'
64now1=$EPOCHREALTIME
65now2=$EPOCHREALTIME
66sec1=${now1%%.*}
67sec2=${now2%%.*}
68
69msec1=${now1##*.}
70msec2=${now2##*.}
71# cut off leading zeros
72shopt -s extglob
73msec1=${msec1##*(0)}
74msec2=${msec2##*(0)}
75
76dsec=$(( $sec2 - $sec1 ))
77dmsec=$(( $msec2 - $msec1 ))
78if (( $dmsec < 0 )); then
79 dmsec=$(( dmsec + 1000000 ))
80 dsec=$(( desc - 1 ))
81fi
82
83# not a real test, but ok for a start
84if (( $dmsec < 1000000 )); then echo EPOCHREALTIME ok; fi
85
86${THIS_SH} -c 'echo $BASH_COMMAND'
87
88# FUNCNAME tested in func.tests
89# RANDOM tested in varenv.sh
90# LINENO tested in dbg-support