diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dc92867 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +# Minimal Dockerfile for building and testing kte on Linux +# This container provides a build environment with all dependencies. +# Mount the source tree at /kte when running the container. +FROM ubuntu:22.04 + +# Avoid interactive prompts during package installation +ENV DEBIAN_FRONTEND=noninteractive + +# Install build dependencies +RUN apt-get update && apt-get install -y \ + build-essential \ + cmake \ + libncursesw5-dev \ + && rm -rf /var/lib/apt/lists/* + +# Set working directory where source will be mounted +WORKDIR /kte + +# Default command: build and run tests +CMD ["sh", "-c", "cmake -B build -DBUILD_GUI=OFF -DBUILD_TESTS=ON && cmake --build build --target kte && cmake --build build --target kte_tests && ./build/kte_tests"] diff --git a/docker-build.sh b/docker-build.sh new file mode 100755 index 0000000..ab4e040 --- /dev/null +++ b/docker-build.sh @@ -0,0 +1,28 @@ +#!/bin/bash +# Helper script to test Linux builds using Docker/Podman +# This script mounts the current source tree into a Linux container, +# builds kte in terminal-only mode, and runs the test suite. + +set -e + +# Detect whether to use docker or podman +if command -v docker &> /dev/null; then + CONTAINER_CMD="docker" +elif command -v podman &> /dev/null; then + CONTAINER_CMD="podman" +else + echo "Error: Neither docker nor podman found in PATH" + exit 1 +fi + +IMAGE_NAME="kte-linux" + +# Check if image exists, if not, build it +if ! $CONTAINER_CMD image inspect "$IMAGE_NAME" &> /dev/null; then + echo "Building $IMAGE_NAME image..." + $CONTAINER_CMD build -t "$IMAGE_NAME" . +fi + +# Run the container with the current directory mounted +echo "Running Linux build and tests..." +$CONTAINER_CMD run --rm -v "$(pwd):/kte" "$IMAGE_NAME" diff --git a/docs/DEVELOPER_GUIDE.md b/docs/DEVELOPER_GUIDE.md index a82391c..599ee2e 100644 --- a/docs/DEVELOPER_GUIDE.md +++ b/docs/DEVELOPER_GUIDE.md @@ -292,6 +292,129 @@ Test files by category: **Total**: 98 tests across 22 test files. See `docs/BENCHMARKS.md` for performance benchmark results. +### Docker/Podman for Linux Builds + +A minimal `Dockerfile` is provided for **testing Linux builds** without +requiring a native Linux system. The Dockerfile creates a build +environment container with all necessary dependencies. Your source tree +is mounted into the container at runtime, allowing you to test +compilation and run tests on Linux. + +**Important**: This is intended for testing Linux builds, not for +running +kte locally. The container expects the source tree to be mounted when +run. + +This is particularly useful for: + +- **macOS/Windows developers** testing Linux compatibility +- **CI/CD pipelines** ensuring cross-platform builds +- **Reproducible builds** with a known Ubuntu 22.04 environment + +#### Prerequisites + +Install Docker or Podman: + +- **macOS**: `brew install podman` (Docker Desktop also works) +- **Linux**: Use your distribution's package manager +- **Windows**: Docker Desktop or Podman Desktop + +If using Podman on macOS, start the VM: + +```bash +podman machine init +podman machine start +``` + +#### Building the Docker Image + +The Dockerfile only installs build dependencies (g++ 11.4.0, CMake 3.22, +libncursesw5-dev). It does not copy or build the source code. + +From the project root: + +```bash +# Build the environment image +docker build -t kte-linux . + +# Or with Podman +podman build -t kte-linux . +``` + +#### Testing Linux Builds + +Mount your source tree and run the build + tests: + +```bash +# Build and test (default command) +docker run --rm -v "$(pwd):/kte" kte-linux + +# Expected output: "98 tests passed, 0 failed" +``` + +The default command builds kte in terminal-only mode (`-DBUILD_GUI=OFF`) +and runs the full test suite. + +#### Custom Build Commands + +```bash +# Open a shell in the build environment +docker run --rm -it -v "$(pwd):/kte" kte-linux /bin/bash + +# Then inside the container: +cmake -B build -DBUILD_GUI=OFF -DBUILD_TESTS=ON +cmake --build build --target kte +cmake --build build --target kte_tests +./build/kte_tests + +# Or run kte directly +./build/kte --help +``` + +#### Running kte Interactively + +To test kte's terminal UI on Linux: + +```bash +# Run kte with a file from your host system +docker run --rm -it -v "$(pwd):/kte" kte-linux sh -c "cmake -B build -DBUILD_GUI=OFF && cmake --build build --target kte && ./build/kte README.md" +``` + +#### CI/CD Integration + +Example GitHub Actions workflow: + +```yaml +- name: Test Linux Build + run: | + docker build -t kte-linux . + docker run --rm -v "${{ github.workspace }}:/kte" kte-linux +``` + +#### Troubleshooting + +**"Cannot connect to Podman socket"** (macOS): + +```bash +podman machine start +``` + +**"Permission denied"** (Linux): + +```bash +# Add your user to the docker group +sudo usermod -aG docker $USER +# Log out and back in +``` + +**Build fails with ncurses errors**: +The Dockerfile explicitly installs `libncursesw5-dev` (wide-character +ncurses). If you modify the Dockerfile, ensure this dependency remains. + +**"No such file or directory" errors**: +Ensure you're mounting the source tree with `-v "$(pwd):/kte"` when +running the container. + ### Writing Tests When adding new functionality: diff --git a/tests/Test.h b/tests/Test.h index d7a326e..cb6ae80 100644 --- a/tests/Test.h +++ b/tests/Test.h @@ -57,7 +57,9 @@ template inline void assert_eq_impl(const A &a, const B &b, const char *ea, const char *eb, const char *file, int line) { - if (!(a == b)) { + // Cast to common type to avoid signed/unsigned comparison warnings + using Common = std::common_type_t; + if (!(static_cast(a) == static_cast(b))) { std::ostringstream oss; oss << file << ":" << line << ": ASSERT_EQ failed: " << ea << " == " << eb; throw AssertionFailure{oss.str()}; @@ -72,4 +74,4 @@ assert_eq_impl(const A &a, const B &b, const char *ea, const char *eb, const cha #define EXPECT_TRUE(x) ::ktet::expect((x), #x, __FILE__, __LINE__) #define ASSERT_TRUE(x) ::ktet::assert_true((x), #x, __FILE__, __LINE__) -#define ASSERT_EQ(a,b) ::ktet::assert_eq_impl((a),(b), #a, #b, __FILE__, __LINE__) +#define ASSERT_EQ(a,b) ::ktet::assert_eq_impl((a),(b), #a, #b, __FILE__, __LINE__) \ No newline at end of file diff --git a/tests/test_migration_coverage.cc b/tests/test_migration_coverage.cc index dc0cbf8..1fc9090 100644 --- a/tests/test_migration_coverage.cc +++ b/tests/test_migration_coverage.cc @@ -424,7 +424,7 @@ TEST (Migration_SyntaxHighlighter_Pattern) break; // Should never happen } std::string line = buf.GetLineString(row); - EXPECT_TRUE(line.size() >= 0); // Always true, but validates access + // Successfully accessed line - size() is always valid for std::string } }