Skip to content

Commit 620a1d6

Browse files
authored
run.sh needs to handle exercises with only one test (#14)
* run.sh needs to handle exercises with only one test In the case where there is only one test, the Odin test runner outputs "Finished 1 test ...". The runner script was always expecting the plural "tests". Fixes #13 * add a test * turn on shell tracing for debugging * undo "slimmed" image, * remove verbose execution from run-tests.sh
1 parent 3313f91 commit 620a1d6

File tree

7 files changed

+45
-27
lines changed

7 files changed

+45
-27
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ Dockerfile
77
bin/run-in-docker.sh
88
bin/run-tests-in-docker.sh
99
bin/run-tests.sh
10+
bin/benchmark.sh
11+
bin/benchmark-in-docker.sh
1012
tests/

Dockerfile

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
ARG ODIN_REF=dev-2025-10
44

5-
# ---------- Build stage ----------
6-
FROM ubuntu:24.04 AS build
5+
FROM ubuntu:24.04
76

87
ENV DEBIAN_FRONTEND=noninteractive
98
RUN apt-get update && apt-get install -y --no-install-recommends \
10-
git build-essential make ca-certificates jq \
11-
clang-18 llvm-18-dev \
9+
git build-essential make ca-certificates \
10+
clang-18 llvm-18-dev clang \
11+
jq gawk locales\
1212
&& update-ca-certificates \
13+
&& locale-gen en_US.UTF-8 \
1314
&& rm -rf /var/lib/apt/lists/*
1415

1516
WORKDIR /src
@@ -23,26 +24,9 @@ RUN make -j"$(nproc)" release-native LLVM_CONFIG=llvm-config-18
2324
# Fix a bug in this Odin release. When we upgrade, revisit this.
2425
RUN sed -E -i '983,984s/\<err\>/marshal_err/g' /src/Odin/core/testing/runner.odin
2526

26-
# ---------- Runtime stage ----------
27-
FROM ubuntu:24.04 AS runtime
28-
29-
ENV DEBIAN_FRONTEND=noninteractive
30-
RUN apt-get update && apt-get install -y --no-install-recommends \
31-
ca-certificates libstdc++6 libllvm18 \
32-
clang lld build-essential \
33-
jq gawk locales \
34-
&& update-ca-certificates \
35-
&& locale-gen en_US.UTF-8 \
36-
&& rm -rf /var/lib/apt/lists/*
37-
38-
# Odin binary and libraries
39-
COPY --from=build /src/Odin/odin /usr/local/bin/odin
40-
COPY --from=build /src/Odin/core /usr/local/lib/odin/core
41-
COPY --from=build /src/Odin/vendor /usr/local/lib/odin/vendor
42-
COPY --from=build /src/Odin/base /usr/local/lib/odin/base
43-
4427
ENV LC_ALL=en_US.UTF-8
45-
ENV ODIN_ROOT=/usr/local/lib/odin
28+
ENV ODIN_ROOT=/src/Odin
29+
ENV PATH="/src/Odin:${PATH}"
4630

4731
WORKDIR /opt/test-runner
4832
COPY ./bin/ bin/

bin/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ for test_dir in tests/*; do
1818
test_dir_name=$(basename "${test_dir}")
1919
test_dir_path=$(realpath "${test_dir}")
2020

21-
bash -x bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}"
21+
bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}"
2222

2323
# OPTIONAL: Normalize the results file
2424
# If the results.json file contains information that changes between

bin/run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ run_tests() {
5454
sanitize_odin_test_output() {
5555
gawk -v pwd="${PWD}/" '
5656
/To run only the failed test,/ {exit}
57-
/Finished [[:digit:]]+ tests in / { sub(/ in [[:digit:].]+.s/, "") }
57+
/Finished [[:digit:]]+ tests? in / { sub(/ in [[:digit:].]+.s/, "") }
5858
{
5959
gsub(pwd, "") # trim full paths from filenames
6060
print
@@ -77,7 +77,7 @@ write_results_v1() {
7777
if (( rc == 0 )); then
7878
jq -n '{version: 1, status: "pass"}' > "${results_file}"
7979
else
80-
if [[ $test_output =~ .*$'\nFinished '[[:digit:]]+' tests.'.* ]]; then
80+
if [[ $test_output =~ .*$'\nFinished '[[:digit:]]+' test'.* ]]; then
8181
# Successfully compiled, but test failures
8282
status='fail'
8383
else
@@ -235,7 +235,7 @@ parse_odin_test_output() {
235235

236236
while IFS= read -r line; do
237237
if ! $seen_finished; then
238-
if [[ $line == "Finished "*" tests. "*" test"*"failed." ]]; then
238+
if [[ $line == "Finished "*" test"?(s)". "*" test"*"failed." ]]; then
239239
seen_finished=true
240240
fi
241241
else
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"version": 3,
3+
"status": "fail",
4+
"tests": [
5+
{
6+
"name": "No name given",
7+
"message": "expected two_fer() to be One for you, one for me., got One for failure, one for me.",
8+
"status": "fail",
9+
"task_id": "1",
10+
"test_code": "testing.expect_value(t, two_fer(), \"One for you, one for me.\")"
11+
}
12+
]
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package one_test_failure
2+
3+
import "core:fmt"
4+
5+
two_fer :: proc(name: string = "failure") -> string {
6+
return fmt.tprintf("One for {}, one for me.", name)
7+
}
8+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package one_test_failure
2+
3+
import "core:testing"
4+
5+
@(test)
6+
/// description = No name given
7+
/// task_id = 1
8+
test_no_name_given :: proc(t: ^testing.T) {
9+
testing.expect_value(t, two_fer(), "One for you, one for me.")
10+
}
11+

0 commit comments

Comments
 (0)