From: <jh...@us...> - 2011-03-11 01:11:21
|
Revision: 264 http://etch.svn.sourceforge.net/etch/?rev=264&view=rev Author: jheiss Date: 2011-03-11 01:11:15 +0000 (Fri, 11 Mar 2011) Log Message: ----------- Add tests for scripts that call return or exit. Fix handling of scripts that call return. Slightly modify the test of a script with a syntax error to use "syntax_error" rather than "syntax error". It makes it more obvious in the error messages that something unnatural is going on. Modified Paths: -------------- trunk/server/lib/etch.rb trunk/test/test_scripts.rb Modified: trunk/server/lib/etch.rb =================================================================== --- trunk/server/lib/etch.rb 2011-03-10 00:41:10 UTC (rev 263) +++ trunk/server/lib/etch.rb 2011-03-11 01:11:15 UTC (rev 264) @@ -1384,7 +1384,7 @@ @dlogger.debug "Processing script #{script} for file #{@file}" @contents = '' begin - eval(IO.read(script)) + run_script_stage2(script) rescue Exception => e if e.kind_of?(SystemExit) # The user might call exit within a script. We want the scripts @@ -1397,5 +1397,13 @@ end @contents end + # The user might call return within a script. We want the scripts to act as + # much like a real script as possible. Wrapping the eval in an extra method + # allows us to handle a return within the script seamlessly. If the user + # calls return it triggers a return from this method. Otherwise this method + # returns naturally. Either works for us. + def run_script_stage2(script) + eval(IO.read(script)) + end end Modified: trunk/test/test_scripts.rb =================================================================== --- trunk/test/test_scripts.rb 2011-03-10 00:41:10 UTC (rev 263) +++ trunk/test/test_scripts.rb 2011-03-11 01:11:15 UTC (rev 264) @@ -52,7 +52,7 @@ end File.open("#{@repodir}/source/#{@targetfile}/source.script", 'w') do |file| - file.write('syntax error') + file.write('syntax_error') end # Gather some stats about the file before we run etch @@ -64,8 +64,73 @@ # Verify that etch didn't do anything to the file assert_equal(before_size, File.stat(@targetfile).size, 'script with syntax error size comparison') assert_equal(before_ctime, File.stat(@targetfile).ctime, 'script with syntax error ctime comparison') - + # + # Script that calls return, make sure nothing blows up + # + testname = 'script calls return' + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <source> + <script>source.script</script> + </source> + </file> + </config> + EOF + end + + File.open("#{@repodir}/source/#{@targetfile}/source.script", 'w') do |file| + file.write('return') + end + + # Gather some stats about the file before we run etch + before_size = File.stat(@targetfile).size + before_ctime = File.stat(@targetfile).ctime + + #run_etch(@server, @testroot, :errors_expected => false, :testname => testname) + run_etch(@server, @testroot, :testname => testname) + + # Verify that etch didn't do anything to the file + assert_equal(before_size, File.stat(@targetfile).size, testname + ' size comparison') + assert_equal(before_ctime, File.stat(@targetfile).ctime, testname + ' ctime comparison') + + # + # Script that calls exit, make sure nothing blows up + # + testname = 'script calls exit' + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <source> + <script>source.script</script> + </source> + </file> + </config> + EOF + end + + File.open("#{@repodir}/source/#{@targetfile}/source.script", 'w') do |file| + file.write('exit') + end + + # Gather some stats about the file before we run etch + before_size = File.stat(@targetfile).size + before_ctime = File.stat(@targetfile).ctime + + run_etch(@server, @testroot, :testname => testname) + + # Verify that etch didn't do anything to the file + assert_equal(before_size, File.stat(@targetfile).size, testname + ' size comparison') + assert_equal(before_ctime, File.stat(@targetfile).ctime, testname + ' ctime comparison') + + # # Run a test where the script doesn't output anything # testname = 'script with no output' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |