require 'test_helper' setup_database() require 'build-tool/cfg/parser' class TestParserGit < ActiveSupport::TestCase def setup @configuration = BuildTool::Configuration.new() @configuration.truncate() @parser = BuildTool::Cfg::Parser.new( @configuration ) end test "Parses a valid git repository declation." do @configuration.add_server( BuildTool::Server.new( 'anongit.gitorious.org', 'git://gitorious.org' ) ) assert_nothing_raised() { @parser.parse_string <<-EOF } module "qt" vcs git remote "kde-qt" url "anongit.gitorious.org" "+kde-developers/qt/kde-qt" end url "anongit.gitorious.org" "qt/qt" # The remote branch we rebase against. track "origin/4.8" end # vcs end # module EOF # Now check the parsed configuration assert_not_nil( @configuration.module('qt') ) assert_attributes( @configuration.module('qt'), { :vcs => { :name => 'git', :config => lambda { |x| assert_not_nil( x.remote['origin'] ) assert_equal( 'git://gitorious.org/qt/qt' , x.remote['origin'].url ) assert_equal( 'origin/4.8', x.track ) } } } ) end test "Git Repository inheritance works." do @configuration.add_server( BuildTool::Server.new( 'anongit.gitorious.org', 'git://anongit.gitorious.org' ) ) assert_nothing_raised() { @parser.parse_string <<-EOF } module "qt" vcs git remote "kde-qt" url "anongit.gitorious.org" "+kde-developers/qt/kde-qt" end url "anongit.gitorious.org" "qt/qt" # The remote branch we rebase against. track "origin/4.8" end # vcs end # module module "qt" vcs git < remote "qt" url "git://myurl" end track "origin/4.7" end # vcs end # module EOF # Now check the parsed configuration assert_not_nil( @configuration.module('qt') ) assert_attributes( @configuration.module('qt'), { :vcs => { :name => 'git' } } ) config = @configuration.module('qt').vcs.config assert_not_nil( config.parent, 'has a parent' ) assert_equal( 'origin/4.7', config.track ) assert_not_nil( config.merged_remote['origin'], 'origin still set' ) assert_equal( 'git://anongit.gitorious.org/qt/qt' , config.merged_remote['origin'].url ) assert_not_nil( config.merged_remote['kde-qt'], 'kde-qt still set' ) assert_equal( 'git://anongit.gitorious.org/+kde-developers/qt/kde-qt' , config.merged_remote['kde-qt'].url ) assert_not_nil( config.merged_remote['qt'], 'qt there too' ) assert_equal( 'git://myurl' , config.merged_remote['qt'].url ) end end