Skip to content

Commit 9411a89

Browse files
authored
Merge pull request #23 from mbland/version
Introduce _GO_CORE_VERSION
2 parents ecd2d81 + e8ef35b commit 9411a89

File tree

5 files changed

+80
-17
lines changed

5 files changed

+80
-17
lines changed

README.md

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,46 @@ your scripts directory. Run `./go help plugins` for more information.
342342

343343
You can import optional Bash library code from the core framework, third-party
344344
plugins, or your own project's scripts directory by sourcing the
345-
`$_GO_USE_MODULES` script. For example, to import the core logging utilities:
345+
`_GO_USE_MODULES` script. For example, to import the core logging utilities:
346346

347347
```bash
348-
. $_GO_USE_MODULES 'log'
348+
. "$_GO_USE_MODULES" 'log'
349349
```
350350

351351
Run `./go help modules` and `./go modules --help` for more information.
352352

353+
#### Logging
354+
355+
The core library `log` module provides functions for standard logging
356+
facilities. For example:
357+
358+
```bash
359+
@go.log INFO Hello, World!
360+
@go.log ERROR Goodbye, World!
361+
```
362+
363+
For more information, run `./go modules --help log`.
364+
365+
#### Bats test assertions and helpers
366+
367+
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.)
373+
374+
Read the comments from each file for more information.
375+
376+
#### `kcov-ubuntu` module for test coverage on Linux
377+
378+
The `kcov-ubuntu` module provides the `run_kcov` function that will download and
379+
compile [kcov](https://github.com/SimonKagstrom/kcov), then run `kcov` with the
380+
original `./go` command line arguments to collect test coverage. Only available
381+
on Ubuntu Linux for now, hence the name. Run `./go modules --help kcov-ubuntu`
382+
for more information and see `scripts/test` for an example of how it may be
383+
used.
384+
353385
### Feedback and contributions
354386

355387
Feel free to [comment on or file a new GitHub

go-core.bash

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#
33
# Framework for writing "./go" scripts in Bash.
44
#
5-
# Version: v1.0.0
6-
# URL: https://github.com/mbland/go-script-bash
7-
#
85
# To use this framework, create a bash script in the root directory of your
96
# project to act as the main './go' script. This script need not be named 'go',
107
# but it must contain the following as the first and last executable lines,
@@ -35,19 +32,25 @@ if [[ "${BASH_VERSINFO[0]}" -lt '3' || "${BASH_VERSINFO[1]}" -lt '2' ]]; then
3532
exit 1
3633
fi
3734

35+
# The version of the framework
36+
#
37+
# NOTE:
38+
# ----
39+
# This and other variables are exported, so that command scripts written in
40+
# languages other than Bash (and hence run in new processes) can access them.
41+
# See `./go vars` and `./go help vars`.
42+
declare -r -x _GO_CORE_VERSION='v1.0.0'
43+
44+
# The URL of the framework's original source repository
45+
declare -r -x _GO_CORE_URL='https://github.com/mbland/go-script-bash'
46+
3847
declare __go_orig_dir="$PWD"
3948
cd "${0%/*}" || exit 1
4049

4150
# Path to the project's root directory
4251
#
4352
# This is directory containing the main ./go script. All functions, commands,
4453
# and scripts are invoked relative to this directory.
45-
#
46-
# NOTE:
47-
# ----
48-
# This and other variables are exported, so that command scripts written in
49-
# languages other than Bash (and hence run in new processes) can access them.
50-
# See `./go vars` and `./go help vars`.
5154
declare -r -x _GO_ROOTDIR="$PWD"
5255

5356
if [[ "${BASH_SOURCE[0]:0:1}" != '/' ]]; then
@@ -104,9 +107,6 @@ declare -x _GO_CMD_NAME=
104107
# string with the arguments delimited by the ASCII NUL character ($'\0').
105108
declare -x _GO_CMD_ARGV=
106109

107-
# The URL of the framework's original source repository.
108-
declare -r -x _GO_CORE_URL='https://github.com/mbland/go-script-bash'
109-
110110
# The directory in which plugins are installed.
111111
declare _GO_PLUGINS_DIR=
112112

lib/bats/assertions

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,23 @@
2424
# fail "output should not match: '$pattern'"
2525
# fi
2626
#
27-
# Alternatively, write your own assertion functions starting with:
27+
# Alternatively, write your own assertion function with the following as the
28+
# first line:
2829
#
2930
# set +o functrace
3031
#
31-
# and then make sure every return path calls:
32+
# and then make sure every return path ends with the following (possibly
33+
# followed by a `return` statement, if not at the end of the function):
3234
#
3335
# return_from_bats_assertion "$return_status" "$BASH_SOURCE"
3436
#
3537
# You may wish to wrap `return_from_bats_assertion` in a local helper function
3638
# to avoid having to specify `$BASH_SOURCE` everywhere.
3739
#
40+
# Also note that if your assertion function calls other assertion functions, you
41+
# should call `set +o functrace` after every one of them. See the implementation
42+
# of `assert_lines_equal` for an example.
43+
#
3844
# The assertions borrow inspiration from rbenv/test/test_helper.bash.
3945

4046
# Unconditionally returns a failing status

lib/log

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,25 @@
2121
# @go.setup_project
2222
# Runs the project's 'setup' script and logs the result
2323
#
24-
# See the function comments for each of the above for further information.
24+
# The log level labels are formatted when output to a terminal, and formatting
25+
# can be forced when writing to a pipe or file by setting `_GO_LOG_FORMATTING`.
26+
#
27+
# `@go.log ERROR` will return an error code, so you may use it in conditional
28+
# statements. `@go.log FATAL` will exit the process.
29+
#
30+
# You can pass entire commands to the `@go.log_command` function, which will
31+
# provide log messages upon startup and completion. Upon error, it will log the
32+
# status and return an error code, so you may use it in conditional statements.
33+
# Wrapping blocks of `@go.log_command` invocations in
34+
# `@go.critical_section_begin` and `@go.critical_section_end` will cause any
35+
# errors to log `FATAL`. Setting `_GO_DRY_RUN` will log the commands without
36+
# executing them.
37+
#
38+
# The `@go.setup_project` function provides a convenient wrapper for running
39+
# first-time project setup scripts. It logs the start and finish of the setup
40+
# script, and provides helpful hints on running the `./go` script upon success.
41+
#
42+
# See the function and variable comments from this file for further information.
2543

2644
# Set this if you want to force terminal-formatted output from @go.log.
2745
#
@@ -229,6 +247,10 @@ declare __GO_CRITICAL_SECTION=0
229247
# the critical section flag will be shared between parent and child Bash
230248
# scripts.
231249
#
250+
# Globals:
251+
# _GO_DRY_RUN: Will log commands without running them
252+
# __GO_CRITICAL_SECTION: Will log FATAL on error
253+
#
232254
# Arguments:
233255
# $@: The command and its arguments to log and execute
234256
@go.log_command() {

tests/vars.bats

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ quotify_expected() {
3535
'declare -ax _GO_CMD_NAME=([0]="vars")'
3636
"declare -rx _GO_CORE_DIR=\"$_GO_CORE_DIR\""
3737
"declare -rx _GO_CORE_URL=\"$_GO_CORE_URL\""
38+
"declare -rx _GO_CORE_VERSION=\"$_GO_CORE_VERSION\""
3839
'declare -a _GO_IMPORTED_MODULES=()'
3940
'declare -- _GO_PLUGINS_DIR=""'
4041
'declare -a _GO_PLUGINS_PATHS=()'
@@ -77,6 +78,7 @@ quotify_expected() {
7778
'declare -ax _GO_CMD_NAME=([0]="test-command" [1]="test-subcommand")'
7879
"declare -rx _GO_CORE_DIR=\"$_GO_CORE_DIR\""
7980
"declare -rx _GO_CORE_URL=\"$_GO_CORE_URL\""
81+
"declare -rx _GO_CORE_VERSION=\"$_GO_CORE_VERSION\""
8082
'declare -a _GO_IMPORTED_MODULES=([0]="complete" [1]="format")'
8183
"declare -- _GO_PLUGINS_DIR=\"$TEST_GO_PLUGINS_DIR\""
8284
"declare -a _GO_PLUGINS_PATHS=(${plugins_paths[*]})"
@@ -112,6 +114,7 @@ quotify_expected() {
112114
"_GO_CMD_NAME: test-command"$'\0'"test-subcommand" \
113115
"_GO_CORE_DIR: $_GO_CORE_DIR" \
114116
"_GO_CORE_URL: $_GO_CORE_URL" \
117+
"_GO_CORE_VERSION: $_GO_CORE_VERSION" \
115118
"_GO_ROOTDIR: $TEST_GO_ROOTDIR" \
116119
"_GO_SCRIPT: $TEST_GO_SCRIPT"
117120
}

0 commit comments

Comments
 (0)