Skip to content

Commit 0a38bcd

Browse files
Optimize test runner (#6)
This commit optimizes the test runner by doing two things: 1. Not copying the `node_modules` and `bower_components` directories but instead symlinking to them 2. Pre-compiling a fake purescript application and copying its `output` directory to the solution's directory. This prevents recompiling the core libraries for each solution
1 parent af6b4e8 commit 0a38bcd

File tree

8 files changed

+51
-12
lines changed

8 files changed

+51
-12
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
.*.swp
33
*.cabal
44
stack.yaml
5-
tests/*/node_modules/
6-
tests/*/bower_components/
5+
tests/*/node_modules
6+
tests/*/bower_components
77
tests/*/.pulp-cache/
88
tests/*/output/
99
tests/*/results.json

Dockerfile

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ RUN apt-get update && \
88

99
WORKDIR /opt/test-runner
1010

11-
# Pre-install packages
12-
COPY package.json package-lock.json ./
11+
ENV PATH="/opt/test-runner/node_modules/.bin:$PATH"
12+
13+
COPY pre-compiled/package.json pre-compiled/package-lock.json ./
1314
RUN npm install
1415

15-
COPY bower.json .
16-
RUN ./node_modules/.bin/bower install --allow-root
16+
COPY pre-compiled/bower.json .
17+
RUN bower install --allow-root
1718

18-
# TODO: pre-compile standard library and copy output directory in run.sh
19+
COPY pre-compiled/ .
20+
RUN pulp build
1921

2022
COPY . .
2123
ENTRYPOINT ["/opt/test-runner/bin/run.sh"]

bin/run.sh

+3-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ echo "${slug}: testing..."
3434

3535
pushd "${input_dir}" > /dev/null
3636

37-
cp -r "${root_dir}/node_modules" .
38-
cp -r "${root_dir}/bower_components" .
39-
40-
# Required to have pulp find the `purs` executable
41-
export PATH="./node_modules/.bin:$PATH"
37+
ln -s "${root_dir}/node_modules"
38+
ln -s "${root_dir}/bower_components"
39+
cp -r "${root_dir}/output" . # We can't symlink this as pulp needs to write to it
4240

4341
# Run the tests for the provided implementation file and redirect stdout and
4442
# stderr to capture it
File renamed without changes.
File renamed without changes.
File renamed without changes.

pre-compiled/src/Leap.purs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module Leap where
2+
3+
import Prelude
4+
5+
isLeapYear :: Int -> Boolean
6+
isLeapYear year =
7+
mod year 4 == 0 &&
8+
mod year 100 /= 0 ||
9+
mod year 400 == 0

pre-compiled/test/Main.purs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module Test.Main where
2+
3+
import Prelude
4+
5+
import Effect (Effect)
6+
import Test.Unit (TestSuite, suite, test)
7+
import Test.Unit.Main (runTest)
8+
import Test.Unit.Assert as Assert
9+
import Leap as Leap
10+
11+
main :: Effect Unit
12+
main = runTest suites
13+
14+
suites :: TestSuite
15+
suites = do
16+
suite "Leap.isLeapYear" do
17+
test "leap year" do
18+
Assert.equal true $ Leap.isLeapYear 1996
19+
test "non-leap year" do
20+
Assert.equal false $ Leap.isLeapYear 1997
21+
test "non-leap even year" do
22+
Assert.equal false $ Leap.isLeapYear 1998
23+
test "century" do
24+
Assert.equal false $ Leap.isLeapYear 1900
25+
test "second century" do
26+
Assert.equal false $ Leap.isLeapYear 1800
27+
test "fourth century" do
28+
Assert.equal true $ Leap.isLeapYear 2400
29+
test "y2k" do
30+
Assert.equal true $ Leap.isLeapYear 2000

0 commit comments

Comments
 (0)