#!/bin/bash
ALL_OS="openeuler fedora debian ubuntu alpine archlinux brew conda msys2"
set_epkg_bin() {
if [ -n "$EPKG_BIN" ] && [ -x "$EPKG_BIN" ]; then
EPKG_BIN="$EPKG_BIN"
elif [ -x "$HOME/.epkg/envs/self/usr/bin/epkg" ]; then
EPKG_BIN="$HOME/.epkg/envs/self/usr/bin/epkg"
elif [ -x "$PROJECT_ROOT/target/debug/epkg" ]; then
EPKG_BIN="$PROJECT_ROOT/target/debug/epkg"
elif [ -x "$PROJECT_ROOT/target/release/epkg" ]; then
EPKG_BIN="$PROJECT_ROOT/target/release/epkg"
else
echo "Error: epkg binary not found" >&2
echo "Tried locations:" >&2
echo " - EPKG_BIN environment variable: ${EPKG_BIN:-not set}" >&2
echo " - $HOME/.epkg/envs/self/usr/bin/epkg" >&2
echo " - $PROJECT_ROOT/target/debug/epkg" >&2
echo " - $PROJECT_ROOT/target/release/epkg" >&2
echo "Please build the project first or set EPKG_BIN environment variable" >&2
exit 1
fi
}
set_color_names() {
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
NC=''
fi
}
color_print() {
local color_var="$1"
local prefix="$2"
local message="$3"
local color=""
eval "color=\$$color_var"
printf "%b%s%b %b\n" "$color" "$prefix" "$NC" "$message" >&2
}
log() {
color_print GREEN "[TEST]" "$*"
}
error() {
color_print RED "[ERROR]" "$*"
exit 1
}
skip() {
color_print YELLOW "[SKIP]" "$*"
exit 0
}
parse_debug_flags() {
DEBUG_FLAG=""
local _remaining=""
while [ $# -gt 0 ] && [ "${1#-}" != "$1" ]; do
case "$1" in
-h|--help)
PARSE_DEBUG_FLAGS_REMAINING=""
return 2
;;
-ddd)
DEBUG_FLAG="-ddd"
;;
-dd)
DEBUG_FLAG="-dd"
;;
-d|--debug)
DEBUG_FLAG="-d"
;;
*)
echo "Unknown option: $1" >&2
PARSE_DEBUG_FLAGS_REMAINING=""
return 1
;;
esac
shift
done
PARSE_DEBUG_FLAGS_REMAINING="$*"
return 0
}
has_cmd() {
command -v "$1" >/dev/null 2>&1
}