From: <jh...@us...> - 2009-02-06 17:23:15
|
Revision: 65 http://etch.svn.sourceforge.net/etch/?rev=65&view=rev Author: jheiss Date: 2009-02-06 17:23:12 +0000 (Fri, 06 Feb 2009) Log Message: ----------- Add tests for duplicate and contradictory instructions Modified Paths: -------------- trunk/test/TODO trunk/test/delete.rb trunk/test/file.rb trunk/test/link.rb Modified: trunk/test/TODO =================================================================== --- trunk/test/TODO 2009-02-06 17:22:39 UTC (rev 64) +++ trunk/test/TODO 2009-02-06 17:23:12 UTC (rev 65) @@ -1,8 +1,6 @@ directory Basic operation Owner/group/perms - -config.xml: Etch aborts when given contradictory instructions Command-line options: Modified: trunk/test/delete.rb =================================================================== --- trunk/test/delete.rb 2009-02-06 17:22:39 UTC (rev 64) +++ trunk/test/delete.rb 2009-02-06 17:23:12 UTC (rev 65) @@ -164,6 +164,70 @@ # the assert within run_etch. assert(!File.exist?(@targetfile) && !File.symlink?(@targetfile), testname) + # + # Test duplicate script instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <delete> + <script>source</script> + <script>source</script> + </delete> + </config> + EOF + end + + File.open(@targetfile, 'w') do |file| + file.puts('Original contents') + end + + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.puts("@contents << 'true'") + end + + # Run etch + #puts "Running duplicate script instructions test" + run_etch(@port, @testbase) + + assert(!File.exist?(@targetfile), 'duplicate script instructions') + + # + # Test contradictory script instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <delete> + <script>source</script> + <script>source2</script> + </delete> + </config> + EOF + end + + File.open(@targetfile, 'w') do |file| + file.puts('Original contents') + end + + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.puts("@contents << 'true'") + end + File.open("#{@repodir}/source/#{@targetfile}/source2", 'w') do |file| + file.puts("@contents << 'true'") + end + + # Run etch + #puts "Running contradictory script instructions test" + run_etch(@port, @testbase, true) + + # Verify that the file wasn't removed + assert(File.exist?(@targetfile), 'contradictory script instructions') + end def teardown Modified: trunk/test/file.rb =================================================================== --- trunk/test/file.rb 2009-02-06 17:22:39 UTC (rev 64) +++ trunk/test/file.rb 2009-02-06 17:23:12 UTC (rev 65) @@ -427,6 +427,232 @@ # And verify that the file contents didn't change assert_equal(testcontents, get_file_contents(@targetfile), 'always_manage_metadata contents') + + # + # Test duplicate plain instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <warning_file/> + <source> + <plain>source</plain> + <plain>source</plain> + </source> + </file> + </config> + EOF + end + + origcontents = "This is the original contents\n" + File.chmod(0644, @targetfile) # Need to give ourselves write perms + File.open(@targetfile, 'w') do |file| + file.write(origcontents) + end + sourcecontents = "This is the source contents\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + + # Run etch + #puts "Running duplicate plain instructions test" + run_etch(@port, @testbase) + + # Verify that the file contents were updated + assert_equal(sourcecontents, get_file_contents(@targetfile), 'duplicate plain instructions') + + # + # Test contradictory plain instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <source> + <plain>source</plain> + <plain>source2</plain> + </source> + </file> + </config> + EOF + end + + origcontents = "This is the original contents\n" + File.chmod(0644, @targetfile) # Need to give ourselves write perms + File.open(@targetfile, 'w') do |file| + file.write(origcontents) + end + sourcecontents = "This is the first source contents\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + source2contents = "This is the second source contents\n" + File.open("#{@repodir}/source/#{@targetfile}/source2", 'w') do |file| + file.write(source2contents) + end + + # Run etch + #puts "Running contradictory plain instructions test" + run_etch(@port, @testbase, true) + + # Verify that the file contents didn't change + assert_equal(origcontents, get_file_contents(@targetfile), 'contradictory plain instructions') + + # + # Test duplicate template instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <warning_file/> + <source> + <template>source</template> + <template>source</template> + </source> + </file> + </config> + EOF + end + + origcontents = "This is the original contents\n" + File.chmod(0644, @targetfile) # Need to give ourselves write perms + File.open(@targetfile, 'w') do |file| + file.write(origcontents) + end + sourcecontents = "This is the source contents\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + + # Run etch + #puts "Running duplicate template instructions test" + run_etch(@port, @testbase) + + # Verify that the file contents were updated + assert_equal(sourcecontents, get_file_contents(@targetfile), 'duplicate template instructions') + + # + # Test contradictory template instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <source> + <template>source</template> + <template>source2</template> + </source> + </file> + </config> + EOF + end + + origcontents = "This is the original contents\n" + File.chmod(0644, @targetfile) # Need to give ourselves write perms + File.open(@targetfile, 'w') do |file| + file.write(origcontents) + end + sourcecontents = "This is the first source contents\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + source2contents = "This is the second source contents\n" + File.open("#{@repodir}/source/#{@targetfile}/source2", 'w') do |file| + file.write(source2contents) + end + + # Run etch + #puts "Running contradictory template instructions test" + run_etch(@port, @testbase, true) + + # Verify that the file contents didn't change + assert_equal(origcontents, get_file_contents(@targetfile), 'contradictory template instructions') + + # + # Test duplicate script instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <file> + <warning_file/> + <source> + <script>source</script> + <script>source</script> + </source> + </file> + </config> + EOF + end + + origcontents = "This is the original contents\n" + File.chmod(0644, @targetfile) # Need to give ourselves write perms + File.open(@targetfile, 'w') do |file| + file.write(origcontents) + end + sourcecontents = "This is the source contents\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.puts("@contents << '#{sourcecontents}'") + end + + # Run etch + #puts "Running duplicate script instructions test" + run_etch(@port, @testbase) + + # Verify that the file contents were updated + assert_equal(sourcecontents, get_file_contents(@targetfile), 'duplicate script instructions') + + # + # Test contradictory script instructions + # + + 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>source2</script> + </source> + </file> + </config> + EOF + end + + origcontents = "This is the original contents\n" + File.chmod(0644, @targetfile) # Need to give ourselves write perms + File.open(@targetfile, 'w') do |file| + file.write(origcontents) + end + sourcecontents = "This is the first source contents\n" + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.write(sourcecontents) + end + source2contents = "This is the second source contents\n" + File.open("#{@repodir}/source/#{@targetfile}/source2", 'w') do |file| + file.write(source2contents) + end + + # Run etch + #puts "Running contradictory script instructions test" + run_etch(@port, @testbase, true) + + # Verify that the file contents didn't change + assert_equal(origcontents, get_file_contents(@targetfile), 'contradictory script instructions') + end def teardown Modified: trunk/test/link.rb =================================================================== --- trunk/test/link.rb 2009-02-06 17:22:39 UTC (rev 64) +++ trunk/test/link.rb 2009-02-06 17:23:12 UTC (rev 65) @@ -219,6 +219,116 @@ # Verify that the link permissions got set correctly perms = File.lstat(@targetfile).mode & 07777 assert_equal(0777, perms, 'link perms') + + # + # Test duplicate dest instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <link> + <dest>#{@destfile}</dest> + <dest>#{@destfile}</dest> + </link> + </config> + EOF + end + + File.delete(@targetfile) + + # Run etch + #puts "Running duplicate dest instructions test" + run_etch(@port, @testbase) + + assert_equal(@destfile, File.readlink(@targetfile), 'duplicate dest instructions') + + # + # Test contradictory dest instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <link> + <dest>#{@destfile}</dest> + <dest>#{@destfile2}</dest> + </link> + </config> + EOF + end + + File.delete(@targetfile) if File.symlink?(@targetfile) + + # Run etch + #puts "Running contradictory dest instructions test" + run_etch(@port, @testbase, true) + + # Verify that the link wasn't created + assert(!File.symlink?(@targetfile) && !File.exist?(@targetfile), 'contradictory dest instructions') + + # + # Test duplicate script instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <link> + <script>source</script> + <script>source</script> + </link> + </config> + EOF + end + + File.delete(@targetfile) if File.symlink?(@targetfile) + + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.puts("@contents << '#{@destfile}'") + end + + # Run etch + #puts "Running duplicate script instructions test" + run_etch(@port, @testbase) + + assert_equal(@destfile, File.readlink(@targetfile), 'duplicate script instructions') + + # + # Test contradictory script instructions + # + + FileUtils.mkdir_p("#{@repodir}/source/#{@targetfile}") + File.open("#{@repodir}/source/#{@targetfile}/config.xml", 'w') do |file| + file.puts <<-EOF + <config> + <link> + <script>source</script> + <script>source2</script> + </link> + </config> + EOF + end + + File.delete(@targetfile) if File.symlink?(@targetfile) + + File.open("#{@repodir}/source/#{@targetfile}/source", 'w') do |file| + file.puts("@contents << '#{@destfile}'") + end + File.open("#{@repodir}/source/#{@targetfile}/source2", 'w') do |file| + file.puts("@contents << '#{@destfile2}'") + end + + # Run etch + #puts "Running contradictory script instructions test" + run_etch(@port, @testbase, true) + + # Verify that the link wasn't created + assert(!File.symlink?(@targetfile) && !File.exist?(@targetfile), 'contradictory script instructions') + end def teardown This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |