Skip to content

Commit daa9f5d

Browse files
committed
go-script-bash v1.3.0
1 parent 3c5b1ae commit daa9f5d

File tree

3 files changed

+96
-27
lines changed

3 files changed

+96
-27
lines changed

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ scripts can be in any other interpreted language.__
195195
First you'll need a copy of this framework available in your project sources.
196196
Archives are available at:
197197

198-
- https://github.com/mbland/go-script-bash/archive/v1.2.1.tar.gz
199-
- https://github.com/mbland/go-script-bash/archive/v1.2.1.zip
198+
- https://github.com/mbland/go-script-bash/archive/v1.3.0.tar.gz
199+
- https://github.com/mbland/go-script-bash/archive/v1.3.0.zip
200200

201201
You can also add this repository to your project as a [`Git
202202
submodule`](https://git-scm.com/book/en/v2/Git-Tools-Submodules):
@@ -365,11 +365,14 @@ For more information, run `./go modules --help log`.
365365
#### Bats test assertions and helpers
366366

367367
The assertions and helpers from the test suite have been extracted into the
368-
`lib/bats/assertions` and `lib/bats/helpers` libraries. While these are not
369-
modules you can import with `_GO_USE_MODULES`, they are completely independent
370-
of the rest of the core framework and you may source them in your own Bats
371-
tests. (Whether or not these will ever become a separate library remains an open
372-
question.)
368+
`lib/bats/assertions`, `lib/bats/helpers`, and `lib/bats/assertion-test-helpers`
369+
libraries. While these are not modules you can import with `_GO_USE_MODULES`,
370+
they are completely independent of the rest of the core framework and you may
371+
source them in your own Bats tests. (Whether or not these will ever become a
372+
separate library remains an open question.)
373+
374+
Variables, helper functions, and assertions for testing features based on the
375+
core framework are available in the `lib/testing` directory.
373376

374377
Read the comments from each file for more information.
375378

RELEASE.md

Lines changed: 85 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# go-script-bash v1.2.1
1+
# go-script-bash v1.3.0
22

3-
This release enhances the public stack trace feature and adds it to `@go.log FATAL` output.
3+
This is a massive feature update that greatly extends the capabilities of the `log` module, improves existing test helpers and adds many new ones, adds several new modules available via `_GO_USE_MODULES`, plus much more. (And it goes without saying there are tons of bug fixes and compatibility workarounds!)
44

55
## The `./go` script: a unified development environment interface
66

@@ -16,31 +16,97 @@ This software is made available as [Open Source software](https://opensource.org
1616

1717
## What's new in this release
1818

19-
### Make `@go.print_stack_trace` take a numerical `skip_callers` argument
19+
All of the issues and pull requests for this release are visible in the [v1.3.0 milestone](https://github.com/mbland/go-script-bash/milestone/1?closed=1). Many of the new features were inspired by the enthusiastic and thoughtful input from [John Omernik](https://github.com/JohnOmernik), based on his experience integrating the framework into his [JohnOmernik/zetago project](https://github.com/JohnOmernik/zetago).
2020

21-
Previously `@go.print_stack_trace` would only skip the immediate caller if the first argument was not null. Now it enforces that the number be a positive integer, in order to skip over the specified number of callers while printing the stack trace. This was done to support better `@go.log FATAL` output, described below.
21+
### `lib/log` updates
2222

23-
Normally an API change like this would warrant a major version bump, but since the impact should be minimal, it any potential for impact exists at all, it's included in this patch release.
23+
`lib/log` gained a number of powerful new features in this update:
2424

25-
### Include stack trace output on `@go.log FATAL` conditions
25+
- Timestamp prefixes are available by defining `_GO_LOG_TIMESTAMP_FORMAT`.
26+
- Each log level can now emit output to any arbitrary number of file descriptors by applying `@go.log_add_output_file`.
27+
- `_GO_LOG_LEVEL_FILTER` and `_GO_LOG_CONSOLE_FILTER` help control the amount of information logged to files or to the console, respectively.
28+
- The new lowest-priority `DEBUG` log level isn't emitted by default; use one of the above filters or `@go.log_add_output_file` to capture it.
29+
- The new `QUIT` log level exits the process like `FATAL`, but without a stack trace.
30+
- `@go.log_command` now captures all command output (even from subprocesses!) and emits it across all file descriptors configured for the `RUN` log level.
31+
- `@go.critical_section_begin` now takes an argument to determine whether failing commands run under `@go.log_command` will log `QUIT` or `FATAL` upon error; the default is set by `_GO_CRITICAL_SECTION_DEFAULT`, which defaults to `FATAL`
32+
- The new `demo-core log` builtin subcommand provides an interactive demonstration of `log` module features; see `./go help demo-core log`.
33+
- Testing assertions and helper functions are publicly available in `lib/testing/log` and `lib/testing/stack-trace`.
2634

27-
`@go.log FATAL` now prints a stack trace before exiting the process, since such information is generally useful under `FATAL` conditions. Every function in the `log` module that calls `@go.log FATAL` removes itself from the stack trace, so the top of the stack shows the location of the user code that triggered the condition, rather than the location of the `log` module function.
35+
See `./go modules -h log` for more information.
2836

29-
## Changes since v1.2.0
37+
### New `lib/file` module for file descriptor-based file I/O
3038

31-
<pre>
32-
b2ad688 Mike Bland <mbland@acm.org>
33-
Merge pull request #28 from mbland/stack-trace
39+
The new `lib/file` functions make it easy to open, write to, and close file descriptors in a safe and convenient fashion. While most of these functions support the new `lib/log` features, they are general-purpose and available to import via `. "$_GO_USE_MODULES" file`. See `./go modules -h file` for more information.
40+
41+
### New `lib/validation` file to validate caller-supplied data
42+
43+
The functions from `lib/validation` help make sure that caller-supplied data and variable names are well-formed and won't execute arbitrary code. The `*_or_die` variations will exit with a stack trace if an item violates validation constraints. Useful for examining identifiers before invoking `eval` or builtins such as `printf -v` that expect an identifier name as an argument. See `./go modules -h validation` for more information.
44+
45+
### Expanded and improved `lib/bats` module and the new `lib/testing` module for testing
46+
47+
It's now easier than ever to compose new assertions from `lib/bats/assertions`, thanks to the new `set "$BATS_ASSERTION_DISABLE_SHELL_OPTIONS"` and `return_from_bats_assertion` convention. New assertions are also easier to test thanks to the new `lib/bats/assertion-test-helpers` utilities.
48+
49+
`lib/bats/assertions` now contains:
50+
51+
- The `fail_if` assertion negator for `lib/bats/assertions` assertions, which makes it easy to write negative conditions with robust output
52+
- The new `assert_lines_match` assertion
53+
- `set_bats_output_and_lines_from_file`, which is used to implement the new `assert_file_equals`, `assert_file_matches`, and `assert_file_lines_match` assertions
54+
55+
Goodies now available in `lib/bats/helpers` include:
56+
57+
- `fs_missing_permission_support` and `skip_if_cannot_trigger_file_permission_failure` for skipping test cases on platforms that cannot trigger file permission-based conditions
58+
- `test_join` for joining multiple expected output elements into a single variable
59+
- `test_printf` and the `TEST_DEBUG` variable for producing targeted test debugging output
60+
- `test_filter` and the `TEST_FILTER` variable for pinpointing specific test cases within a suite and skipping the rest
61+
- `split_bats_output_into_lines` to ensure blank lines from `output` are preserved in `lines`; this facilitates using `assert_lines_equal` and `assert_lines_match` with output containing blank lines
62+
- `stub_program_in_path` to easily write temporary test stubs for programs in `PATH`
63+
64+
Also, framework-specific test helpers have been exported to `lib/testing`, to help with writing tests that depend on core framework output and behavior, including functions that help validate stack trace and `@go.log` output.
65+
66+
All existing and new test helper functions have also been thoroughly tested on multiple platforms to ensure portability, ease-of-use, and a minimum of surprises.
67+
68+
### `lib/format` updates
69+
70+
The `lib/format` module gained two new functions:
71+
72+
- `@go.array_printf` for transforming an entire array of items at once using `printf -v`
73+
- `@go.strip_formatting_codes` for removing ASCII formatting codes from a string, used by `@go.log` when writing to non-console file descriptors in the absence of `_GO_LOG_FORMATTING`
74+
75+
Also, `@go.pad_items` and `@go.zip_items` have updated interfaces that expect the caller to provide the name of the output variable, now that both are defined in terms of `@go.array_printf` (which is in turn implemented using the new `@go.split`, described below.) See `./go modules -h format` for more information.
3476

35-
965782d Mike Bland <mbland@acm.org>
36-
log: Add stack trace to FATAL output
77+
### New `lib/strings` modules
3778

38-
a0f4413 Mike Bland <mbland@acm.org>
39-
stack-trace: Move, add helpers to environment.bash
79+
The `lib/strings` module provides `@go.split` and `@go.join` functions that implement behavior common to other programming language libraries. See `./go modules -h strings` for more information.
4080

41-
cd57da0 Mike Bland <mbland@acm.org>
42-
print-stack-trace: Add go-core stack test helper
81+
`@go.split` in particular is highly recommend for widespread use to avoid an obscure Bash bug on Travis CI; see the function comments and `git show 99ab78 2297b4` for details.
4382

44-
8424338 Mike Bland <mbland@acm.org>
45-
print_stack_trace: Make skip_callers arg numerical
83+
### `_GO_USE_MODULES` exported for subprocess use
84+
85+
Now any Bash process spawned by the `./go` script has access to the `_GO_USE_MODULES` mechanism, most notably Bats test cases and assertions.
86+
87+
### New `demo-core` framework and `lib/subcommands` module
88+
89+
The `lib/subcommands` module exports the `@go.show_subcommands` function, which may be used to implement commands that are only shells for a number of subcommands. See `./go modules -h subcommands` for more information.
90+
91+
The new `demo-core` command demonstrates the use of `@go.show_subcommands`, and provides a framework for writing small demonstration programs for module features. As a first step, the `demo-core log` subcommand provides a demonstration of various `log` module features. See `./go help demo-core` and `./go help demo-core log` for more information.
92+
93+
### `@go.printf` works independently of `fold`
94+
95+
`@go.printf` no longer opens a pipe to the `fold` program, and now folds lines itself. The performance difference was a very minor improvement or degradation across systems, and now output is folded regardless of the presence of `fold` on the host system.
96+
97+
### Uses `[` instead of `[[` in all Bats test cases
98+
99+
Turns out there's a gotcha when using `[[` in Bats test cases under Bash versions lower than 4.1, such as the stock 3.2.57(1)-release that ships on macOS. See `git show fefce2` for details.
100+
101+
### Uses ASCII Unit Separator (`$'\x1f'`) instead of NUL to export arrays
102+
103+
Previously, `$'\0'` was used to export the `_GO_CMD_NAME` and `_GO_CMD_ARGV` arrays to commands written in other languages. However, it wasn't possible to successfully use NUL to implement the new `@go.array_printf` in the `lib/format` module, or to pass it as a delimiter to `@go.split` from the new `lib/strings` module, since Bash can join strings using `IFS=$'\0'`, but not split them. (Setting `IFS=$'\0'` is equivalent to setting it to the null string, which disables word splitting.) Consequently, the ASCII Unit Separator character seemed a fine substitute for that purpose, and it seemed wise to apply it to `_GO_CMD_NAME` and `_GO_CMD_ARGV` as well.
104+
105+
## Changes since v1.2.1
106+
107+
You can see the details of every change by issuing one or more of the following commands after cloning: https://github.com/mbland/go-script-bash
108+
109+
<pre>
110+
$ ./go changes v1.2.1 v1.3.0
111+
$ gitk v1.2.1..HEAD
46112
</pre>

go-core.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fi
3939
# This and other variables are exported, so that command scripts written in
4040
# languages other than Bash (and hence run in new processes) can access them.
4141
# See `./go vars` and `./go help vars`.
42-
declare -r -x _GO_CORE_VERSION='v1.2.1'
42+
declare -r -x _GO_CORE_VERSION='v1.3.0'
4343

4444
# The URL of the framework's original source repository
4545
declare -r -x _GO_CORE_URL='https://github.com/mbland/go-script-bash'

0 commit comments

Comments
 (0)