# vim:ts=2:sw=2:et: #------------------------------------------------------------------------------- # Copyright (c) 2010, 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_Output < Test::Unit::TestCase include P4RubyTest def name "Test output" end def test_new_output assert( p4, "Failed to create Perforce client" ) begin # First test new output format assert( p4.connect, "Failed to connect to Perforce server" ) assert( create_client, "Failed to create test workspace" ) # Add test files %w{ foo bar baz }.each do |name| File.open( name, "w" ) do |f| f.puts( "Test" ) end p4.run_add( name ) end p4.run_submit( '-dtest' ) # Run a 'p4 sync' and ignore the output, then run it again # and we should get a 'file(s) up-to-date' message that we # want to trap. p4.exception_level = P4::RAISE_NONE p4.run_sync p4.run_sync # Check warnings array contains the warning as a string assert( !p4.warnings.empty?, "Didn't get a warning!") w = p4.warnings[0] assert( w.kind_of?( String ), "Didn't get a String" ) assert( w =~ /up-to-date/, "Didn't get expected warning" ) # Now check messages array contains the message object assert( !p4.messages.empty?, "Didn't get any messages!" ) assert( p4.messages.length == 1 ) w = p4.messages[0] assert( w.kind_of?( P4::Message ), "Didn't get a P4::Message object" ) assert( w.to_s =~ /up-to-date/, "Didn't get expected warning. Got '#{w.to_s}'" ) assert( w.severity == P4::E_WARN, "Severity was not E_WARN" ) assert( w.generic == P4::EV_EMPTY, "Wasn't an empty message" ) assert( w.msgid == 6532, "Got the wrong message: #{w.msgid}" ) # Sync to none and then sync to head - check number of info, warning # and error messages p4.run_sync( '//...#none' ); p4.tagged = false p4.run_sync( '//depot/...' ) infos = p4.messages.select { |m| m.severity == P4::E_INFO } warns = p4.messages.select { |m| m.severity == P4::E_WARN } errs = p4.messages.select { |m| m.severity >= P4::E_FAILED } assert_equal(3, infos.length, "Wrong number of info messages") assert_equal(0, warns.length, "Wrong number of warnings" ) assert_equal(0, errs.length, "Wrong number of errors" ) ensure p4.disconnect end end end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15524 | surajdolby |
Populate -o //guest/perforce_software/p4ruby/main/... //guest/surajdolby/p4ruby/.... |
||
//guest/perforce_software/p4ruby/main/test/14_output_test.rb | |||||
#1 | 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. |
||
//guest/perforce_software/p4ruby/main/test/14_output.rb | |||||
#6 | 14624 | jmistry | Pull p11.1 changes back to main | ||
#5 | 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. |
||
#4 | 14610 | jmistry |
Fix unlink error on unit tests Wrap the connect/disconnect in begin/ensure blocks to ensure that the client disconnect even if there are failures in a unit test. Fix unicode unit test for 1.9. When the contents of a file is stored in a String object, ruby 1.9 sets the String's encoding to the current locale. This is overridden in the test case and set to the correct value. This may need to be documented. user visible change. |
||
#3 | 14589 | Sven Erik Knop | Pulled P4Ruby p10.2 changes back to main. | ||
#2 | 14580 | tony |
Added P4::Message#msgid method that returns the UniqueCode of any error message - much easier than matching it's output text. User-visible enhancement documented in p4rubynotes.txt |
||
#1 | 14579 | tony |
Make new class P4::Message for returning Error objects to the user. Currently handles errors and warnings, but could potentially be used for output too (might bloat people's code though). Essentially, if you're using a 2010.2 or later client, or if you've set your api_level to 68 or higher, the P4#errors and P4#warnings arrays will be populated with P4::Message objects instead of strings. Users of older API's, or those who set their api_level to 67 or lower in their scripts will get the old behaviour. P4::Message objects have the following methods: severity() - returns the severity generic() - returns the generic code to_s() - converts the message to a string inspect() - returns a string showing the message details. User-visible enhancement documented in p4rubynotes.txt |