File: scitest.sci

package info (click to toggle)
scilab 5.2.2-9
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 334,832 kB
  • ctags: 52,586
  • sloc: xml: 526,945; ansic: 223,590; fortran: 163,080; java: 56,934; cpp: 33,840; tcl: 27,936; sh: 20,397; makefile: 9,908; ml: 9,451; perl: 1,323; cs: 614; lisp: 30
file content (173 lines) | stat: -rw-r--r-- 4,822 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2008 - INRIA
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt

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(msprintf(gettext("%s: Wrong first input argument: File with .dia suffix expected."),"scitest"));
			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
		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'');'..
		+'tmpdirToPrint = msprintf(''TMPDIR1=''''%s''''\n'',TMPDIR);'..
		+'diary('''+tmpfiles+'dia'+''');'..
		+'write(%io(2),tmpdirToPrint);'..
		+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(msprintf(gettext("Test failed ERROR DETECTED while executing %s"),tstfile));
			return;
		end
	end
	
	if grep(dia,'error on test')<>[] then
		mydisp(msprintf(gettext("Test failed ERROR DETECTED while executing %s"),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(msprintf(gettext("Test Failed. See : fc /L /N  %s"),diafile+' '+diafile+'.ref '));
		else
		mydisp(msprintf(gettext("Test Failed. See : diff -wu  %s"),diafile+' '+diafile+'.ref '));
		end
		else
		mydisp(gettext("Test passed"));
		end
	end
	mydisp('----------------------------------------------------------');
	
endfunction

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

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