Skip to content
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

Fix test runner #22

Merged
merged 25 commits into from
Sep 7, 2021
Merged

Fix test runner #22

merged 25 commits into from
Sep 7, 2021

Conversation

2Grey
Copy link
Contributor

@2Grey 2Grey commented Sep 3, 2021

Fixes for #21

  • Fix default value for showSkipped flag
  • Fix creating output directory if doesn't exist
  • Fix run.sh script

Runs

Direct launch of TestRunner

./bin/TestRunner --slug freelancer-rates --solution-directory ./freelancer-rates --output-directory ./Out --swift-location $(which swift) --build-directory "/tmp"

Result

{
    "status" : "pass",
    "tests" : [
        {
            "name" : "FreelancerRatesTests.FreelancerRatesTests testdailyRateFrom",
            "status" : "pass"
        }
    ]
}

Script run of TestRunner

./bin/run.sh freelancer-rates ./freelancer-rates ./Out

Result

{
  "status" : "pass",
  "tests" : [
    {
      "name" : "FreelancerRatesTests.FreelancerRatesTests testdailyRateFrom",
      "status" : "pass"
    },
    {
      "name" : "FreelancerRatesTests.FreelancerRatesTests testmonthlyRoundDown",
      "status" : "pass"
    },
    {
      "name" : "FreelancerRatesTests.FreelancerRatesTests testmonthlyRoundUp",
      "status" : "pass"
    },
    {
      "name" : "FreelancerRatesTests.FreelancerRatesTests testworkdaysIn",
      "status" : "pass"
    },
    {
      "name" : "FreelancerRatesTests.FreelancerRatesTests testworkdaysShouldRoundDown",
      "status" : "pass"
    }
  ]
}
freelancer-rates: comparing ./Out/results
diff: ./freelancer-rates/freelancer-rates/results.json: No such file or directory

@2Grey 2Grey requested a review from a team as a code owner September 3, 2021 12:01
@iHiD
Copy link
Member

iHiD commented Sep 3, 2021

Thanks @2Grey :)

@ErikSchierboom will take a look at this on Tuesday if no-one else gets to it first!

@@ -1 +1,2 @@
test/output
.github/
tests/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are passed to the test scripts via a volume mount, but they don't have to be present when building the Dockerfile. Having them here has the benefit of being able to change the tests without having to rebuild the Docker image.

@@ -1,42 +1,51 @@
# Exercism Swift Test Runner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this file to make it similar to existing test runner READMEs, which was needed because I change the test script files to be consistent too.

# build docker image
docker build --rm --no-cache -t swift-test-runner .

docker run \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were several options missing here, including a key one: --network none. Other test runners have this file named run-all-tests-in-docker, so I've renamed the file and added the right flags that match how the test runner is actually run on the website.

echo "usage: run-in-docker.sh exercise-slug ./relative/path/to/solution/folder/ ./relative/path/to/output/directory/"
printHelpAndExit() {
echo -e "${ORANGE}USAGE${NC}"
echo -e " ./run-in-docker.sh ${GREEN}-s${NC} two-fer ${GREEN}-i${NC} /absolute/path/to/solution/folder/ ${GREEN}-o${NC} ./absolute/path/to/output/directory/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've converted the relative paths to absolute paths as there is no guarantee that the path is relative (see https://github.com/exercism/docs/blob/main/building/tooling/test-runners/docker.md) and in fact it is more likely for it to be absolute.

# build docker image
docker build --rm --no-cache -t swift-test-runner .
docker build --rm --no-cache -t exercism/swift-test-runner .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual name we use for the test runner, so adding the prefix ensure that the local development environment uses this built version.

Comment on lines 66 to 70
--network none \
--read-only \
--mount type=bind,src="${INPUT_DIR}",dst=/solution \
--mount type=bind,src="${OUTPUT_DIR}",dst=/output \
--mount type=volume,dst=/tmp \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the proper flags here

Comment on lines 20 to 25
--network none \
--read-only \
--mount type=bind,src="${PWD}/tests",dst=/opt/test-runner/tests \
--mount type=volume,dst=/tmp \
--workdir /opt/test-runner \
--entrypoint /opt/test-runner/bin/run-tests.sh \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the proper flags here

# echo "-------------"
RUNALL=true "${BASEDIR}"/TestRunner --slug "${SLUG}" --solution-directory "${INPUT_DIR}/${SLUG}" --output-directory "${OUTPUT_DIR}" --swift-location $(which swift) --build-directory "/tmp/"

RUNALL=true "${BASEDIR}"/TestRunner --slug "${SLUG}" --solution-directory "${INPUT_DIR}" --output-directory "${OUTPUT_DIR}" --swift-location $(which swift) --build-directory "/tmp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the /${SLUG} argument from the solution directory as the solution directory should be the argument that is passed in.

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for fixing the test runner. I've done a bit of work to get the test runner to adhere to the spec fully, but it has succeeded!

- '.gitignore'
- 'LICENSE'
- '**.md'
- main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We renamed the branch to main

.DS_Store
**/.build
**/Packages
**/Package.resolved
**/*.xcodeproj
bin/TestRunner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually don't store binaries in our repos

Comment on lines +7 to +9
# $1: exercise slug
# $2: absolute path to solution folder
# $3: absolute path to output directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed this file to take positional arguments as that is how the interface requires it.

@ErikSchierboom ErikSchierboom added the x:size/large Large amount of work label Sep 7, 2021
@ErikSchierboom
Copy link
Member

Let me know if there is anything you want to know about the commits I added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
x:size/large Large amount of work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants