You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-11Lines changed: 18 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -4,40 +4,47 @@ Core functions for any Bash program
4
4
5
5
## Summary
6
6
7
-
The following are functions available for use. See [api.md](./docs/api.md) for more details
8
-
9
-
### `init`
10
-
11
-
-`core.util.init`
12
-
13
-
Initialize global variables used by other functions
14
-
15
-
Add and remove traps. With these, multiple packages can add or remove traps handlers for signals
7
+
The following is a brief overview of the available functions. See [api.md](./docs/api.md) for more details
16
8
17
9
### `trap`
18
10
11
+
Add or remove multiple functions at a time to any set of signals. Without these, it is impossible to trap a signal without erasing a previous one
12
+
19
13
-`core.trap_add`
20
14
-`core.trap_remove`
21
15
22
16
### `shopt`
23
17
18
+
Enable or disable a shell option. Enabling a shell option adds it to a hidden stack. When that shell option is no longer needed, it should be removed by popping it from the stack
19
+
24
20
-`core.shopt_push`
25
21
-`core.shopt_pop`
26
22
27
23
### `err`
28
24
29
-
I suppose it can look redundant (compared to `if ! fn; then :; fi`), but it can help make errors a bit more safe in larger applications, since you don't have to worry about a caller forgetting to `if ! fn` or `fn ||` (and terminating the script if `set -e`). It also makes it easier to communicate specific error codes and helps separate between calculated / expected errors and unexpected errors (fatal / faults)
25
+
It can look redundant (compared to `if ! fn; then :; fi`) to define error functions, but it can help make errors a bit more safe in larger applications, since you don't have to worry about a caller forgetting to `if ! fn` or `fn ||` (and terminating the script if `set -e`). It also makes it easier to communicate specific error codes and helps separate between calculated / expected errors and unexpected errors / faults
30
26
31
27
-`core.err_set`
32
28
-`core.err_clear`
33
29
-`core.err_exists`
34
30
35
31
### `stacktrace`
36
32
37
-
Prints the stack trace. Recommended to use with `core.trap_add`
33
+
Prints the stack trace. It is recommended to use this with `core.trap_add` (see [example](./docs/api.md#corestacktraceprint))
38
34
39
35
-`core.stacktrace_print`
40
36
37
+
This is what it may look like
38
+
39
+
```txt
40
+
Stacktrace:
41
+
in core.stacktrace_print (/storage/ur/storage_home/Docs/Programming/repos/Groups/Bash/bash-core/.hidden/test.sh:0)
42
+
in err_handler (/storage/ur/storage_home/Docs/Programming/repos/Groups/Bash/bash-core/.hidden/test.sh:36)
43
+
in fn3 (/storage/ur/storage_home/Docs/Programming/repos/Groups/Bash/bash-core/.hidden/test.sh:48)
44
+
in fn2 (/storage/ur/storage_home/Docs/Programming/repos/Groups/Bash/bash-core/.hidden/test.sh:53)
45
+
in fn (/storage/ur/storage_home/Docs/Programming/repos/Groups/Bash/bash-core/.hidden/test.sh:57)
46
+
```
47
+
41
48
## Installation
42
49
43
50
Use [Basalt](https://github.com/hyperupcall/basalt), a Bash package manager, to add this project as a dependency
Copy file name to clipboardExpand all lines: tests/trap.bats
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -2,12 +2,15 @@
2
2
3
3
load './util/init.sh'
4
4
5
-
# Note that this and similar functions only test for array appending, not
6
-
#actual execution of the functions on the signal. There seems to be a limitation
5
+
# Note that the array appending of these core.trap-* functions are tested. The actual
6
+
# execution of the functions on the signal are bit tested. There seems to be a limitation
7
7
# of Bats that prevents this from working
8
8
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
9
+
# Additionally, the '${___global_trap_table___[nokey]}' is there to ensure that the
10
+
# ___global_trap_table___ is an associative array. If that variable is not an associative
11
+
# array, indexing with 'nokey' still yields the value of the (string) variable (no error
12
+
# will be thrown). Now that 'core.init' is automatically called when the array is not
13
+
# defined (to be an associative array), these checks are unecessary (yet, they still exist)
11
14
12
15
@test "core.trap_add fails when function is not supplied" {
0 commit comments