Skip to content

Commit e3cedb7

Browse files
committed
Improvements to partest-ack, plus partest-paths.
I noticed partest-ack was not finding all matching tests, and fixed that. Also cleaned up the ack options so they're understood by the latest version of ack. Along the way I broke the canonicalization functionality out into its own script so it can easily be used from other places.
1 parent dc8854e commit e3cedb7

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

tools/partest-ack

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
declare quiet failed update partest_debug
66
declare cotouched since sortCommand
77
declare -a ack_args partest_args scalac_args
8+
declare -r standard_ack_args="--noenv -s --java --scala --type-add=scala:ext:flags,check --files-with-matches"
89

910
partest_args=( --show-diff )
10-
base="$(cd "$(dirname "$0")"/.. && pwd)"
11+
bindir="$(cd "$(dirname "$0")" && pwd)"
12+
base="$bindir/.."
1113
cd "$base" || { echo "Could not change to base directory $base" && exit 1; }
1214
filesdir="test/files"
1315
sortCommand="sort -u"
16+
partestPaths="$bindir/partest-paths"
1417

15-
# have to enumerate good test dirs since partest chokes and fails
16-
# on continuations, bench, etc. tests
17-
pathRegex="$filesdir/(pos|neg|jvm|run|scalap|presentation)/[^/.]+([.]scala)?\$"
18+
[[ -x "$partestPaths" ]] || { echo "Cannot find partest-paths in $partestPaths" && exit 1; }
1819

1920
[[ $# -gt 0 ]] || {
2021
cat <<EOM
@@ -32,7 +33,7 @@ runs all the tests for which any associated file matches the regex. Associated
3233
files include .check and .flags files. Tests in directories will match if any
3334
file matches. A file can match the regex by its contents or by its name.
3435
35-
You must have ack installed: http://betterthangrep.com/ack-standalone
36+
You must have ack version 2.12+ installed: http://beyondgrep.com/ack-2.12-single-file
3637
3738
Examples:
3839
@@ -79,24 +80,12 @@ done
7980
shift $((OPTIND-1))
8081
ack_args=( "${ack_args[@]}" "$@" )
8182

82-
# Echo the argument only if it matches our idea of a test and exists.
83-
isPath () { [[ "$1" =~ $pathRegex ]] && [[ -e "$1" ]]; }
84-
85-
# Filter stdin down to actual test paths.
86-
asTestPaths () {
87-
while read p; do
88-
p1="${p%.*}"
89-
isPath "$p1" && echo "$p1"
90-
isPath "$p1.scala" && echo "$p1.scala"
91-
done
92-
}
93-
9483
# These methods all just create paths which may or may not be tests
95-
# all are filtered through "asTestPaths" which limits the output to actual tests
84+
# all are filtered through partest-paths which limits the output to actual tests
9685
regexPathTests () { find "$filesdir" | ack --noenv "$@"; }
9786
failedTests () { for p in $(find "$filesdir" -name '*.log'); do p1=${p%.log} && p2=${p1%-*} && echo "$p2"; done; }
9887
sinceTests() { git log --since="$@" --name-only --pretty="format:" -- "$filesdir"; }
99-
regexCodeTests () { ack --noenv --text --files-with-matches "$@" -- "$filesdir"; }
88+
regexCodeTests () { ack $standard_ack_args "$@" -- "$filesdir"; }
10089
sameCommitTests() { for rev in $(git rev-list HEAD -- "$@"); do git --no-pager show --pretty="format:" --name-only "$rev" -- "$filesdir"; done; }
10190

10291
countStdout () {
@@ -115,7 +104,7 @@ randomSort () {
115104
testRun () {
116105
local description="$1" && shift
117106
printf >&2 "%% tests %-25s ... " "$description"
118-
"$@" | asTestPaths | sort -u | countStdout | egrep -v '^[ ]*$'
107+
"$@" | "$partestPaths" | countStdout | egrep -v '^[ ]*$'
119108
}
120109

121110
allMatches() {

tools/partest-paths

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
#
3+
# Given a list of files on stdin, translates them into a set
4+
# of tests covering those files. That means paths which aren't
5+
# part of a test are dropped and the rest are rewritten to the
6+
# primary test path, with duplicates dropped.
7+
8+
cd "$(dirname "$0")/.."
9+
10+
# We have to enumerate good test dirs since partest chokes and fails
11+
# on continuations, bench, etc. tests
12+
pathRegex="test/files/(pos|neg|jvm|run|scalap|presentation)/[^/.]+([.]scala)?\$"
13+
14+
# Echo the argument only if it matches our idea of a test and exists.
15+
isPath () { [[ "$1" =~ $pathRegex ]] && [[ -e "$1" ]]; }
16+
17+
# Filter stdin down to actual test paths.
18+
asTestPaths() {
19+
while read -r p; do
20+
# Matched file at the standard test depth
21+
p1="${p%.*}" && isPath "$p1.scala" && echo "$p1.scala" && continue
22+
# Or, matched file may be in a test subdirectory, so strip the last path segment and check
23+
p2="${p1%/*}" && isPath "$p2" && echo "$p2" && continue
24+
done
25+
}
26+
27+
asTestPaths | sort -u

0 commit comments

Comments
 (0)