Rename REAMDE to README.md
[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 # remove bad chars
55 c=`echo "$b" | sed 's/\([\\.*^$]\|\[\|]\)/./g'`
56 # Remove alts of args test variations
57 c=`echo "$c" | sed 's/\(_[0-9]*alt[0-9][0-9]*\)/\\\\(\1\\\\)\\\\?/g;s/\(_args[0-9][0-9]*\)/\\\\(\1\\\\)\\\\?/'`
58 b=`echo "$b" | sed 's/_[0-9]*alt[0-9][0-9]*//g;s/_args[0-9][0-9]*//'`
59 # Search the orig nit file in the list
60 cat listfull.out | grep -- "\(^\|/\)$c.nit" || {
61 res=1
62 echo >&2 "No test $b.nit found for $f"
63 test "$verbose" == "true" || continue
64 # Search the nit file outside the list...
65 find ../../nit* -name "$b.nit" >&2
66 # Search the nit file in the git history...
67 git log -1 -- "$b.nit" >&2
68 # Search the orig file in the git history...
69 git log -1 -- "$f" >&2
70 }
71 done
72
73 exit $res