#!/bin/sh
_get_python_cmd() {
if echo "$EPKG_BIN" | grep -q '\.exe$'; then
echo "python"
elif [ "$OS" = "Windows_NT" ]; then
echo "python"
else
echo "python3"
fi
}
test_install_run() {
local pkg="$1"
shift
run_install "$pkg" || return 1
run "$@" || return 1
return 0
}
test_lang_python() {
local py_cmd="$(_get_python_cmd)"
if [ "$CHANNEL_NAME" = "brew" ]; then
run_install python || return 1
run $py_cmd --version || return 1
run $py_cmd -c "print('Hello from Python')" || return 1
else
run_install python || return 1
run $py_cmd --version || return 1
run $py_cmd -c "print('Hello from Python')" || return 1
fi
return 0
}
test_lang_perl() {
run_install perl || return 1
run perl -e 'print "Hello from Perl\n"' || return 1
run perl -v | head -2 || return 1
return 0
}
test_lang_ruby() {
run_install ruby || return 1
run ruby --version || return 1
run ruby -e 'puts "Hello from Ruby"' || return 1
return 0
}
test_lang_nodejs() {
run_install nodejs || return 1
run node --version || return 1
run node -e "console.log('Hello from Node.js')" || return 1
return 0
}
test_lang_go() {
run_install go || return 1
run go version || return 1
return 0
}
test_build_cmake() {
run_install cmake || return 1
run cmake --version || return 1
return 0
}
test_build_make() {
run_install make || return 1
if [ "$CHANNEL_NAME" = "brew" ]; then
run gmake --version || return 1
else
run make --version || return 1
fi
return 0
}
test_build_ninja() {
run_install ninja || return 1
run ninja --version || return 1
return 0
}
test_scipy_numpy() {
local py_cmd="$(_get_python_cmd)"
run_install python || run_install python3 || return 1
run_install numpy || return 1
run $py_cmd -c "import numpy; print('numpy version:', numpy.__version__)" || return 1
return 0
}
test_scipy_scipy() {
local py_cmd="$(_get_python_cmd)"
run_install python || run_install python3 || return 1
run_install scipy || return 1
run $py_cmd -c "import scipy; print('scipy version:', scipy.__version__)" || return 1
return 0
}
test_scipy_pandas() {
local py_cmd="$(_get_python_cmd)"
run_install python || run_install python3 || return 1
run_install pandas || return 1
run $py_cmd -c "import pandas; print('pandas version:', pandas.__version__)" || return 1
return 0
}
test_ml_scikit() {
run_install scikit-learn || return 1
local py_cmd="$(_get_python_cmd)"
run $py_cmd -c "import sklearn; print('sklearn version:', sklearn.__version__)" || return 1
return 0
}
test_util_jq() {
run_install jq || return 1
run jq --version || return 1
echo '{"test":1}' | run jq . || return 1
return 0
}
test_util_curl() {
run_install curl || return 1
run curl --version || return 1
return 0
}
test_util_wget() {
run_install wget || return 1
run wget --version || return 1
return 0
}
test_util_sed() {
run_install sed || return 1
run sed --version || return 1
return 0
}
test_suite_utils() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "jq"; then
test_util_jq || channel_skip "no jq for channel=$CHANNEL_NAME"
fi
if ! echo "$skip_list" | grep -qw "tree"; then
if run_install tree 2>/dev/null; then
run tree --version || channel_skip "tree not found"
else
channel_skip "no tree for channel=$CHANNEL_NAME"
fi
fi
}
test_suite_langs() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "python"; then
test_lang_python
fi
if ! echo "$skip_list" | grep -qw "perl"; then
test_lang_perl
fi
if ! echo "$skip_list" | grep -qw "ruby"; then
if [ "$CHANNEL_NAME" != "brew" ]; then
test_lang_ruby
fi
fi
if ! echo "$skip_list" | grep -qw "nodejs"; then
if [ "$CHANNEL_NAME" = "brew" ]; then
run_install node
elif [ "$CHANNEL_NAME" = "msys2" ]; then
run_install mingw-w64-x86_64-nodejs
else
run_install nodejs
fi
run node -e "console.log('Hello from Node.js')"
fi
if ! echo "$skip_list" | grep -qw "go"; then
test_lang_go
fi
}
test_suite_build() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "cmake"; then
test_build_cmake
fi
if ! echo "$skip_list" | grep -qw "make"; then
test_build_make
fi
if ! echo "$skip_list" | grep -qw "ninja"; then
test_build_ninja
fi
}
test_suite_scipy() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "numpy"; then
test_scipy_numpy
fi
if ! echo "$skip_list" | grep -qw "scipy"; then
test_scipy_scipy
fi
if ! echo "$skip_list" | grep -qw "pandas"; then
test_scipy_pandas
fi
}
test_suite_ml() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "scikit"; then
test_ml_scikit
fi
}
test_suite_pkgmgr() {
local pkg_to_remove="${1:-tree}"
run_remove "$pkg_to_remove"
epkg list | head -30
epkg search jq | head -20
epkg info jq | head -20
}
test_suite_install_list_consistency() {
local skip_list="$1"
local test_pkg1="${2:-jq}"
local test_pkg2="${3:-tree}"
if ! echo "$skip_list" | grep -qw "install_list_1"; then
echo "--- Installing $test_pkg1 and verifying visibility ---"
run_install "$test_pkg1" || return 1
local list_output
list_output=$(epkg list --installed 2>&1)
if echo "$list_output" | grep -q "No packages found"; then
echo "FAIL: epkg list shows no packages after installing $test_pkg1" >&2
return 1
fi
if ! echo "$list_output" | grep -q "$test_pkg1"; then
echo "FAIL: $test_pkg1 not visible in epkg list after install" >&2
return 1
fi
echo "PASS: $test_pkg1 visible in list after install"
fi
if ! echo "$skip_list" | grep -qw "install_list_2"; then
echo "--- Installing $test_pkg2 and verifying both packages visible ---"
run_install "$test_pkg2" || return 1
local list_output
list_output=$(epkg list --installed 2>&1)
if echo "$list_output" | grep -q "No packages found"; then
echo "FAIL: epkg list shows no packages after installing $test_pkg2" >&2
return 1
fi
if ! echo "$list_output" | grep -q "$test_pkg1"; then
echo "FAIL: $test_pkg1 no longer visible after installing $test_pkg2" >&2
return 1
fi
if ! echo "$list_output" | grep -q "$test_pkg2"; then
echo "FAIL: $test_pkg2 not visible in epkg list after install" >&2
return 1
fi
echo "PASS: both $test_pkg1 and $test_pkg2 visible in list"
fi
return 0
}
test_msys2_mingw_cpp_dev() {
local skip_list="$1"
echo "--- MSYS2: MinGW C/C++ development scenario ---"
if ! echo "$skip_list" | grep -qw "mingw_gcc"; then
if [ "$CHANNEL_NAME" = "msys2" ]; then
run_install mingw-w64-ucrt-x86_64-gcc || return 1
run gcc --version || return 1
fi
fi
if ! echo "$skip_list" | grep -qw "mingw_cmake"; then
if [ "$CHANNEL_NAME" = "msys2" ]; then
run_install mingw-w64-ucrt-x86_64-cmake || return 1
run cmake --version || return 1
fi
fi
echo "PASS: MSYS2 MinGW development tools work"
return 0
}
test_conda_data_science() {
local skip_list="$1"
local py_cmd="$(_get_python_cmd)"
echo "--- Conda: Data Science scenario ---"
if ! echo "$skip_list" | grep -qw "ds_python"; then
run $py_cmd --version 2>/dev/null || run_install python || return 1
run $py_cmd --version || return 1
fi
if ! echo "$skip_list" | grep -qw "ds_numpy"; then
run_install numpy || return 1
run $py_cmd -c "import numpy; print('numpy:', numpy.__version__)" || return 1
fi
echo "PASS: Conda data science tools work"
return 0
}
test_brew_dev_tools() {
local skip_list="$1"
echo "--- Homebrew: Developer tools scenario ---"
if ! echo "$skip_list" | grep -qw "dev_git"; then
run_install git || return 1
run git --version || return 1
fi
if ! echo "$skip_list" | grep -qw "dev_jq"; then
run_install jq || return 1
run jq --version || return 1
fi
echo "PASS: Homebrew developer tools work"
return 0
}
test_suite_queries() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "info"; then
epkg info python | head -20 || return 1
fi
if ! echo "$skip_list" | grep -qw "search"; then
epkg search python | head -10 || return 1
fi
if ! echo "$skip_list" | grep -qw "list"; then
epkg list | head -10 || return 1
fi
return 0
}
test_suite_history() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "history"; then
epkg history
fi
if ! echo "$skip_list" | grep -qw "restore"; then
run_install jq || return 1
epkg restore -1 --assume-yes
fi
return 0
}
test_suite_env_io() {
local skip_list="$1"
local export_file="/tmp/epkg-env-export-$CHANNEL_NAME.yaml"
if ! echo "$skip_list" | grep -qw "export"; then
epkg env export > "$export_file" || return 1
if [ ! -s "$export_file" ]; then
echo "Export file is empty" >&2
return 1
fi
echo "Exported environment to $export_file"
head -20 "$export_file"
fi
return 0
}
test_suite_gc() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "gc"; then
epkg gc --assume-yes || return 1
fi
return 0
}
test_suite_upgrade() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "upgrade"; then
epkg list --upgradable | head -10
epkg upgrade --assume-yes
fi
return 0
}
test_suite_list_variants() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "list_installed"; then
epkg list --installed | head -10 || return 1
fi
if ! echo "$skip_list" | grep -qw "list_upgradable"; then
epkg list --upgradable | head -10 || return 1
fi
if ! echo "$skip_list" | grep -qw "list_pattern"; then
epkg list "python*" | head -10 || return 1
fi
return 0
}
test_suite_env() {
local skip_list="$1"
local test_env="${ENV_NAME}-test"
if ! echo "$skip_list" | grep -qw "env_create"; then
"$EPKG_BIN" env create "$test_env" -c "$CHANNEL_NAME"
fi
if ! echo "$skip_list" | grep -qw "env_list"; then
"$EPKG_BIN" env list | head -10
fi
if ! echo "$skip_list" | grep -qw "env_remove"; then
"$EPKG_BIN" env remove "$test_env"
fi
if ! echo "$skip_list" | grep -qw "env_path"; then
epkg env path || return 1
fi
if ! echo "$skip_list" | grep -qw "env_config"; then
epkg env config get name
fi
return 0
}
test_suite_repo() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "repo_list"; then
epkg repo list || return 1
fi
return 0
}
test_suite_run() {
local skip_list="$1"
local py_cmd="$(_get_python_cmd)"
if ! echo "$skip_list" | grep -qw "run_python"; then
run_install python || return 1
run $py_cmd --version || return 1
fi
if ! echo "$skip_list" | grep -qw "run_python_c"; then
run $py_cmd -c "import os; print('Run test OK')" || return 1
fi
return 0
}
test_suite_search() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "search_pattern"; then
epkg search "python" | head -10 || return 1
fi
if ! echo "$skip_list" | grep -qw "search_file"; then
epkg search "*/bin/python" | head -10
fi
return 0
}
test_suite_info() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "info_installed"; then
epkg info python | head -20
fi
if ! echo "$skip_list" | grep -qw "info_available"; then
epkg info jq | head -20 || return 1
fi
return 0
}
test_suite_dry_run() {
local skip_list="$1"
if ! echo "$skip_list" | grep -qw "dry_install"; then
echo "Testing: epkg --dry-run install curl"
epkg --dry-run install curl
fi
if ! echo "$skip_list" | grep -qw "dry_remove"; then
echo "Testing: epkg --dry-run remove curl"
epkg --dry-run remove curl
fi
return 0
}