Skip to content

Commit

Permalink
Add reporting for copy action (#86)
Browse files Browse the repository at this point in the history
* Add reporting for copy action

* Action reporter

* Add summary method

* Update action handlers to use reporter

* Passing tests

* Add CLI integration tests

* Use shasum

* Fix optional reporter

* Configurable log level

* Add integrationTests README

* Add copy test

* Add test for console log level

* Update summary -> printSummary

* Allow configuring of log level from the command line

* Add configure loglevel integration test
  • Loading branch information
cbush authored Apr 22, 2022
1 parent c11c693 commit 2b37a07
Show file tree
Hide file tree
Showing 38 changed files with 12,337 additions and 157 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ name: Node.js CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
build:

runs-on: ubuntu-latest

strategy:
Expand All @@ -20,11 +19,12 @@ jobs:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test
- run: cd integrationTests && ./runTests.sh
2 changes: 2 additions & 0 deletions integrationTests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
output/

54 changes: 54 additions & 0 deletions integrationTests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# CLI Integration Tests

These tests run the CLI and ensure that a CLI command on an "input" directory
results in an "output" directory that perfectly matches the "expected"
directory.

More thorough testing of actions should be done in unit tests. This is just
another layer of assurance that the CLI is not broken when you make changes.

## Run All Tests

To run the tests:

```sh
./runTests.sh
```

This does the following:

- Builds the latest Bluehawk executable
- Runs all "test.sh" files found in subdirectories
- Checksum-compares the contents of each test's "output" and "expected" directories

## Run a Specific Test

The "runTests.sh" script optionally takes one argument. This can be the
directory name that contains a test.sh file.

The following example will only run the "snip" test:

```sh
./runTests.sh snip
```

## Add a Test

To create a test, copy an existing test as a template:

```sh
cp -R ./snip myNewTest
```

Within your new test directory, create input files (if needed) in a directory
called "input".

Create the expected result file(s) and place them in a directory called
"expected".

Update the command in "myNewTest/test.sh" to the command you want to test. The
`$BLUEHAWK` environment variable will be set to the current development build.

Ensure the output of your command is sent to a directory called "output".

Use the parent directory's "runTests.sh" script to run your test.
6 changes: 6 additions & 0 deletions integrationTests/copy/expected/state1/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Hi, this is a sample text.

This text should be in state1

That's all, folks!

6 changes: 6 additions & 0 deletions integrationTests/copy/expected/state2/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Hi, this is a sample text.

This text should be in state2

That's all, folks!

11 changes: 11 additions & 0 deletions integrationTests/copy/input/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Hi, this is a sample text.

:state-start: state1
This text should be in state1
:state-end:
:state-start: state2
This text should be in state2
:state-end:

That's all, folks!

9 changes: 9 additions & 0 deletions integrationTests/copy/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -e

cd "$(dirname "$0")"

rm -rf output
mkdir output

$BLUEHAWK copy --state state1 -d ./output/state1 input
$BLUEHAWK copy --state state2 -d ./output/state2 input
5 changes: 5 additions & 0 deletions integrationTests/logLevel/expected/logLevel0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Processed 3 files:
- 0 binary files
- 3 text files
- 2 errors
- 0 files written
9 changes: 9 additions & 0 deletions integrationTests/logLevel/expected/logLevel1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bluehawk errors on path/to/project/input/sample.txt:
(parser) Line 11:1 - 11:1(162) blockTag: After Newline, expected TagEnd but found EOF
bluehawk errors on path/to/project/input/sample.txt:
(parser) Line 11:1 - 11:1(162) blockTag: After Newline, expected TagEnd but found EOF
Processed 3 files:
- 0 binary files
- 3 text files
- 2 errors
- 0 files written
10 changes: 10 additions & 0 deletions integrationTests/logLevel/expected/logLevel2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bluehawk errors on path/to/project/input/sample.txt:
(parser) Line 11:1 - 11:1(162) blockTag: After Newline, expected TagEnd but found EOF
bluehawk errors on path/to/project/input/sample.txt:
(parser) Line 11:1 - 11:1(162) blockTag: After Newline, expected TagEnd but found EOF
state not found: notfound
Processed 3 files:
- 0 binary files
- 3 text files
- 2 errors
- 0 files written
11 changes: 11 additions & 0 deletions integrationTests/logLevel/expected/logLevel3
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
parsed file: path/to/project/input/normalFile.txt
bluehawk errors on path/to/project/input/sample.txt:
(parser) Line 11:1 - 11:1(162) blockTag: After Newline, expected TagEnd but found EOF
bluehawk errors on path/to/project/input/sample.txt:
(parser) Line 11:1 - 11:1(162) blockTag: After Newline, expected TagEnd but found EOF
state not found: notfound
Processed 3 files:
- 0 binary files
- 3 text files
- 2 errors
- 0 files written
Empty file.
11 changes: 11 additions & 0 deletions integrationTests/logLevel/input/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Hi, this is a sample text.



:snippet-start: test-one
This text should be in test-one

Yes I forgot to close this snippet to force an error.

That's all, folks!

21 changes: 21 additions & 0 deletions integrationTests/logLevel/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash -e

cd "$(dirname "$0")"

rm -rf output
mkdir output

# These are meant to cause errors, so don't fail out the script.
set +e

for LOGLEVEL in 0 1 2 3
do
# - Ignore the actual output, just look at the logs
# - Use a state that is not actually found to trigger the state not found warning
# - Set the log level to each possible level
# - Redirect stderr to stdout
# - Pipe to sed, delete any instances of your computer name
# - Pipe to a file
$BLUEHAWK snip -d output/ignoreThis --state notfound --logLevel $LOGLEVEL input 2>&1 | sed -e "s!$(pwd)!path/to/project!g" > output/logLevel$LOGLEVEL
done
set -e
43 changes: 43 additions & 0 deletions integrationTests/runTests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash -e

# Local build setup
pushd "$(dirname "$0")" > /dev/null
pushd .. > /dev/null
PROJECT_ROOT="`pwd`"
npm install
npm run build
popd > /dev/null
export BLUEHAWK="node $PROJECT_ROOT/build/src/main"

function checksum() {
pushd "$1" > /dev/null
CHECKSUM_RESULT=`find . -type f ! -name ".DS_Store" -exec shasum {} + | sort | shasum`
popd > /dev/null
}

# Select tests
if [ -z "$1" ]
then
TESTS=`find . -name "test.sh"`
else
TESTS="$1"/test.sh
fi

# Run tests
for TEST in $TESTS
do
TEST_DIR="$(dirname "$TEST")"
"$TEST"
checksum ./"$TEST_DIR"/expected
EXPECTED_CHECKSUM=$CHECKSUM_RESULT
checksum ./"$TEST_DIR"/output
OUTPUT_CHECKSUM=$CHECKSUM_RESULT
if [ "$EXPECTED_CHECKSUM" != "$OUTPUT_CHECKSUM" ]
then
echo "Test failed: $TEST_DIR"
echo "Compare ./$TEST_DIR/expected and ./$TEST_DIR/output to debug."
exit 1
else
echo "✅ Test passed: $TEST_DIR"
fi
done
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This text should be in test-one
8 changes: 8 additions & 0 deletions integrationTests/snip/input/sample.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Hi, this is a sample text.

:snippet-start: test-one
This text should be in test-one
:snippet-end:

That's all, folks!

8 changes: 8 additions & 0 deletions integrationTests/snip/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

cd "$(dirname "$0")"

rm -rf output
mkdir output

$BLUEHAWK snip -d ./output input
Loading

0 comments on commit 2b37a07

Please sign in to comment.