-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Ignore more files in Docker context * Add scripts to run tests * Run smoke tests in CI * Add smoke tests
- Loading branch information
1 parent
ab66d87
commit 062f515
Showing
13 changed files
with
1,691 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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 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.