File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,31 @@ function try_output() {
6262    try " $expected "   " $expected_output "   " $input " 
6363}
6464
65+ #  try_compile_error - test shecc with invalid C program
66+ #  Usage:
67+ #  - try_compile_error invalid_input_code
68+ #  compile "invalid_input_code" with shecc so that shecc generates a
69+ #  compilation error message.
70+ # 
71+ #  This function uses shecc to compile invalid code and obtains the exit
72+ #  code returned by shecc. The exit code must be a non-zero value to
73+ #  indicate that shecc has the ability to parse the invalid code and
74+ #  output an error message.
75+ function  try_compile_error()  {
76+     local  input=$( cat) 
77+ 
78+     local  tmp_in=" $( mktemp --suffix .c) " 
79+     local  tmp_exe=" $( mktemp) " 
80+     echo  " $input "   >  " $tmp_in " 
81+     " $SHECC "   -o " $tmp_exe "   " $tmp_in " 
82+     local  exit_code=$? 
83+ 
84+     if  [ 0 ==  $exit_code  ];  then 
85+         echo  " Error: compilation is passed." 
86+         exit  1
87+     fi 
88+ }
89+ 
6590function  items()  {
6691    local  expected=" $1 " 
6792    local  input=" $2 " 
@@ -238,6 +263,14 @@ int main() {
238263} 
239264EOF 
240265
266+ try_compile_error <<  EOF 
267+ int main() { 
268+     int a = 03, b = 01118, c = 091; 
269+     printf("%d %d %d\n", a, b, c); 
270+     return 0; 
271+ } 
272+ EOF 
273+ 
241274try_ 1 <<  EOF 
242275int is_odd(int x); 
243276
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments