aboutsummaryrefslogtreecommitdiff
path: root/lib/actions/test.bash
blob: 820a6895dad33ed23ffa6f0f506c2e28f27dc171 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env bash

action() {
	local OPTIND
	local raku
	local failures=0

	while getopts ":p:" opt
	do
		case "$opt" in
			p) RSTAR_PREFIX=$OPTARG ;;
			*) emerg "Invalid option specified: $opt" ;;
		esac
	done

	shift $(( OPTIND - 1 ))

	raku="$RSTAR_PREFIX/bin/raku"

	# Ensure raku is available
	if [[ ! -f $raku ]]
	then
		emerg "No Raku executable available at $raku."
		emerg "Make sure you ran the install command."
		emerg "Also, if you installed with -p, you must specify it for test as well"
	fi

	# If no specific targets are specified, set all targets
	if (( $# < 1 ))
	then
		set -- spectest modules
	fi

	# Run each test target
	for target in "$@"
	do
		if [[ $(type -t "action_test_$target") != "function" ]]
		then
			crit "Test target '$target' is invalid"
			continue
		fi

		"action_test_$target" && continue

		failures=$(( failures + 1 ))
	done

	if (( failures > 0 ))
	then
		return 4
	fi
}

action_test_modules() {
	local modules
	local failures

	modules="$(tmpfile)"

	# Manually set a minimal PATH
	PATH="/bin:/usr/bin:/usr/local/bin"

	# Add the Rakudo bin directories from RSTAR_PREFIX
	PATH+=":$(readlink -f "$RSTAR_PREFIX/bin")"
	PATH+=":$(readlink -f "$RSTAR_PREFIX/share/perl6/site/bin")"
	PATH+=":$(readlink -f "$RSTAR_PREFIX/share/perl6/vendor/bin")"
	PATH+=":$(readlink -f "$RSTAR_PREFIX/share/perl6/core/bin")"

	# And export this version to the tests
	export PATH

	debug "PATH set to $PATH"

	awk '/^[^#]/ {print $1}' "$BASEDIR/etc/modules.txt" > "$modules"

	# Go through each module and run the tests
	while read -r module
	do
		chgdir "$BASEDIR/src/rakudo-star-modules/$module"
		prove6 -v . && continue

		failures+=("$module")
	done < "$modules"

	# Return cleanly if no failures occurred
	if [[ -z ${failures[*]} ]]
	then
		return 0
	fi

	# Or inform the user of the failing modules
	emerg "One or more modules failed their tests:"

	for module in "${failures[@]}"
	do
		emerg "  $module"
	done

	return 1
}

action_test_spectest() {
	local destination
	local source

	destination="$(tmpdir)"
	source="$BASEDIR/src/rakudo-$(config_etc_kv "fetch_core.txt" "rakudo_version")"

	notice "Using $destination as working directory"

	# Grab the source files
	cp -R -- "$source/." "$destination"
	chgdir "$destination"

	# Run the spectest
	perl Configure.pl --prefix="$RSTAR_PREFIX"
	make spectest
}