#!/usr/bin/ruby $:.unshift( "." ) $:.unshift( "./lib" ) require "P4" require 'test/unit' require 'test/unit/ui/console/testrunner' # # Array to hold a list of Test::Unit::TestCase subclasses in the order in # which they are subclassed. See below for the black magic. # $p4ruby_test_list = Array.new # # Reopen the Test::Unit::TestCase class, and define TestCase.inherited, so # we can see whenever a subclass is created. As they're created, we append # them to a list of subclasses, and this will dictate the order of the # tests when they're run. # module Test module Unit class TestCase def TestCase.inherited( sub ) $p4ruby_test_list.push( sub ) end end end end # # Define some common methods and attributes that can be included # by our Test::Unit::TestCase subclasses. # module P4RubyTest @@STARTDIR = Dir.getwd @@ROOTDIR = "testroot" @@P4D = "p4d" # Assume it's in the PATH attr_accessor :p4 # # Rather ugly, but very effective... # def initialize( test_method_name ) super( test_method_name ) Dir.chdir( client_root ) ENV.delete( 'PWD' ) init_client() end # # Set up the test tree - cleaning out any old data # def create_test_tree() if( File.directory?( server_root ) ) puts( "Removing old test tree!" ) cleanup_test_tree() end Dir.mkdir( server_root ) Dir.mkdir( client_root ) create_p4config_file() true end def init_client() # Create a P4 object for all tests. Makes life simple. @p4 = P4.new @p4.port = "rsh:#{@@P4D} -r #{server_root} -L log -vserver=3 -i" @p4.parse_forms end # # Cleanup the test tree # def cleanup_test_tree() rmdir( server_root ) end # # Return the path of the server root # def server_root @@STARTDIR + '/' + @@ROOTDIR end # # Return the client root # def client_root server_root + '/' + 'workspace' end private # # Nuke an entire tree # def rmdir( top ) Dir.entries( top ).each do |ent| next if( ent == '.' || ent == '..' ) path = top + '/' + ent if( File.directory?( path ) ) rmdir( path ) else File.unlink( path ) end end Dir.delete( top ) end def create_p4config_file return unless ( ENV.has_key?( 'P4CONFIG' ) ) File.open( server_root + '/' + ENV[ 'P4CONFIG' ], "w" ) do |f| f.puts( "P4PORT=#{@p4.port}" ) end end end # # Load each test in the test/ subdirectory in alphabetical order of filename. # This (through the magic of overriding Test::Unit::TestCase.inherited) will # also be the execution order. # Dir.entries( "test" ).sort.each do |ent| next if( ent == "." || ent == ".." ) next unless ent =~ /^\d+_\w+.rb/ puts( "Loading test/#{ent}..." ) require "test/#{ent}" end # # Build the test suite by adding in the tests, in the order that they # were loaded. Note that what we're adding is the classes rather than # the filenames, so we use the global $p4ruby_test_list to access the # Test::Unit::TestCase subclasses. # class TestSuite def self.suite suite = Test::Unit::TestSuite.new( "P4Ruby Tests" ) $p4ruby_test_list.each do |t| suite << t.suite end suite end end # # Now run them # Test::Unit::UI::Console::TestRunner.run( TestSuite, 3 )
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#18 | 14677 | tony |
Delete obsolete test runner: 'rake test' does the trick now, and fix up the manifest file |
||
#17 | 14676 | tony |
Rework P4Ruby unit tests so they they are actually units. Now the test order is irrelevant as all tests are standalone. Tidied up the code formatting as well and removed all the tabs from the ruby sources files. Added a modeline for vim users so consistent indentation will be used. |
||
#16 | 14654 | jmistry |
Merging P4Ruby p12.2 to main. Integration only change. |
||
#15 | 14642 | jmistry |
Ensure exit 1 on failure Previously, 'test.rb' would always return with an exit 0, even if a test failed or raised an error. Now exit with the result of 'Test::Unit::UI::Console::TestRunner.run().passed?'. |
||
#14 | 14624 | jmistry | Pull p11.1 changes back to main | ||
#13 | 14622 | jmistry |
Pull 10.2 changes to main Pick up missing changes in p10.2 and integrate to main. As part of the integrate I also moved the unit tests '16_streams.rb' and '17_streaming_handler.rb' because the integration introduced collisions with the unit test names. Updated MANIFEST with new names for unit tests and also added '98_unicode.rb', which was missing from it. |
||
#12 | 14592 | Sven Erik Knop |
Enable P4-Ruby to compile and test with Ruby 1.9. The current solution is far from ideal because it is not possible to compile and test both Ruby 1.8 and Ruby 1.9 in parallel. The Makefile writes both artifacts and binaries to the same location. This means a user/tester/builder needs to choose on Ruby platform or ensure 'make clean' is called first. Many of the test cases also still fail in Ruby 1.9. We also need to investigate the Unicode story with Ruby 1.9 and see if the lessons learned from Python 3 can be applied somehow. Infrastructure change, no functional change yet. |
||
#11 | 14578 | tony | Pull 2010.1 changes into main | ||
#10 | 14575 | tony |
Add some simple unicode tests to prove that P4Ruby supports unicode mode. It has done so for many years, but it's nice to have some tests to make sure it doesn't get broken. Testing infrastructure change only |
||
#9 | 14574 | tony |
Fix P4Ruby's test suite so it works for Ruby 1.9 and Ruby 1.8. The interface for Ruby's Unit::Test module has changed slightly between the two versions. In Ruby 1.8, the verbosity was passed as an integer, while in Ruby 1.9 it's one of several options passed as a hash. This change checks the version number of Ruby and adapts the call if it's 1.9 or later. |
||
#8 | 14571 | tony |
Tidy P4Ruby's connection state management. P4ClientApi was accumulating a lot of 'int' flags. This change combines them all into a bitmask with some methods to encapsulate the manipulation of the mask. I've also removed the code which worked around a very old and obscure protocol bug in 2000.1/2000.2 servers. Anyone using a server that old doesn't deserve the modern P4Ruby. To test P4#server_case_sensitive? I have adapted the test suite so that the server it runs uses the -C1 flag - so it's case-folding on all platforms. The reason for this is that it enables the tests to succeed on Windows and Mac OS where case-folding is the norm. Infrastructure change only. No functional change. |
||
#7 | 14541 | tony |
Copyright notice housekeeping: update all notices to 2008, and correct start date from 1997 to 2001 when P4Ruby was first released from the public depot. No functional change |
||
#6 | 14522 | tony | Add copyright notices to the test files. | ||
#5 | 14518 | tony |
Porting changes for Windows. A few tweaks to the generated makefile are required to stop Windows griping about file permissions on chmod, and since it's sometimes hard to delete a file immediately after closing it, we have a couple of retries built-in to the test suite now. Note that to clean up the test root, we have to shut all the spawned p4d's down. That means all the clients must disconnect, so the test cases that connect have all be updated to disconnect. |
||
#4 | 14507 | tony |
Add optional --keep parameter to test.rb so that the test root can be saved for investigation when things go wrong. |
||
#3 | 14497 | tony |
Porting changes for NT. No functional change |
||
#2 | 14493 | tony |
Turn on tagged mode by default, and make parse_forms mode always on (it only works when tagged mode is on too). Now users can turn tagged mode off if they want to by calling: p4.tagged = false and turn it back on by calling: p4.tagged = true You can test the current state of affairs using: p4.tagged? User-visible change to be documented in Scripting Interface Guide |
||
#1 | 14491 | tony |
Add first draft of automated test suite for P4Ruby. Run it using 'ruby test.rb' |