-
-
Notifications
You must be signed in to change notification settings - Fork 2
Add smoke tests #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add smoke tests #22
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,6 @@ node_modules | |
.gitattributes | ||
.dockerignore | ||
Dockerfile | ||
test/ | ||
bin/ | ||
!bin/run.sh | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Run the representer on a solution using the representer Docker image. | ||
# The representer Docker image is built automatically. | ||
|
||
# Arguments: | ||
# $1: exercise slug | ||
# $2: absolute path to solution folder | ||
# $3: absolute path to output directory | ||
|
||
# Output: | ||
# Writes the test results to a results.json file in the passed-in output directory. | ||
# The test results are formatted according to the specifications at https://github.com/exercism/docs/blob/main/building/tooling/representers/interface.md | ||
|
||
# Example: | ||
# ./bin/run-in-docker.sh two-fer /absolute/path/to/two-fer/solution/folder/ /absolute/path/to/output/directory/ | ||
|
||
# If any required arguments is missing, print the usage and exit | ||
if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]; then | ||
echo "usage: ./bin/run-in-docker.sh exercise-slug /absolute/path/to/solution/folder/ /absolute/path/to/output/directory/" | ||
exit 1 | ||
fi | ||
|
||
slug="$1" | ||
input_dir="${2%/}" | ||
output_dir="${3%/}" | ||
|
||
# Create the output directory if it doesn't exist | ||
mkdir -p "${output_dir}" | ||
|
||
# Build the Docker image | ||
docker build --rm -t exercism/typescript-representer . | ||
|
||
# Run the Docker image using the settings mimicking the production environment | ||
docker run \ | ||
--rm \ | ||
--network none \ | ||
--read-only \ | ||
--mount type=bind,source="${input_dir}",destination=/solution \ | ||
--mount type=bind,source="${output_dir}",destination=/output \ | ||
--mount type=tmpfs,destination=/tmp \ | ||
exercism/typescript-representer "${slug}" /solution /output |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Test the representer Docker image by running it against a predefined set of | ||
# solutions with an expected output. | ||
# The representer Docker image is built automatically. | ||
|
||
# Output: | ||
# Outputs the diff of the expected representation and mapping against the | ||
# actual representation and mapping generated by the representer. | ||
|
||
# Example: | ||
# ./bin/run-tests-in-docker.sh | ||
|
||
# Build the Docker image | ||
docker build --rm -t exercism/typescript-representer . | ||
|
||
# Run the Docker image using the settings mimicking the production environment | ||
docker run \ | ||
--rm \ | ||
--network none \ | ||
--read-only \ | ||
--mount type=bind,source="${PWD}/test",destination=/opt/representer/test \ | ||
--mount type=tmpfs,destination=/tmp \ | ||
--volume "${PWD}/bin/run-tests.sh:/opt/representer/bin/run-tests.sh" \ | ||
--workdir /opt/representer \ | ||
--entrypoint /opt/representer/bin/run-tests.sh \ | ||
exercism/typescript-representer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Synopsis: | ||
# Test the representer by running it against a predefined set of solutions | ||
# with an expected output. | ||
|
||
# Output: | ||
# Outputs the diff of the expected representation and mapping against the | ||
# actual representation and mapping generated by the representer. | ||
|
||
# Example: | ||
# ./bin/run-tests.sh | ||
|
||
exit_code=0 | ||
|
||
# We need to copy the fixtures to a temp directory as the user | ||
# running within the Docker container does not have permissions | ||
# to run the sed command on the fixtures directory | ||
fixtures_dir="test/fixtures" | ||
tmp_fixtures_dir="/tmp/test/fixtures" | ||
rm -rf "${tmp_fixtures_dir}" | ||
mkdir -p "${tmp_fixtures_dir}" | ||
cp -R ${fixtures_dir}/* "${tmp_fixtures_dir}" | ||
|
||
# Iterate over all test directories | ||
for test_file in $(find "${tmp_fixtures_dir}" -name expected_mapping.json); do | ||
slug=$(echo "${test_file:${#tmp_fixtures_dir}+1}" | cut -d / -f 1) | ||
test_dir=$(dirname "${test_file}") | ||
test_dir_name=$(basename "${test_dir}") | ||
test_dir_path=$(realpath "${test_dir}") | ||
|
||
bin/run.sh "${slug}" "${test_dir_path}" "${test_dir_path}" | ||
|
||
for file in representation.txt mapping.json; do | ||
expected_file="expected_${file}" | ||
echo "${test_dir_name}: comparing ${file} to ${expected_file}" | ||
|
||
if ! diff "${test_dir_path}/${file}" "${test_dir_path}/${expected_file}"; then | ||
exit_code=1 | ||
fi | ||
done | ||
done | ||
|
||
exit ${exit_code} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"IDENTIFIER_0": "Clock", | ||
"IDENTIFIER_1": "hour", | ||
"IDENTIFIER_2": "minute", | ||
"IDENTIFIER_3": "reset", | ||
"IDENTIFIER_4": "totalMinutes", | ||
"IDENTIFIER_5": "adjustTime", | ||
"IDENTIFIER_6": "getHour", | ||
"IDENTIFIER_7": "getMinute", | ||
"IDENTIFIER_8": "formatNumber", | ||
"IDENTIFIER_9": "numberToFormat", | ||
"IDENTIFIER_10": "numberString", | ||
"IDENTIFIER_11": "length", | ||
"IDENTIFIER_12": "plus", | ||
"IDENTIFIER_13": "minutes", | ||
"IDENTIFIER_14": "minus", | ||
"IDENTIFIER_15": "equals", | ||
"IDENTIFIER_16": "clock", | ||
"IDENTIFIER_17": "delta", | ||
"IDENTIFIER_18": "minutesPerDay", | ||
"IDENTIFIER_19": "minutesPerHour", | ||
"IDENTIFIER_20": "hoursPerDay", | ||
"IDENTIFIER_21": "Math", | ||
"IDENTIFIER_22": "abs", | ||
"IDENTIFIER_23": "currentMinutes", | ||
"IDENTIFIER_24": "newMinutes", | ||
"IDENTIFIER_25": "floor" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduces the likelihood of docker layer cache invalidation