Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Ignore build outputs and caches to speed up context when copying (if ever used)
**/build/
**/.gradle/
**/.idea/
**/.vscode/
**/.git/
**/.gitignore
**/*.o
**/*.so
**/*.dll
**/*.dylib
**/parser
**/libparser.*
26 changes: 12 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,35 @@ name: CI

on:
pull_request:
branches: [ main, lexer ]
push:

permissions:
contents: read
checks: write
pull-requests: write

jobs:
test:
docker-tests:
name: Docker Integration Tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Ensure Docker is available
run: docker --version

- name: Run tests
run: ./gradlew tests:test
- name: Run integration + JUnit tests via Docker
shell: bash
run: |
set -euo pipefail
bash ./docker_test.sh

- name: Generate test report
- name: Publish JUnit Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: JUnit Tests
name: JUnit Tests (Docker)
path: 'tests/build/test-results/test/*.xml'
reporter: java-junit
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Dev/test container for building and running the compiler tests
# Avoids OS-specific issues by standardizing on Ubuntu + toolchain

FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
bison \
flex \
openjdk-21-jdk-headless \
ca-certificates \
git \
bash \
&& rm -rf /var/lib/apt/lists/*

# Set JAVA_HOME for JNI header generation
ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
ENV PATH="$JAVA_HOME/bin:$PATH"

WORKDIR /app

# Default entrypoint is bash; we'll mount the repo at /app and run our script
ENTRYPOINT ["/bin/bash"]
75 changes: 0 additions & 75 deletions compiler/src/main/java/integration_test.sh

This file was deleted.

94 changes: 0 additions & 94 deletions compiler/src/main/java/integration_test.sh.old

This file was deleted.

32 changes: 32 additions & 0 deletions docker_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail

IMAGE="hmm-compiler-test:latest"

echo "[1/2] Building Docker image: ${IMAGE}"
docker build -t "${IMAGE}" .

# Resolve host path in a Docker-friendly way across Windows Git Bash and Unix shells
HOST_PATH="${PWD}"
UNAME_S=$(uname -s || echo "")
if [[ "$UNAME_S" == MINGW* || "$UNAME_S" == MSYS* || "$UNAME_S" == CYGWIN* ]]; then
# On Git Bash/MSYS, prefer Windows-style path for Docker volume mounts
if command -v pwd >/dev/null 2>&1 && pwd -W >/dev/null 2>&1; then
HOST_PATH=$(pwd -W)
fi
fi

echo "[2/2] Running tests inside Docker container"
# Prevent MSYS from rewriting /app into a Windows path; set working dir explicitly
MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL="*" \
docker run --rm -t \
-v "${HOST_PATH}:/app" \
-w "/app" \
"${IMAGE}" \
-lc "set -euo pipefail; \
find . -type f -name '*.sh' -exec sed -i 's/\r$//' {} + ; \
bash ./integration_test.sh; \
export LD_LIBRARY_PATH=/app/compiler/src/main/cpp/parser; \
echo \"LD_LIBRARY_PATH=\$LD_LIBRARY_PATH\"; \
chmod +x ./gradlew; \
./gradlew --no-daemon tests:test -Djava.library.path=/app/compiler/src/main/cpp/parser"
32 changes: 32 additions & 0 deletions docs/docker-testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Running Compiler Tests via Docker

This project includes a containerized test environment so tests run identically across Windows, macOS, and Linux.

## Prerequisites

- Docker Desktop (Windows/macOS) or Docker Engine (Linux)
- No need to install GCC, Make, Bison, Flex, or JDK locally

## One-command run

From the project root:

```bash
./docker_test.sh
```

What this does:
- Builds a Docker image with build tools (gcc/g++, make), bison, flex, and JDK 21
- Mounts the current workspace into the container
- Runs `./integration_test.sh` inside the container

## Notes

- The C++ parser is rebuilt inside the container; any prebuilt binaries in your repo are cleaned first.
- The test script will auto-generate the JNI header (`compiler_lexer_Lexer.h`) if it is missing using `javac -h`.
- If you change code, just re-run `./docker_test.sh`; no need to rebuild the image unless Dockerfile changes.

## Troubleshooting

- If Docker complains about permissions on the mounted volume, run the script from a path Docker can access (e.g., inside your user directory) and ensure file sharing is enabled in Docker Desktop settings.
- If you are on WSL2, you can run the same command inside your WSL shell.
Loading