11#! /usr/bin/env sh
22set -eu
33
4+ # Detect container runtime (prefer podman, fallback to docker)
5+ if command -v podman > /dev/null 2>&1 ; then
6+ CONTAINER_RUNTIME=" podman"
7+ elif command -v docker > /dev/null 2>&1 ; then
8+ CONTAINER_RUNTIME=" docker"
9+ else
10+ printf " Error: Neither podman nor docker is installed\n" >&2
11+ exit 1
12+ fi
13+
414# Global variables
515IMAGE_NAME=" dotfiles-test"
616REPORT_FILE=" ${REPORT_FILE:- test_report.txt} "
@@ -9,13 +19,13 @@ REPO_DIR="$(git rev-parse --show-toplevel)"
919
1020# Build the test image
1121build_image () {
12- printf " Building test image...\n"
13- podman build -t " $IMAGE_NAME " -f " $REPO_DIR /Containerfile" " $REPO_DIR "
22+ printf " Building test image with %s ...\n" " $CONTAINER_RUNTIME "
23+ " $CONTAINER_RUNTIME " build -t " $IMAGE_NAME " -f " $REPO_DIR /Containerfile" " $REPO_DIR "
1424}
1525
1626# Start a new test container
1727start_container () {
18- CURRENT_CONTAINER=$( podman run -d \
28+ CURRENT_CONTAINER=$( " $CONTAINER_RUNTIME " run -d \
1929 -v " $REPO_DIR :/dotfiles:ro" \
2030 " $IMAGE_NAME " \
2131 sleep infinity)
@@ -26,7 +36,7 @@ start_container() {
2636cleanup_container () {
2737 if [ -n " $CURRENT_CONTAINER " ]; then
2838 printf " Cleaning up container: %s\n" " $CURRENT_CONTAINER "
29- podman rm -f " $CURRENT_CONTAINER " > /dev/null 2>&1 || true
39+ " $CONTAINER_RUNTIME " rm -f " $CURRENT_CONTAINER " > /dev/null 2>&1 || true
3040 CURRENT_CONTAINER=" "
3141 fi
3242}
@@ -42,7 +52,7 @@ assert() {
4252 printf " Command: %s\n" " $command " | tee -a " $REPORT_FILE "
4353
4454 # Run the command in the container and capture output and exit code
45- if output=$( podman exec " $CURRENT_CONTAINER " sh -c " $command " 2>&1 ) ; then
55+ if output=$( " $CONTAINER_RUNTIME " exec " $CURRENT_CONTAINER " sh -c " $command " 2>&1 ) ; then
4656 exit_code=0
4757 else
4858 exit_code=$?
0 commit comments