aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/cpt-build1
-rw-r--r--src/cpt-lib20
2 files changed, 19 insertions, 2 deletions
diff --git a/src/cpt-build b/src/cpt-build
index edf59bb..d922084 100755
--- a/src/cpt-build
+++ b/src/cpt-build
@@ -7,6 +7,7 @@ parser_definition() {
setup REST -- "usage: ${0##*/} [pkg...]"
msg -- '' 'Options:'
flag CPT_PROMPT -y --no-prompt on:0 init:"$CPT_PROMPT" -- "Do not prompt for confirmation"
+ flag CPT_TEST -t --test init:"$CPT_TEST" -- "Run tests (if it exists)"
disp :usage -h --help -- "Show this help message"
disp :version -v --version -- "Print version information"
}
diff --git a/src/cpt-lib b/src/cpt-lib
index 0460fcb..6957841 100644
--- a/src/cpt-lib
+++ b/src/cpt-lib
@@ -677,8 +677,11 @@ pkg_depends() {
[ "$pkg_build" ] && [ -z "$2" ] &&
(pkg_list "$1" >/dev/null) && return
- # Recurse through the dependencies of the child packages.
- while read -r dep _ || [ "$dep" ]; do
+ while read -r dep type || [ "$dep" ]; do
+ # Skip test dependencies unless $CPT_TEST is set to 1.
+ case $type in test) [ "$CPT_TEST" = 1 ] || continue; esac
+
+ # Recurse through the dependencies of the child packages.
[ "${dep##\#*}" ] && pkg_depends "$dep"
done 2>/dev/null < "$(pkg_find "$1")/depends" ||:
@@ -964,6 +967,19 @@ pkg_build() {
kill 0
} } | tee "$log_dir/$pkg-$time-$pid"
+ # Run the test script if it exists and the user wants to run tests. This
+ # is turned off by default.
+ [ -x "$repo_dir/test" ] && [ "$CPT_TEST" = 1 ] && {
+ run_hook pre-test "$pkg" "$pkg_dir/$pkg"
+ log "$pkg" "Running tests"
+ "$repo_dir/test" "$pkg_dir/$pkg" "$build_version" "$sys_arch" 2>&1 || {
+ log "$pkg" "Test failed"
+ log "$pkg" "Log stored to $log_dir/$pkg-$time-$pid"
+ run_hook test-fail "$pkg" "$pkg_dir/$pkg"
+ pkg_clean
+ kill 0
+ } } | tee -a "$log_dir/$pkg-$time-$pid"
+
# Delete the log file if the build succeeded to prevent
# the directory from filling very quickly with useless logs.
[ "$CPT_KEEPLOG" = 1 ] || rm -f "$log_dir/$pkg-$time-$pid"