File: scitest.sci

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (149 lines) | stat: -rw-r--r-- 4,421 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
function scitest(tstfile,force,error_check,keep_prompt,postscript_graphics)
// if error_check is %t then execution errors are reported 
// if error_check is %f then only test checked error are detected 
// (see examples in tests directory) 
// if keep_prompt is %t the the prompt is kept in the dia file 
// this can be useful for producing demos 
  [lhs,rhs]=argn(0);
  if exists('force','local')==0 then force = %f ; end 
  if exists('error_check','local')==0 then error_check = %f ; end 
  if exists('keep_prompt','local')==0 then keep_prompt = %f ; end 
  if exists('postscript_graphics','local')==0 then postscript_graphics = %f ; end 

  ind=strindex(tstfile,"."); 
  if ind==[] then 
    diafile = tstfile+'.tst'
  else
     suf = part(tstfile,ind($):length(tstfile));
     if suf == '.dia' then 
       error('scitest: first argument should not be a file with .dia suffix" );
       return 
     end
     diafile=strsubst(tstfile,suf,'.dia')
  end
  if newest(tstfile,diafile)==2 & force == %f  then return,end
  
  mydisp('------------------- File '+tstfile+'--------------------')
  //Reset standard globals
  rand('seed',0);rand('uniform');
  if MSDOS then
    SCI=strsubst(SCI,'/','\')
    tmpfiles=strsubst(TMPDIR,'/','\')+'\tmp.'
  else
     tmpfiles=TMPDIR+'/tmp.'
  end

  // Do some modification in  tst file 
  // ---------------------------------
  txt=mgetl(tstfile)
  txt=strsubst(txt,'pause,end','bugmes();quit;end')
  txt=strsubst(txt,'-->','@#>') 
  //to avoid suppression of input --> with prompts
  txt=strsubst(txt,'halt()','');
 
  if postscript_graphics then 
    pg1='driver(''Pos'');xinit('''+tmpfiles+'gr'+''');',
    pg2='xend();'
  else
    pg1=''
    pg2=''
  end
  head='mode(3);clear;lines(28,72);lines(0);'..
       +'deff(''[]=bugmes()'',''write(%io(2),''''error on test'''')'');'..
       +'predef(''all'');'..
       +'diary('''+tmpfiles+'dia'+''');'..
       +'mprintf(''TMPDIR1=''''%s''''\n'',TMPDIR);'..
       +pg1;
  
  tail="diary(0);"+pg2+"exit;"
  
  txt=[head;
       txt;
       tail];
  // and save it in a temporary file 
  mputl(txt,tmpfiles+'tst')
  
  myexec()

  //  Do some modification in  dia file 
  // ----------------------------------
  dia=mgetl(tmpfiles+'dia')
  dia(grep(dia,'exec('))=[];
  TMP=dia(1);dia(1)=[]
  dia(grep(dia,'diary(0)'))=[];
  
  execstr(TMP)
  
  dia=strsubst(dia,TMPDIR,'TMPDIR');
  dia=strsubst(dia,TMPDIR1,'TMPDIR');
  dia=strsubst(dia,TMPDIR1,'TMPDIR');
  dia=strsubst(dia,SCI,'SCI');

  //suppress the prompts
  if keep_prompt == %f then 
    dia=strsubst(dia,'-->','') 
  end
  dia=strsubst(dia,'@#>','-->')
  dia=strsubst(dia,'-1->','')
  
  //standardise  number display   
  dia=strsubst(strsubst(strsubst(strsubst(dia,' .','0.'),..
				 'E+','D+'),'E-','D-'),'-.','-0.')
  //not to change the ref files
  dia=strsubst(dia,'bugmes();return','bugmes();quit');
  // write down the resulting dia file
  mputl(dia,diafile)
  //Check for execution errors
  // -------------------------
  
  if  error_check == %t then 
    if grep(dia,'!--error')<>[] then 
      mydisp("Test failed ERROR DETECTED  while executing "+tstfile)
      return 
    end
  end   
  
  if grep(dia,'error on test')<>[] then
    mydisp("Test failed ERROR DETECTED  while executing "+tstfile)
    return
  end
  //Check for diff with the .ref file
  // --------------------------------
  [u,ierr]=mopen(diafile+'.ref','r')
  if ierr== 0 then //ref file exists
    ref=mgetl(u);mclose(u)
    // suppress blank (diff -nw)
    dia=strsubst(dia,' ','')
    ref=strsubst(ref,' ','')
    
    if or(ref<>dia) then 
      if MSDOS then
	mydisp('Test Failed SEE : fc /L /N  '+diafile+' '+diafile+'.ref ')
      else
	 mydisp('Test Failed SEE : diff -w  '+diafile+' '+diafile+'.ref ')
      end
    else
       mydisp('Test passed')
    end
  end
  mydisp('----------------------------------------------------------')
endfunction

function mydisp(str)
//write(result,str,'(a)')
  write(%io(2),str,'(a)')
endfunction

function myexec()
  if MSDOS then
      if fileinfo(tmpfiles+'dia')<>[] then  
	unix_s('del '+tmpfiles+'dia')
      end
      unix_s('""'+SCI+'\bin\scilex.exe'+'""'+' -nwni -args -nouserstartup < '+tmpfiles+'tst')
  else
     if fileinfo(tmpfiles+'dia')<>[] then  
       unix_s('rm -f '+tmpfiles+'dia')
     end
     unix_s('( '+SCI+'/bin/scilab -nw -args -nouserstartup <'+tmpfiles+'tst > '+tmpfiles+'res ) 2> '+tmpfiles+'err')
  end
endfunction