File: test_bug_3104326.pro

package info (click to toggle)
gnudatalanguage 1.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,832 kB
  • sloc: cpp: 198,435; ansic: 47,740; sh: 691; python: 474; makefile: 149; xml: 69; f90: 28
file content (228 lines) | stat: -rw-r--r-- 7,232 bytes parent folder | download | duplicates (3)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
;
; this bug is now referenced as
; http://sourceforge.net/p/gnudatalanguage/bugs/335/
;
; Sylwester, 28/11/2010: the line number of a missing/unknown
; procedure was not well found/computed.
;
; Alain, 18/09/2013: trying to clarify this test, automatic
; calculation of the expected line number where the code will stop,
; beeing independant of the path as long as the file is in the GDL_PATH
;
; In GDL, as is in September 2013, the full path to the procedure
; is not return when we are in the same directory (TBC)
;
function GETTING_LINE_NUMBER, info
;
info=ROUTINE_INFO('TEST_BUG_3104326',/source)
;
SPAWN, 'grep -n NONEXISTENT '+info.path, out, status
;
idx=STRPOS(out[1], ':')
if (idx GT 0) then begin
    line_number=LONG(STRMID(out[1],0,idx))
endif else begin
    line_number=-1
endelse
return, line_number
;
end
;
pro TEST_BUG_3104326, path2exe=path2exe, idl=idl, gdl=gdl, $
                      verbose=verbose, test=test, no_exit=no_exit, help=help
;
if KEYWORD_SET(help) then begin
    print, 'pro TEST_BUG_3104326, path2exe=path2exe, idl=idl, $'
    print, '                      verbose=verbose, test=test, no_exit=no_exit, help=help'
    return
endif
if !version.os_family eq 'Windows' then begin
   spawn,'ps',stdps
   if n_elements(stdps) lt 4 then begin
      message,/continue," Windows' invocation without a shell: fake result: immediate return"
      return
   endif
   message,/continue," Windows' invocation: via shell? going for it"
endif
;
; since the routine was compiled, we can know where it is !
;
info=ROUTINE_INFO('TEST_BUG_3104326',/source)
;
; the line number where the compiler fails. Should be change if
; lines added to this code !!
line_number=GETTING_LINE_NUMBER(info)
if (line_number LE 0) then begin
    MESSAGE, /continue, 'problem during Line Number estimation'
    if ~KEYWORD_SET(no_exit) then EXIT, status=1 else STOP
endif
;
cmd_suffixe=' -quiet 2>/dev/stdout'
;
; logic: provide path to an exe is first priority
; if not provide, if /IDL selected, verify it else verifying relative GDL
;
if KEYWORD_SET(path2exe) then begin
   gdl_exe=path2exe
   if FILE_TEST(gdl_exe,/dir) then begin
      print, 'You provided a PATH, not an EXE'
      print, 'please provide a full path with exe for GDL/IDL using keyword PATH2EXE='
      return
   endif
    if ~FILE_TEST(gdl_exe) then begin
        print, 'No real file found in the path2exe'
        print, 'please provide a full path with exe for GDL/IDL using keyword PATH2EXE='
        return
    endif
endif else begin
    ;; inside call can be switch to IDL
    if KEYWORD_SET(idl) then begin
        print, 'using IDL for internal call'
        gdl_exe='idl'
        spawn, 'which '+gdl_exe, out
        if ((STRLEN(out) EQ 0) OR ~FILE_TEST(out)) then begin
            print, 'No IDL found in the path'
            print, 'please provide a custom path to IDL (or GDL) using keyword PATH2EXE='
            return
        endif
    endif else begin
        ;; default internal call is GDL
        print, 'using GDL for internal call'
        ;; default (what is happening when we run "make check"): 
        ;; assuming we are in the testsuite/ dir and GDL exe is in ../src/
        gdl_exe='../src/gdl'
        if ~FILE_TEST(gdl_exe) then begin
            print, 'No GDL at expected place, trying in the PATH'
            gdl_exe='gdl'
            spawn, 'which '+gdl_exe, out
            if ((STRLEN(out) EQ 0) OR ~FILE_TEST(out)) then begin
                print, 'No GDL found in the path'
                print, 'please provide a path to GDL using keyword PATH2EXE='
                return
            endif
        endif
    endelse
endelse
;
; we have verified that we know where is the routine" (full path)
; and if we have a real executable (idl or gdl)
;                         ;
command='echo "' $
  + '.compile '+ info.path + STRING(10b) $
  + 'test_bug_3104326_helper' + STRING(10b) + '" | ' + gdl_exe+cmd_suffixe
;
SPAWN, command, out
;
; when lines are too long in IDL, they are cut
old=out
out=old[0]
tmp=''
for ii=1, N_elements(old)-1 do begin &$
    if (STRMID(old[ii],0,1) EQ '%') then begin &$
        out=[out, tmp] &$
        tmp=old[ii] &$
    endif else begin &$
        tmp=tmp+old[ii] &$
    endelse &$
endfor
if (STRLEN(tmp) GT 0) then out=[out, tmp]
out=STRCOMPRESS(out) ; we keep some spaces !
;
if KEYWORD_SET(verbose) then begin
    print, 'line number : ', line_number
    print, 'command :', command
    print, 'raw result  :'
    if N_ELEMENTS(old) GT 1 then print, '>>'+TRANSPOSE(old)+'<<' else print, old
    print, 'result  :'
    if N_ELEMENTS(out) GT 1 then print, '>>'+TRANSPOSE(out)+'<<' else print, out
endif
;
nb_errors=0
;
; We can do now three tests:
; -1- testing that the line number in the line with "% Executation halted"
;    is the good one
;
; -2- testing if the expected path is returned
;
; -3- testing also it is the last last line (antepenultimate line)
;
; "good_line" to be used by tests 1 and 2
good_line_nb=WHERE(STRPOS(out, '% Execution') EQ 0, exist)
; Compared to initial version, we change the test because, in fact,
; the filename should be prefixed by the directory, not ready in GDL
filtre1='TEST_BUG_3104326_HELPER_SUB '+STRCOMPRESS(STRING(line_number),/remove_all)
;
; test -1-
;
if exist EQ 0 then begin
    MESSAGE, /continue, 'Error here before test 1: expression <<% Execution halted>> not found'
    nb_errors++
endif else begin
    if STRPOS(out[good_line_nb], filtre1) eq -1 then begin
        nb_errors++
        MESSAGE, /continue, 'Error during test 1: no line number returned.'
    endif
 endelse

if (nb_errors gt 0) then begin
 nb_errors-- ; we KNOW GDL is in error on this one!
 filtre1='TEST_BUG_3104326_HELPER_SUB' ; otherwise the following tests will always be false.
end
;
; test -2-  NOT READY in GDL
;
; what is the effective path of the routine ?
path=info.PATH
index=STRPOS(path, PATH_SEP(), /reverse_search)
;
if (index GT 0) then begin
    path=STRMID(path, 0, index)
    if (nb_errors eq 0) then filtre2=STRCOMPRESS(STRING(line_number),/remove_all)+' '+path else filtre2=path ; since not having the number would force the test to be false.
    ;;
    if STRPOS(out[good_line_nb], filtre2) eq -1 then begin
        MESSAGE, /continue, 'Error during test 2: full path not well returned'
        nb_errors++
        ;; BEGIN of block to be removed when GDL ready
        DEFSYSV, '!gdl', exist=exist
        if exist then begin
            MESSAGE, /continue, 'To be done in GDL : prefixing function by full path'
            nb_errors--
        endif
        ;;END of block to be removed when GDL ready
    endif
endif
;
; test -3-
;
if STRPOS(out[N_ELEMENTS(out) - 3], filtre1) eq -1 then begin
    MESSAGE, /continue, 'Error during test 3: must be antepenultimate line'
    nb_errors++
endif
;
if (nb_errors GT 0) then begin
    if ~KEYWORD_SET(no_exit) then EXIT, status=1
endif else begin
    MESSAGE, /continue, 'the three tests were passed with success'
endelse
;
if KEYWORD_SET(test) then STOP
;
end
;
; ----------------------------------
;
pro TEST_BUG_3104326_HELPER
;
TEST_BUG_3104326_HELPER_SUB
;
end
;
; ----------------------------------
;
pro TEST_BUG_3104326_HELPER_SUB
;
; this name should remain in majuscules
NONEXISTENT
;
end