#!/bin/bash
# dev/package/check - package checking

set -e

lib_load 'dev/package/versions'
lib_load 'dev/tool/make'


######
# Package Checking

package_check_app() {
	local name=$1
	run env PATH="install/bin:$PATH" $name check \
		&& app_echo "$name check: success" \
		|| error "$name check: failed"
}


package_check_build() {
	has_args 2 "$@"
	local testdir=$1
	local apps=$2

	local verbose=true

	run rm -rf "$testdir"
	if [ -d .git ]; then
		run git clone . "$testdir"
	elif [ "$(pwd)" != "$(realpath "$testdir")" ]; then
		run_mkdir "$testdir"
		run cp -a * "$testdir"
	elif [ ! -d "$testdir" ]; then
		error "$testdir: directory does not exists"
	fi

	run cd "$testdir"
	run ./bootstrap.sh
	make_run info

	for_each package_check_app $apps

	make_run clean

	run git status --ignored
}
package_check_install() {
	has_args 1 "$@"
	local testdir=$1
	run cd "$testdir"
	make_run install
	make_run uninstall
}

package_check_dist() {
	has_args 3 "$@"
	local testdir=$1
	local archives=$2
	local apps=$3

	local -a alist
	alist=( $archives )
	local archive="${alist[0]}"

	local verbose=true

	run cd "$testdir"
	info "creating distribution archives"
	make_run dist

	local version=$(package_version_read_full)
	local distdir="${PKG}-$version"
	if [ -d "$distdir" ]; then
		info "removing earlier test directory"
		run rm -rf "$distdir"
	fi
	info "extracting distribution archives"
	tar_verbose=true tar_extract "$archive"
	info "running standard tests"
	run package_check_build "$distdir" "$apps"
	info "running installation tests"
	run package_check_install "$distdir"
	info "removing output files"
	make_run clean
}

View the Developer Guide Index

View the Reference Manual Index


Generated on Wed Jun 28 07:39:51 PDT 2017 by mcsh d14 v0.20.0.