summaryrefslogtreecommitdiffstats
path: root/apts
blob: 95eb662b5e72e34a4db4a095fcab676f922bc35e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh

# apts is a testing suite for packages on the Alpine Linux system
# In theory, it will work on any distribution that uses the apk-tools
# package manager
# Author: Jeff Bilyk <jbilyk@gmail.com>
# Version History available at http://git.alpinelinux.org/cgit/apts/

# Get file to output to 
program=$0

usage() {
	echo "Usage: $program outputfile <package>"
	exit 1
}

# parse opts
while getopts "h" opt; do
	case "$opt" in
	h) usage;;
	help) usage;;
	esac
done

OUTFILE=$1

# are there any file arguments
if [ $# -eq 0 ]; then
	echo "no outfile specified"
	usage
fi

#remove opts so that package is $@
shift $(( $OPTIND - 1 ))

# shift once more
shift

# Get directory with test files
. /etc/apts/apts.conf

# CD to test file dir
cd $TESTSDIR

# if there aren't any args besides outfile test all packages
if [ $# -eq 0 ]; then
        i=1
	totaltests=`ls ./tests/ | wc -w`
	echo "All (${totaltests}) packages to be tested"
	passedtests="0"
	for package in `ls ./tests/`; do
                echo "Testing $package apk (${i}/${totaltests})"
		i=$((i + 1))
		/bin/sh -e ./tests/$package $package >> "$OUTFILE" 2>&1
		if [ $? -gt 0 ]; then
			echo "$package failed tests" && exit 1;
		fi
		echo "$package passed tests" >> "$OUTFILE"
		echo "$package passed tests"
		passedtests=$((passedtests + 1))
        done
	echo "$passedtests of $totaltests passed"
	exit 0;
fi

# If script still running, there's args, so test all specified packages
i=1
while [ $# -gt 0 ]; do
	echo "file number $i: $1"
	PACKAGE=$1
	
	# does testing file exist
	test -e ./tests/$PACKAGE

	# If no testing file exists then run generic-apk
	if [ "$?" == "1" ]; then
		echo "Testing file for $PACKAGE does not exist"
		/bin/sh -e ./tests/generic-apk $PACKAGE >> "$OUTFILE" 2>&1

		if [ $? -gt 0 ]; then
			echo "$PACKAGE failed tests" && exit 1;
		fi
		# if script is running, package passed tests
		echo "$PACKAGE passed tests"

	# if testing file exists, then keep running
	else 
		echo "Testing $PACKAGE apk"
		/bin/sh -e ./tests/$PACKAGE $PACKAGE >> "$OUTFILE" 2>&1

		if [ $? -gt 0 ]; then
			echo "$PACKAGE failed tests" && exit 1;
		fi

		echo "$PACKAGE passed tests"
	fi

	i=$((i + 1))
	shift
done