Skip to content

Running Swift Linux Tests on Mac

Trisha Moyer edited this page Jan 19, 2018 · 12 revisions

Running Linux Tests while Developing on Mac

We have prepared a way for users to run the Swift Linux tests while developing on Mac. To do so the user needs to download Docker and have it installed on their machines. Instructions on how to get started can be found in the Docker documentation.

What does our docker image do?

Our Dockerfile is pretty straight forward.

FROM swiftdocker/swift:4.0
ADD . /SwiftSDK
WORKDIR /SwiftSDK
RUN rm -rf /SwiftSDK/.build/debug && swift package resolve && swift package clean
CMD swift test

FROM - The first line creates an image from the swiftdocker Swift version 4.0 base image.
ADD and WORKDIR - Then it creates a directory called SwiftSDK on the docker image, copies the working directory into the new directory, and starts the image from there.
RUN - Next it deletes the .build/debug directory so that it's doesn't have any conflicts on the Docker Container while running the tests. Next it resolves any needed dependencies and cleans the project.
CMD - Finally it runs swift test that will run the Linux Tests.

Running the Tests

The first step is to create a docker image from the Dockerfile we have in the swift-sdk directory.

  1. Open your terminal and navigate to the swift-sdk directory.
  2. Run docker build -t swift-sdk-docker-image . inside that directory.
  3. Run docker run swift-sdk-docker-image:latest

Explanation

Step 1 - You have to be in the directory with the Dockerfile in order to create the image
Step 2 - Create the swift-sdk-docker-image locally on your machine.
Step 3 - Run the swift-sdk-docker-image.

From there on you can make as many changes as you'd like.
Then to test your changes by running the Linux Tests, you need to run:

docker run -v /Path/to/your/directory/swift-sdk:/SwiftSDK swift-sdk-docker-image:latest

Because we already created the docker image we no longer have to recreate it. Now we can just overwrite the files/directories we have in the image and can run the tests. Note: You need to give the fully qualified path to your swift-sdk directory. This is due to the way Docker implements the -v option.

Clone this wiki locally