Skip to content

Commit

Permalink
hello: assert_files_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefbiiko committed May 19, 2021
1 parent ef9a8b8 commit 3cf0dbb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-11.0]
os: [ubuntu-20.04, macos-10.15]
steps:
- uses: actions/[email protected]

- name: run the example test case on ubuntu
if: startsWith(matrix.os, 'ubuntu')
run: |
source <(curl -sSf https://raw.githubusercontent.com/chiefbiiko/bashert/v1.0.1/bashert.sh)
source <(curl -sSf https://raw.githubusercontent.com/chiefbiiko/bashert/v1.1.0/bashert.sh)
source ./test_suite.sh
test_users_list_200
Expand All @@ -24,4 +24,5 @@ jobs:
run: |
source ./bashert.sh
source ./test_suite.sh
test_users_list_200
test_users_list_200
test_assert_files_equal
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2020 Noah Anabiik Schwarz
Copyright (c) 2020-2021 Noah Anabiik Schwarz

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ assert_status ./curl_header_dump 204
assert_equal twin twin
assert_not_equal fraud fr@ud
assert_match acab '^acab|ACAB$'
assert_files_equal ./a ./b
assert_files_equal_ignore_space ./a ./b
assert_gt 419 255
assert_lt -1 0
Expand All @@ -28,17 +29,14 @@ use `lurc` instead of plain `curl` to require `TLS 1.2` for every connection and

## usage

free 2 use however u like

anyways, find my personal usage conventions illustrated below

> obviously, this needs 2 run in `bash` and you probly also want tools like `curl` and `jq` available in that shell - fortunately, when using github actions `ubuntu-*` and `macos-*` runners we get `curl` and `jq` preinstalled amongst other things
`touch` two files `test_suite.sh` and `.github/workflows/ci.yml` as below
### `test_suite.sh`

define a test case with a simple `bash` function declaration making use of the provided assertion helpers, fx:
source `bashert.sh` from a local copy or via the network, then define test cases with simple `bash` function declarations making use of the provided assertion helpers, fx:

```bash
source <(curl -sSf https://raw.githubusercontent.com/chiefbiiko/bashert/v1.1.0/bashert.sh)

test_users_list_200() {
printf "test_users_list_200\n"

Expand All @@ -65,22 +63,22 @@ test_users_list_200() {
}
```

> `source`ing from a url like above only works on `ubuntu` runners
### `.github/workflows/ci.yml`

1. source `bashert.sh` from a local copy or via the network
2. source your custom `test_suite.sh`
3. call your `bash` test case functions
1. source your custom `test_suite.sh`
2. call your `bash` test case functions

```bash
steps:
- uses: actions/[email protected]
- run: |
source <(curl -sSf https://raw.githubusercontent.com/chiefbiiko/bashert/v1.0.1/bashert.sh)
source ./test_suite.sh
test_users_list_200
```

> `source`ing from a url like above only works on `ubuntu` runners
> obviously, this needs 2 run in `bash` and you probly also want tools like `curl` and `jq` available in that shell - fortunately, when using github actions `ubuntu-*` and `macos-*` runners we get `curl` and `jq` preinstalled amongst other things
## license

Expand Down
13 changes: 13 additions & 0 deletions bashert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ assert_files_equal_ignore_space() {
fi
}

assert_files_equal() {
# usage: assert_files_equal "$file_a" "$file_b"
if [[ ! -f "$1" ]] || [[ ! -f "$2" ]]; then
>&2 printf "[assert_files_equal] missing file params\n"
exit 1
fi

if ! cmp --silent "$1" "$2"; then
>&2 printf "file contents are not equal\n"
exit 1
fi
}

assert_gt() {
# usage: assert_gt $a $b
if [[ -z "$1" ]] || [[ -z "$2" ]]; then
Expand Down
14 changes: 14 additions & 0 deletions test_suite.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
source ./bashert.sh

test_users_list_200() {
printf "test_users_list_200\n"

Expand All @@ -21,4 +23,16 @@ test_users_list_200() {

assert_equal $id 1
assert_match "$username" '^[a-zA-Z0-9_-]+$'
}

test_assert_files_equal() {
printf "test_assert_files_equal\n"

file_a=$(mktemp)
file_b=$(mktemp)
file_c=$(mktemp)
head -c 419 </dev/urandom > $file_a
cp $file_a $file_b

assert_files_equal $file_a $file_b
}

0 comments on commit 3cf0dbb

Please sign in to comment.