2 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # Copyright 2009 Jean-Sebastien Gelinas <calestar@gmail.com>
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
28 recent
=`ls -t ../src/nitc ../src/nitc_[0-9] ../bin/nitc ../c_src/nitc 2>/dev/null | head -1`
29 if [[ "x$recent" == "x" ]]; then
30 echo 'Could not find nitc, aborting'
33 echo 'Using nitc from: '$recent
37 # The default nitc compiler
38 [ -z
"$NITC" ] && find_nitc
48 # Process each files given as arguments
51 echo "File '$ii' does not exist."
55 # Prepare the includes
57 if [ "x$tmp" = "x$ii" ]; then
58 oincludes
="-I . -I ../lib/standard -I ../lib/standard/collection"
63 # Process each alternatives in the current file
64 for alt
in "" `sed -n 's/.*#!*\(alt[0-9]*\)#.*/\1/p' "$ii" | sort -u`; do
65 f
=`basename "$ii" .nit`
71 if [ "x$alt" != "x" ]; then
72 test -d alt || mkdir
-p alt
75 sed "s/#$alt#//g;/#!$alt#/d" "$ii" > "$i"
76 includes
="$includes -I alt"
82 # Clean-up before compile and tests
83 rm -rf .nit_compile
2> /dev
/null
86 # The point of ICode testing is to validate analysis/optimizations
87 # Force '--global' option !
88 $NITC $OPT --global
--output
-format icode
"$i" $includes 2> "$ff.cmp.err" > "$ff.compile.log"
90 if [ "$ERR" != 0 ]; then
92 echo "! [======= fail: Compilation error =======]"
95 TEST_FILE
=$d/$ff.tests
96 if [ ! -f
$TEST_FILE ]; then
97 # Could not find the .tests file associated with this test
98 echo ". [======= fail: Cannot open test file =======]"
105 # Each lines in the .tests file describe a test to execute on the generated
106 # ICode. The file has 4 parameters:
110 # - Arguments for the test
111 # We use the class to open the right icode file.
112 # We use a special method named "no-file" to ensure that the class file does not exist.
113 # If the method is different from "no-file" then we search in said method for the expression given
114 # with the _arguments_ field. This expression will be evaluated as a awk regexp.
115 # We have two types of tests :
116 # - has : the given argument must be found for the test to be successful
117 # - no : the given argument must NOT be found for the test to be successful
119 while IFS
=, read CLASS METHOD TYPE ATTR
121 ICODE_FILE
=$d/.nit_compile
/$CLASS.icode
123 echo -n
'==> Test #'$cptr' ...... '
125 if [ -f
$ICODE_FILE ]; then
126 # Check if the file should exist
127 if [ "x$METHOD" = "xno-file" ]; then
128 # this is not normal, the file should not exist
134 # Use awk to get the method in the file and search in it for the argument
153 if [ $awkstatus -ne
0 ] ; then
155 if [ "x$TYPE" = "xno" ]; then
156 # Should not have beed found
159 elif [ "x$TYPE" = "xhas" ]; then
160 # Should have been found
164 echo "Test file format error !!!"
169 if [ "x$TYPE" = "xno" ]; then
170 # Should not have beed found
173 elif [ "x$TYPE" = "xhas" ]; then
174 # Should have been found
178 echo "Test file format error !!!"
183 # The class file was not found
184 if [ "x$METHOD" = "xno-file" ]; then
189 # Should have been found
199 echo "ok: " `echo $ok | wc -w` "/" `echo $ok $nok $nos | wc -w`
201 if [ -n
"$nok" ]; then
203 echo "There were $(echo $nok | wc -w) errors !"
205 if [ -n
"$nos" ]; then
209 if [ -n
"$nok" ]; then