Merge: doc: fixed some typos and other misc. corrections
[nit.git] / tests / search_tests.sh
1 #!/bin/bash
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 stop=false
17 while [ "$stop" = false ]; do
18 case "$1" in
19 -v) verbose=true; shift;;
20 *) stop=true
21 esac
22 done
23
24 if test $# = 0; then
25 echo "Usage: search_test.sh [-v] prog/res/testname..."
26 echo "Search program paths of tests for given nit files, res files, and test names"
27 echo " -v Try to find something and display it when a test is not found."
28 exit
29 fi
30
31 res=0
32
33 # Build the full list once to filter results
34 ./listfull.sh > listfull.out
35 find zzz_tests >> listfull.out
36
37 for f in "$@"; do
38 # Get the basename
39 case "$f" in
40 *.nit)
41 if test -f "$ff"; then
42 echo "$f"
43 continue
44 fi
45 b=`basename -- "$f" .nit`
46 ;;
47 *.res)
48 b=`basename -- "$f" .res`
49 ;;
50 *)
51 b=`basename -- "$f"`
52 ;;
53 esac
54
55 # remove bad chars
56 c="$(printf '%s\n' "$b" | sed '
57 # POSIX BRE metacharacters -> .
58 s/[\\.*^$]\|\[\|]/./g
59
60 # Escape the apostrophe the same way than `listfull.sh`,
61 # then re-escape in POSIX BRE.
62 # x -> x\\xx (where `x` is the apostrophe)
63 s/'\''/'\''\\\\'\'\''/g
64 ')"
65
66 # Remove alts of args test variations
67 c=`echo "$c" | sed 's/\(_[0-9]*alt[0-9][0-9]*\)/\\\\(\1\\\\)\\\\?/g;s/\(_args[0-9][0-9]*\)/\\\\(\1\\\\)\\\\?/'`
68 b=`echo "$b" | sed 's/_[0-9]*alt[0-9][0-9]*//g;s/_args[0-9][0-9]*//'`
69 # Search the orig nit file in the list
70 {
71 grep -- "\(^'\|/\)$c.nit" listfull.out | xargs -E '' -- printf '%s\n'
72 } || {
73 res=1
74 echo >&2 "No test $b.nit found for $f"
75 test "$verbose" == "true" || continue
76 # Search the nit file outside the list...
77 find ../../nit* -name "$b.nit" >&2
78 # Search the nit file in the git history...
79 git log -1 -- "$b.nit" >&2
80 # Search the orig file in the git history...
81 git log -1 -- "$f" >&2
82 }
83 done
84
85 exit $res