#------------------------------------------------------------------------------- # Copyright (c) 1997-2007, Perforce Software, Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE # SOFTWARE, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH # DAMAGE. #------------------------------------------------------------------------------- class TC_Resolve < Test::Unit::TestCase include P4RubyTest def name "Test resolve operations" end def test_resolve assert( p4, "Failed to create Perforce client" ) begin test_dir = "test_resolve" Dir.mkdir( test_dir ) file = "foo" fname = File.join( test_dir, file ) assert( p4.connect, "Failed to connect to Perforce server" ) assert( p4.run_opened.length == 0, "Shouldn't have any open files" ) # Create the file to test resolve File.open( fname, 'w' ) { |fd| fd.puts( "First Line!" ) } p4.run_add( fname ) assert( p4.run_opened.length == 1, "Unexpected number of open files" ) change = p4.fetch_change assert( change.kind_of?( P4::Spec ), "Change form is not a P4::Spec" ) change._description = "First resolve submit" assert( change._description == "First resolve submit", "Change description not set properly" ) assert_submit( "Failed to add file", change ) assert( p4.run_opened.length == 0, "Unexpected number of open files" ) # Create a second revision of the file p4.run_edit( fname ) File.open( fname, "a" ) { |fd| fd.puts( "Second Line." ) } assert( p4.run_opened.length == 1, "Unexpected number of open files" ) change = p4.fetch_change assert( change.kind_of?( P4::Spec ), "Change form is not a P4::Spec" ) change._description = "Second resolve submit" assert( change._description == "Second resolve submit", "Change description not set properly" ) assert_submit( "Failed to add file", change ) assert( p4.run_opened.length == 0, "Unexpected number of open files" ) assert_nothing_raised( "Problem scheduling resolve for {#fname}" ) do # Now sync to rev #1 p4.run_sync( fname + "#1" ) # open the file for edit and sync to schedule a resolve p4.run_edit( fname ) p4.run_sync( fname ) end # ...and test a standard resolve p4.run_resolve do |md| client = p4.client assert( md.class == P4::MergeData, "Merge data wasn't a P4::MergeData object" ) assert_equal( "//#{client}/#{fname}", md.your_name, "Unexpected Your name: #{md.your_name}" ) assert_equal( "//depot/#{fname}#2", md.their_name, "Unexpected Their name: #{md.their_name}" ) assert_equal( "//depot/#{fname}#1", md.base_name, "Unexpected Base name: #{md.base_name}" ) assert_equal( "at", md.merge_hint, "Unexpected merge hint: #{md.merge_hint}" ) "at" end change = p4.fetch_change assert( change.kind_of?( P4::Spec ), "Change form is not a P4::Spec" ) change._description = "Third resolve submit" assert( change._description == "Third resolve submit", "Change description not set properly" ) assert_submit( "Failed to add file", change ) assert( p4.run_opened.length == 0, "Unexpected number of open files" ) # Test to check that exceptions cause the resolve to stop at # the point that the exception happened. assert_nothing_raised( "Problem scheduling resolve for {#fname}" ) do p4.run_sync( fname + "#1" ) p4.run_edit( fname ) p4.run_sync( fname + "#2" ) p4.run_edit( fname ) p4.run_sync( fname ) end assert_equal( 2, p4.run_resolve( "-n" ).length, "Unexpected number of resolves scheduled" ) assert_raise( RuntimeError ) do count = 0 p4.run_resolve do |md| puts "Count: #{count}" raise RuntimeError, "Force an exception during a resolve." unless count > 0 count += 1 "at" end end ensure p4.run_revert( '//...' ) unless( p4.run_opened.empty? ) p4.disconnect end end # # Local method to help ensure submits are working # def assert_submit( msg, *args ) assert_block( msg ) do begin result = @p4.run_submit( args ) if( result[-1].has_key?( 'submittedChange' ) ) true else false end rescue P4Exception false end end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#8 | 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. |
||
#7 | 14641 | jmistry |
pull unit test fix from p12.1 to main. Integration only change. |
||
#6 | 14640 | jmistry |
Pull changes from p12.1 to main. Integration only change. |
||
#5 | 14636 | jmistry |
Fix binary file resolve Accessing the base_name attribute of a P4::MergeData object resulted in a segmentation fault when resolving binary files. This is because the base file is empty for binary files, and the Name() method invoked on it does not protect itself in case of a NULL value. User visible change, to be documented in the release notes. |
||
#4 | 14633 | jmistry |
remove md.info[ 'clientFile' ] check Difficult to test the value of this on different platforms, so removing it for now. The remaining checks against P4::MergeData#info should be enough to ensure that it contains the correct information. |
||
#3 | 14629 | jmistry |
Implemented 'action resolve' in P4Ruby. This extends the existing P4MergeData class to support action resolve. Users will need to test the MergeData object passed to the block to determine if the resolve is for content (P4::MergeData#content_resolve?) or action (P4::MergeData#action_resolve?). The attributes available in 'P4::MergeDatamerge' for an action resolve are: merge_action : The action chosen for the merge, can be emtpy yours_action: your action/filetype their_action: their action/filetype type: the type of merge. Can be "Branch resolve", "Filetype resolve", "Delete resolve" "Filename resolve" info: a dictionary with additional information that can vary with the resolve type. Updated unit test to test action resolve. User visible change, to be documented in the release notes for 2012.1. |
||
#2 | 14628 | jmistry |
Quit resolve if there is an exception. Follow-on from change @410702, which raised exceptions up to the user from P4#run_resolve. Further testing showed that if multiple resolves are scheduled and an exception is raised, then subsequent resolves would clear that. We now check if an exception has been raised by an earlier resolve and return early if there has been. Unit test has been updated with this case. User visible change to be documented in release notes. |
||
#1 | 14625 | jmistry |
Add resolve test case Before beginning work on ActionResolve, let's add a unit test for content resolves. |