Skip to content

Commit

Permalink
Patch release 0.8.1
Browse files Browse the repository at this point in the history
Signed-off-by: Torsten Long <[email protected]>
  • Loading branch information
razziel89 committed Mar 28, 2024
1 parent bfe32e4 commit 5882824
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ coverage: test
# Analyse output of coverage reports and fail if not all files have been
# covered of if coverage is not high enough.
gawk \
-v min_cov="92" \
-v tot_num_files="1" \
-v min_cov="91" \
-v tot_num_files="2" \
'BEGIN{num_files=0; cov=0;} \
$$1 ~ /"file":/{num_files++} \
$$1 ~ /"covered_lines":/{cov=$$2} \
$$1 ~ /"total_lines":/{tot_cov=$$2} \
END{ \
if(num_files!=tot_num_files){ \
printf("Not all files covered: %d < %d\n", num_files, tot_num_files); exit 1 \
printf("Not all files covered: %d != %d\n", num_files, tot_num_files); exit 1 \
} \
} \
END{ \
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ The following tools are needed to use `shellmock`:

- `base32`
- `base64`
- `basename`
- `bash` (at least version 4.4)
- `cat`
- `chmod`
- `env`
- `find`
- `flock`
- `gawk`
- `grep`
- `mkdir`
- `mktemp`
- `ps`
- `rm`
- `sed`
- `sort`
Expand All @@ -67,7 +70,7 @@ The following tools are needed to use `shellmock`:
On Debian-based systems, they can be installed via:

```bash
sudo apt install -yqq bash coreutils findutils gawk grep sed
sudo apt install -yqq bash coreutils findutils gawk grep procps sed util-linux
```

You also need the [bats-core] testing framework that
Expand Down
3 changes: 1 addition & 2 deletions bin/mock_exe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
# stored this way can be used by the main shellmock library to assert
# user-defined expectations.

set -euo pipefail

# Check whether required environment variables are set.
env_var_check() {
local var
Expand Down Expand Up @@ -315,6 +313,7 @@ main() {
# Run if executed directly. If sourced from a bash shell, don't do anything,
# which simplifies testing.
if [[ -z ${BASH_SOURCE[0]-} ]] || [[ ${BASH_SOURCE[0]} == "${0}" ]]; then
set -euo pipefail
main "$@"
else
:
Expand Down
4 changes: 3 additions & 1 deletion go/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Always ignore the sumfile because users won't have one either.
go.sum
/go.sum
# Ignore the build artefact.
/main
5 changes: 1 addition & 4 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,4 @@ module main

go 1.22.1

require (
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8
mvdan.cc/sh/v3 v3.8.0
)
require mvdan.cc/sh/v3 v3.8.0
14 changes: 10 additions & 4 deletions go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ import (
"os"
"slices"

"golang.org/x/exp/maps"
shell "mvdan.cc/sh/v3/syntax"
)

func sortedKeys(data map[string]int) []string {
result := make([]string, 0, len(data))
for key := range data {
result = append(result, key)
}
slices.Sort(result)
return result
}

// Determine all commands executed by a script.
func findCommands(shellCode shell.Node) map[string]int {
result := map[string]int{}
Expand Down Expand Up @@ -66,9 +74,7 @@ func main() {
log.Fatalf("failed to parse shell code: %s", err.Error())
}
commands := findCommands(parsed)
keys := maps.Keys(commands)
slices.Sort(keys)
for _, cmd := range keys {
for _, cmd := range sortedKeys(commands) {
count := commands[cmd]
fmt.Printf("%s:%d\n", cmd, count)
}
Expand Down
11 changes: 10 additions & 1 deletion tests/extended.bats
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,28 @@ EOF
}

@test "that we know which executables shellmock uses" {
run -0 --separate-stderr shellmock commands < "${root}/shellmock.bash"
# Source mock executable to know functions defined therein. Shellmock itself
# has already been sourced, which means we can filter its internal functions.
source "${root}/bin/mock_exe.sh"

code=$(cat "${root}/shellmock.bash" "${root}/bin/mock_exe.sh")
run -0 --separate-stderr shellmock commands <<< "${code}"

exes=(
base32
base64
basename
cat
chmod
env
find
flock
gawk
go
grep
mkdir
mktemp
ps
rm
sed
sort
Expand Down

0 comments on commit 5882824

Please sign in to comment.