$title 'Test execmode behavior' (EXECMODE01,SEQ=673) $onText This tests the correct behavior under the different settings for EXECMODE. execmode (execmode=0) limits on call, execute, put and echo commands Values (cumulative): 0 everything allowed 1 interactive shells in $call and execute commands are prohibited 2 all $call and execute commands are prohibited 3 $echo or put commands can only write below the working or scratch directory 4 $echo and put commands are not allowed Contributor: Lutz Westermann, December 2014 $offText $onEcho > okWithEM0a.gms $call $offEcho $onEcho > okWithEM0b.gms execute ''; $offEcho $onEcho > okWithEM1a.gms $call touch dummy.gms $offEcho $onEcho > okWithEM1b.gms execute 'touch dummy.gms'; $offEcho $onEcho > okWithEM1c.gms file fx put_utility fx 'exec' / 'touch dummy.gms'; $offEcho $onEcho > okWithEM1d.gms file fx put_utility fx 'shell' / 'touch dummy.gms'; $offEcho *Assuming that this is executed in any subfolder $onEcho > okWithEM2a.gms $echo test > ..%system.dirsep%dummy.txt $offEcho $onEcho > okWithEM2b.gms file fy /'..%system.dirsep%dummy.txt'/ putclose fy 'test'; $offEcho $onEcho > okWithEM3a.gms $echo test > dummy.txt $offEcho $onEcho > okWithEM3b.gms file fz /'dummy.txt'/; putclose fz 'test'; $offEcho set em execMode / 0*4 / * do not use 0 since it allows interactive shells which is problematic in scripted tests emR(em) execModes to run / 1*4 / tc test cases / a*d / emtcMap(em,tc) / 0.(a,b) 1.(a*d) 2.(a,b) 3.(a,b) /; singleton set activeOuter(em) activeInner(em) activeTestCase(tc); Alias (em,aem); file fx; loop(emtcMap(em,tc), activeOuter(em) = yes; activeTestCase(tc) = yes; loop(emR(aem), activeInner(aem) = yes; put_utility fx 'exec' / 'gams okWithEM' em.tl:0 tc.tl:0 '.gms lo=%GAMS.lo% execmode=' aem.tl:0 ; if(ord(aem) <= ord(em), if(sameas(em,'2'), execute '=test -e ..%system.dirsep%dummy.txt'); if(sameas(em,'3'), execute '=test -e dummy.txt'); abort$( errorlevel) 'this should not have failed', activeOuter, activeTestCase, activeInner; if(sameas(em,'2'), execute 'rm -rf ..%system.dirsep%dummy.txt'); if(sameas(em,'3'), execute 'rm -rf dummy.txt'); else if(sameas(em,'2'), execute '=test -e ..%system.dirsep%dummy.txt'); if(sameas(em,'3'), execute '=test -e dummy.txt'); abort$(not errorlevel) 'this should have failed', activeOuter, activeTestCase, activeInner; ) ) )