Skip to content

Commit 37b8dc5

Browse files
committed
test: Properly call core.init to set global varaibles
1 parent bcda5ee commit 37b8dc5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/trap.bats

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ load './util/init.sh'
66
# actual execution of the functions on the signal. There seems to be a limitation
77
# of Bats that prevents this from working
88

9+
# The '${___global_trap_table___[nokey]}' is there to ensure that the
10+
# ___global_trap_table___ is an actual associative array. If '___global_trap_table___' is not an associative array, the index with 'nokey' still returns the value of the variable (no error will be thrown). These were origianlly done when the 'core.init' function was not called within these tests
11+
912
@test "core.trap_add fails when function specified does not exist" {
1013
run core.trap_add 'nonexistent' 'USR1'
1114

@@ -22,17 +25,21 @@ load './util/init.sh'
2225

2326
@test "core.trap_add adds trap function properly" {
2427
somefunction() { :; }
28+
core.init
2529
core.trap_add 'somefunction' 'USR1'
2630

31+
[ "${___global_trap_table___[nokey]}" != $'\x1Csomefunction' ]
2732
[ "${___global_trap_table___[USR1]}" = $'\x1Csomefunction' ]
2833
}
2934

3035
@test "core.trap_add adds function properly 2" {
3136
somefunction() { :; }
3237
somefunction2() { :; }
38+
core.init
3339
core.trap_add 'somefunction' 'USR1'
3440
core.trap_add 'somefunction2' 'USR1'
3541

42+
[ "${___global_trap_table___[nokey]}" != $'\x1Csomefunction\x1Csomefunction2' ]
3643
[ "${___global_trap_table___[USR1]}" = $'\x1Csomefunction\x1Csomefunction2' ]
3744
}
3845

@@ -45,6 +52,7 @@ load './util/init.sh'
4552

4653
@test "core.trap_remove removes trap function properly 1" {
4754
somefunction() { :; }
55+
core.init
4856
core.trap_add 'somefunction' 'USR1'
4957
core.trap_remove 'somefunction' 'USR1'
5058

@@ -54,19 +62,23 @@ load './util/init.sh'
5462
@test "core.trap_remove removes trap function properly 2" {
5563
somefunction() { :; }
5664
somefunction2() { :; }
65+
core.init
5766
core.trap_add 'somefunction' 'USR1'
5867
core.trap_add 'somefunction2' 'USR1'
5968
core.trap_remove 'somefunction' 'USR1'
6069

70+
[ "${___global_trap_table___[nokey]}" != $'\x1Csomefunction2' ]
6171
[ "${___global_trap_table___[USR1]}" = $'\x1Csomefunction2' ]
6272
}
6373

6474
@test "core.trap_remove removes trap function properly 3" {
6575
somefunction() { :; }
6676
somefunction2() { :; }
77+
core.init
6778
core.trap_add 'somefunction' 'USR1'
6879
core.trap_add 'somefunction2' 'USR1'
6980
core.trap_remove 'somefunction2' 'USR1'
7081

82+
[ "${___global_trap_table___[nokey]}" != $'\x1Csomefunction' ]
7183
[ "${___global_trap_table___[USR1]}" = $'\x1Csomefunction' ]
7284
}

0 commit comments

Comments
 (0)