build-tool 0.5.7 → 0.6.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.rvmrc +1 -0
- data/.yardopts +1 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +56 -0
- data/History.txt +64 -0
- data/README.txt +0 -7
- data/Rakefile +8 -56
- data/bin/build-tool +4 -1
- data/build-tool.gemspec +62 -0
- data/db/migrations/20110703074000_add_command_logs.rb +17 -0
- data/db/migrations/20110703075000_add_module_logs.rb +20 -0
- data/db/migrations/20110815170000_add_features.rb +17 -0
- data/db/migrations/20120103204700_add_modules.rb +17 -0
- data/db/migrations/20120106181200_add_settings.rb +18 -0
- data/lib/build-tool.rb +3 -4
- data/lib/build-tool/application.rb +127 -37
- data/lib/build-tool/build-system/autoconf.rb +2 -8
- data/lib/build-tool/build-system/base.rb +12 -4
- data/lib/build-tool/build-system/cmake.rb +2 -0
- data/lib/build-tool/build-system/custom.rb +2 -0
- data/lib/build-tool/build-system/kdel10n.rb +2 -0
- data/lib/build-tool/build-system/make.rb +2 -0
- data/lib/build-tool/build-system/none.rb +2 -0
- data/lib/build-tool/build-system/qmake.rb +2 -0
- data/lib/build-tool/build-system/qt.rb +4 -0
- data/lib/build-tool/cfg/lexer.rex +40 -8
- data/lib/build-tool/cfg/lexer_base.rb +3 -1
- data/lib/build-tool/cfg/node.rb +17 -1
- data/lib/build-tool/cfg/parser.y +92 -10
- data/lib/build-tool/cfg/visitor.rb +202 -78
- data/lib/build-tool/command_actions.rb +26 -10
- data/lib/build-tool/commands.rb +289 -197
- data/lib/build-tool/commands/build.rb +13 -9
- data/lib/build-tool/commands/configuration.rb +25 -0
- data/lib/build-tool/commands/configuration/edit.rb +42 -0
- data/lib/build-tool/commands/configuration/list.rb +48 -0
- data/lib/build-tool/commands/configure.rb +9 -5
- data/lib/build-tool/commands/ctags.rb +8 -3
- data/lib/build-tool/commands/environments.rb +2 -4
- data/lib/build-tool/commands/environments/list.rb +13 -10
- data/lib/build-tool/commands/environments/set.rb +5 -1
- data/lib/build-tool/commands/features.rb +24 -0
- data/lib/build-tool/commands/features/disable.rb +70 -0
- data/lib/build-tool/commands/features/enable.rb +66 -0
- data/lib/build-tool/commands/features/list.rb +92 -0
- data/lib/build-tool/commands/fetch.rb +9 -3
- data/lib/build-tool/commands/files.rb +9 -5
- data/lib/build-tool/commands/gc.rb +48 -15
- data/lib/build-tool/commands/history.rb +21 -16
- data/lib/build-tool/commands/info.rb +16 -13
- data/lib/build-tool/commands/install.rb +8 -4
- data/lib/build-tool/commands/modules.rb +2 -4
- data/lib/build-tool/commands/modules/cleanup.rb +52 -0
- data/lib/build-tool/commands/modules/disable.rb +95 -0
- data/lib/build-tool/commands/modules/enable.rb +52 -0
- data/lib/build-tool/commands/modules/info.rb +44 -35
- data/lib/build-tool/commands/modules/list.rb +67 -15
- data/lib/build-tool/commands/modules/shell.rb +8 -2
- data/lib/build-tool/commands/rebase.rb +15 -7
- data/lib/build-tool/commands/recipes.rb +2 -4
- data/lib/build-tool/commands/recipes/add.rb +16 -2
- data/lib/build-tool/commands/recipes/edit.rb +72 -0
- data/lib/build-tool/commands/recipes/incoming.rb +11 -7
- data/lib/build-tool/commands/recipes/info.rb +12 -8
- data/lib/build-tool/commands/recipes/install.rb +37 -42
- data/lib/build-tool/commands/recipes/list.rb +6 -2
- data/lib/build-tool/configuration.rb +88 -3
- data/lib/build-tool/environment.rb +2 -0
- data/lib/build-tool/errors.rb +5 -0
- data/lib/build-tool/history.rb +3 -181
- data/lib/build-tool/model/command_log.rb +93 -0
- data/lib/build-tool/model/feature.rb +80 -0
- data/lib/build-tool/{module.rb → model/module.rb} +110 -29
- data/lib/build-tool/model/module_log.rb +64 -0
- data/lib/build-tool/model/setting.rb +84 -0
- data/lib/build-tool/recipe.rb +40 -18
- data/lib/build-tool/repository.rb +39 -33
- data/lib/build-tool/server.rb +27 -3
- data/lib/build-tool/singleton.rb +2 -0
- data/lib/build-tool/sshkey.rb +2 -0
- data/lib/build-tool/state_helper.rb +64 -0
- data/lib/build-tool/vcs/archive.rb +3 -1
- data/lib/build-tool/vcs/base.rb +13 -0
- data/lib/build-tool/vcs/git-svn.rb +36 -14
- data/lib/build-tool/vcs/git.rb +180 -44
- data/lib/build-tool/vcs/mercurial.rb +25 -13
- data/lib/build-tool/vcs/svn.rb +20 -15
- data/lib/build-tool/version.rb +30 -0
- data/lib/mj/error.rb +2 -0
- data/lib/mj/logging.rb +2 -0
- data/lib/mj/mixins/inherited_attributes.rb +73 -0
- data/lib/mj/tools/editor.rb +34 -0
- data/lib/mj/tools/ssh.rb +2 -0
- data/lib/mj/tools/subprocess.rb +2 -1
- data/lib/mj/vcs/git.rb +14 -2
- data/lib/mj/visitor.rb +22 -0
- data/tasks/db.rake +36 -0
- data/tasks/racc.rake +14 -0
- data/tasks/rdoc.rake +8 -0
- data/tasks/rexical.rake +14 -0
- data/tasks/test.rake +21 -0
- data/test/integration/history_test.rb +88 -0
- data/test/integration/parser_configuration.rb +36 -0
- data/test/integration/parser_environment_parser.rb +156 -0
- data/test/integration/parser_feature_test.rb +75 -0
- data/test/integration/parser_git-svn_test.rb +92 -0
- data/test/integration/parser_git_test.rb +97 -0
- data/test/integration/parser_mercurial_test.rb +77 -0
- data/test/integration/parser_module_test.rb +103 -0
- data/test/integration/parser_svn_test.rb +92 -0
- data/test/integration/parser_test.rb +73 -0
- data/test/test_helper.rb +61 -0
- data/test/unit/configuration_test.rb +36 -0
- data/test/unit/git_configuration_test.rb +163 -0
- data/test/unit/git_svn_configuration_test.rb +240 -0
- data/test/unit/mercurial_configuration_test.rb +64 -0
- data/test/unit/model/command_log_test.rb +103 -0
- data/test/unit/model/feature_test.rb +29 -0
- data/test/unit/model/module_log_test.rb +70 -0
- data/test/unit/model/module_test.rb +32 -0
- data/test/unit/repository_test.rb +110 -0
- data/test/unit/server_test.rb +66 -0
- data/test/unit/svn_configuration_test.rb +90 -0
- metadata +134 -93
- data/Manifest.txt +0 -80
- data/db/migrations/001_command_histories.rb +0 -20
- data/db/migrations/002_module_events.rb +0 -24
- data/db/migrations/003_command_histories_add_logfile.rb +0 -19
- data/lib/build-tool/GUI.rb +0 -360
- data/lib/build-tool/commands/help.rb +0 -22
- data/lib/build-tool/commands/lsfeatures.rb +0 -76
- data/lib/build-tool/feature.rb +0 -47
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
setup_database()
|
4
|
+
|
5
|
+
require 'build-tool/cfg/parser'
|
6
|
+
|
7
|
+
class ParserModuleTest < ActiveSupport::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@configuration = BuildTool::Configuration.new()
|
11
|
+
@configuration.truncate()
|
12
|
+
@parser = BuildTool::Cfg::Parser.new( @configuration )
|
13
|
+
@localparser = BuildTool::Cfg::Parser.new( @configuration, false )
|
14
|
+
end
|
15
|
+
|
16
|
+
test 'Parses a valid module declaration' do
|
17
|
+
assert_nothing_raised() { @parser.parse_string <<-EOF }
|
18
|
+
module "test_default"
|
19
|
+
end
|
20
|
+
module "test_disabled"
|
21
|
+
end
|
22
|
+
disable module "test_disabled"
|
23
|
+
EOF
|
24
|
+
# Now check the parsed configuration
|
25
|
+
assert( @configuration.module( 'test_default' ).default_active? )
|
26
|
+
assert( @configuration.module( 'test_default' ).active? )
|
27
|
+
assert( !@configuration.module( 'test_disabled' ).default_active? )
|
28
|
+
assert( !@configuration.module( 'test_disabled' ).active? )
|
29
|
+
|
30
|
+
# Parse a local config file
|
31
|
+
@localparser.parse_string <<-EOF
|
32
|
+
disable module "test_default"
|
33
|
+
enable module "test_disabled"
|
34
|
+
EOF
|
35
|
+
|
36
|
+
# Now check the parsed configuration
|
37
|
+
assert( !@configuration.module( 'test_default' ).active? )
|
38
|
+
assert( @configuration.module( 'test_disabled' ).active? )
|
39
|
+
# But the defaults are the same
|
40
|
+
assert( @configuration.module( 'test_default' ).default_active? )
|
41
|
+
assert( !@configuration.module( 'test_disabled' ).default_active? )
|
42
|
+
@configuration.save()
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'Parses all values' do
|
46
|
+
assert_nothing_raised() { @parser.parse_string <<-EOF }
|
47
|
+
module "test_default"
|
48
|
+
description "Default is a test module"
|
49
|
+
long description "It really is"
|
50
|
+
end
|
51
|
+
EOF
|
52
|
+
# Now check the parsed configuration
|
53
|
+
assert( @configuration.module( 'test_default' ) )
|
54
|
+
mod = @configuration.module( 'test_default' )
|
55
|
+
assert_equal( mod.description, 'Default is a test module' )
|
56
|
+
assert_equal( mod.long_description, 'It really is' )
|
57
|
+
|
58
|
+
# Parse a local config file
|
59
|
+
@localparser.parse_string <<-EOF
|
60
|
+
module "test_default"
|
61
|
+
long description """Multi line comment
|
62
|
+
works"""
|
63
|
+
end
|
64
|
+
EOF
|
65
|
+
|
66
|
+
mod = @configuration.module( 'test_default' )
|
67
|
+
assert_equal( 'Default is a test module', mod.description )
|
68
|
+
assert_equal( "Multi line comment\nworks", mod.long_description )
|
69
|
+
end
|
70
|
+
|
71
|
+
test 'Keeps settings over reloads' do
|
72
|
+
assert_nothing_raised() { @parser.parse_string <<-EOF }
|
73
|
+
module "test_default"
|
74
|
+
end
|
75
|
+
module "test_disabled"
|
76
|
+
end
|
77
|
+
disable module "test_disabled"
|
78
|
+
EOF
|
79
|
+
@configuration.module( 'test_disabled' ).active = true
|
80
|
+
@configuration.module( 'test_default' ).active = false
|
81
|
+
@configuration.save()
|
82
|
+
|
83
|
+
@configuration = BuildTool::Configuration.new()
|
84
|
+
@configuration.load()
|
85
|
+
@parser = BuildTool::Cfg::Parser.new( @configuration )
|
86
|
+
@localparser = BuildTool::Cfg::Parser.new( @configuration, false )
|
87
|
+
assert_nothing_raised() { @parser.parse_string <<-EOF }
|
88
|
+
module "base"
|
89
|
+
end
|
90
|
+
module "test_default" < "base"
|
91
|
+
end
|
92
|
+
module "test_disabled"
|
93
|
+
end
|
94
|
+
disable module "test_disabled"
|
95
|
+
EOF
|
96
|
+
|
97
|
+
# Now check the parsed configuration.
|
98
|
+
assert( !@configuration.module( 'test_default' ).active? )
|
99
|
+
assert( @configuration.module( 'test_disabled' ).active? )
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end # class TestParserModuleTest
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
setup_database()
|
4
|
+
|
5
|
+
require 'build-tool/cfg/parser'
|
6
|
+
|
7
|
+
class TestParserSvn < ActiveSupport::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@configuration = BuildTool::Configuration.new()
|
11
|
+
@configuration.truncate()
|
12
|
+
@parser = BuildTool::Cfg::Parser.new( @configuration )
|
13
|
+
end
|
14
|
+
|
15
|
+
test "Parses a valid svn repository declation." do
|
16
|
+
@configuration.add_server( BuildTool::Server.new( 'svn.kde.org', 'svn://anonsvn.kde.org/home/kde' ) )
|
17
|
+
@configuration.add_repository( BuildTool::Repository.new( 'kde' ) )
|
18
|
+
@configuration.repository( 'kde' ).server = @configuration.server( 'svn.kde.org' )
|
19
|
+
assert_nothing_raised() { @parser.parse_string <<-EOF }
|
20
|
+
module "oxygen-icons"
|
21
|
+
vcs svn
|
22
|
+
remote-path "kdesupport/oxygen"
|
23
|
+
use repository "kde"
|
24
|
+
end # vcs
|
25
|
+
end # module
|
26
|
+
EOF
|
27
|
+
# Now check the parsed configuration
|
28
|
+
assert_not_nil( @configuration.module('oxygen-icons') )
|
29
|
+
assert_attributes(
|
30
|
+
@configuration.module('oxygen-icons'),
|
31
|
+
{
|
32
|
+
:vcs =>
|
33
|
+
{
|
34
|
+
:name => 'svn',
|
35
|
+
:config =>
|
36
|
+
{
|
37
|
+
:repository =>
|
38
|
+
{
|
39
|
+
:name => 'kde',
|
40
|
+
:url => 'svn://anonsvn.kde.org/home/kde'
|
41
|
+
},
|
42
|
+
:remote_path => "kdesupport/oxygen"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
}
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
test "SVN Repository inheritance works." do
|
51
|
+
@configuration.add_server( BuildTool::Server.new( 'svn.kde.org', 'svn://anonsvn.kde.org/home/kde' ) )
|
52
|
+
@configuration.add_repository( BuildTool::Repository.new( 'kde' ) )
|
53
|
+
@configuration.repository( 'kde' ).server = @configuration.server( 'svn.kde.org' )
|
54
|
+
assert_nothing_raised() { @parser.parse_string <<-EOF }
|
55
|
+
module "oxygen-icons"
|
56
|
+
vcs svn
|
57
|
+
remote-path "kdesupport/oxygen"
|
58
|
+
use repository "kde"
|
59
|
+
end # vcs
|
60
|
+
end # module
|
61
|
+
module "oxygen-icons"
|
62
|
+
vcs svn <
|
63
|
+
remote-path "kdesupport/oxygen-neu"
|
64
|
+
end # vcs
|
65
|
+
end # module
|
66
|
+
EOF
|
67
|
+
# Now check the parsed configuration
|
68
|
+
assert_not_nil( @configuration.module('oxygen-icons') )
|
69
|
+
assert_attributes(
|
70
|
+
@configuration.module('oxygen-icons'),
|
71
|
+
{
|
72
|
+
:vcs =>
|
73
|
+
{
|
74
|
+
:name => 'svn',
|
75
|
+
:config =>
|
76
|
+
{
|
77
|
+
:repository =>
|
78
|
+
{
|
79
|
+
:name => 'kde',
|
80
|
+
:url => 'svn://anonsvn.kde.org/home/kde'
|
81
|
+
},
|
82
|
+
:remote_path => "kdesupport/oxygen-neu"
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
}
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
setup_database()
|
4
|
+
|
5
|
+
require 'build-tool/cfg/parser'
|
6
|
+
|
7
|
+
class TestParser < ActiveSupport::TestCase
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@configuration = BuildTool::Configuration.new()
|
11
|
+
@configuration.truncate()
|
12
|
+
@parser = BuildTool::Cfg::Parser.new( @configuration )
|
13
|
+
end
|
14
|
+
|
15
|
+
test "Parser parses a empty string" do
|
16
|
+
assert_nothing_raised() { @parser.parse_string( "" ) }
|
17
|
+
end
|
18
|
+
|
19
|
+
test "Parser throws an exception on invalid input" do
|
20
|
+
assert_raise(BuildTool::ParseError) do @parser.parse_string( "this is really invalid text" ) end
|
21
|
+
end
|
22
|
+
|
23
|
+
test "Parses a valid recipe" do
|
24
|
+
assert_nothing_raised() { @parser.parse_string <<-EOF }
|
25
|
+
log-directory "$HOME/test/log"
|
26
|
+
|
27
|
+
module "test"
|
28
|
+
build-prefix "/home/mjansen/test"
|
29
|
+
install-prefix "/tst"
|
30
|
+
end
|
31
|
+
EOF
|
32
|
+
# Now check the parsed configuration
|
33
|
+
test = @configuration.module('test')
|
34
|
+
assert_not_nil( @configuration.module('test'), 'There is a module named "test".' )
|
35
|
+
assert( test.active?, 'The module is active.' )
|
36
|
+
assert_nil( test.parent, 'The module has no parent.' )
|
37
|
+
assert_equal(
|
38
|
+
Pathname.new( '/home/mjansen/test' ),
|
39
|
+
test.build_prefix,
|
40
|
+
'The build prefix is correctly set.' )
|
41
|
+
assert_equal(
|
42
|
+
Pathname.new( '/home/mjansen/test/bld/test' ),
|
43
|
+
test.build_directory,
|
44
|
+
'The build directory is correctly set' )
|
45
|
+
end
|
46
|
+
|
47
|
+
test "Parses a valid recipe with module inheritance" do
|
48
|
+
assert_nothing_raised() { @parser.parse_string <<-EOF }
|
49
|
+
log-directory "$HOME/test/log"
|
50
|
+
|
51
|
+
module "base"
|
52
|
+
build-prefix "/home/mjansen/test"
|
53
|
+
install-prefix "/tst"
|
54
|
+
end
|
55
|
+
module "test_inherit" < "base"
|
56
|
+
end
|
57
|
+
EOF
|
58
|
+
# Now check the parsed configuration
|
59
|
+
test = @configuration.module('test_inherit')
|
60
|
+
assert_not_nil( test, 'There is a module named "test".' )
|
61
|
+
assert( test.active?, 'The module is active.' )
|
62
|
+
assert_equal( test.parent, @configuration.module('base') )
|
63
|
+
assert_equal(
|
64
|
+
Pathname.new( '/home/mjansen/test' ),
|
65
|
+
test.build_prefix,
|
66
|
+
'The build prefix is correctly set.' )
|
67
|
+
assert_equal(
|
68
|
+
Pathname.new( '/home/mjansen/test/bld/test_inherit' ),
|
69
|
+
test.build_directory,
|
70
|
+
'The build directory is correctly set' )
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'active_support/test_case'
|
3
|
+
require 'active_record'
|
4
|
+
|
5
|
+
require 'logging'
|
6
|
+
Logging.init :debug2, :debug, :trace, :verbose, :info, :warn, :error
|
7
|
+
include Logging.globally
|
8
|
+
|
9
|
+
begin
|
10
|
+
# require 'turn'
|
11
|
+
rescue LoadError
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# Set up the database.
|
16
|
+
def setup_database
|
17
|
+
if not ActiveRecord::Base.connected?
|
18
|
+
ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ':memory:' )
|
19
|
+
ActiveRecord::Migrator.migrate( [ 'db/migrations' ] )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def close_database
|
24
|
+
ActiveRecord::Base.remove_connection
|
25
|
+
end
|
26
|
+
|
27
|
+
def assert_attributes( obj, attr )
|
28
|
+
|
29
|
+
attr.each do |key, val|
|
30
|
+
case val
|
31
|
+
when :not_nil
|
32
|
+
assert_not_nil( obj.send( key ), "#{key.to_s} should not be nil." )
|
33
|
+
when :nil
|
34
|
+
assert_nil( obj.send( key ), "#{key.to_s} should be nil." )
|
35
|
+
else
|
36
|
+
if val.is_a?( Hash )
|
37
|
+
assert_not_nil( obj.send( key ), "#{key.to_s} should not be nil." )
|
38
|
+
assert_attributes( obj.send( key ), val )
|
39
|
+
elsif val.is_a?( Proc )
|
40
|
+
val.call( obj.send( key ) )
|
41
|
+
else
|
42
|
+
assert_equal( val, obj.send( key ) )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
class RepositoryMock
|
50
|
+
attr_accessor :name
|
51
|
+
def initialize( name )
|
52
|
+
@name = name
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
class ModuleMock
|
57
|
+
attr_accessor :name
|
58
|
+
def initialize( name )
|
59
|
+
@name = name
|
60
|
+
end
|
61
|
+
end # class ModuleMock
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
setup_database()
|
4
|
+
|
5
|
+
require 'build-tool/configuration'
|
6
|
+
|
7
|
+
class ConfigurationTest < ActiveSupport::TestCase
|
8
|
+
|
9
|
+
test 'Constructor.' do
|
10
|
+
c = BuildTool::Configuration.new
|
11
|
+
end
|
12
|
+
|
13
|
+
test 'log_directory is not allowed to be relative' do
|
14
|
+
c = BuildTool::Configuration.new
|
15
|
+
assert_raises( BuildTool::ConfigurationError, /Log directory .* is relative/ ) do
|
16
|
+
c.log_directory = 'my/relative/dir'
|
17
|
+
end
|
18
|
+
assert_raises( BuildTool::ConfigurationError, /Log directory .* is relative/ ) do
|
19
|
+
c.log_directory = '$SOME_SHELL_VAR/relative/dir'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'log_directory handles ~ and $HOME' do
|
24
|
+
c = BuildTool::Configuration.new
|
25
|
+
assert_nothing_raised() do
|
26
|
+
c.log_directory = '$HOME/test1'
|
27
|
+
end
|
28
|
+
assert_equal( "#{ENV["HOME"]}/test1", c.log_directory.to_s )
|
29
|
+
assert_nothing_raised() do
|
30
|
+
c.log_directory = '~/test2'
|
31
|
+
end
|
32
|
+
assert_equal( "#{ENV["HOME"]}/test2", c.log_directory.to_s )
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'build-tool/vcs/git'
|
4
|
+
|
5
|
+
|
6
|
+
class GitConfigurationTest < ActiveSupport::TestCase
|
7
|
+
|
8
|
+
test 'Constructor.' do
|
9
|
+
cfg = BuildTool::VCS::GitConfiguration.new
|
10
|
+
assert_equal( 'git', cfg.name )
|
11
|
+
assert_equal( {}, cfg.remote )
|
12
|
+
assert_equal( {}, cfg.global_options )
|
13
|
+
assert_equal( {}, cfg.options )
|
14
|
+
assert_equal( 'origin/master', cfg.track )
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'Track is correctly split.' do
|
18
|
+
cfg = BuildTool::VCS::GitConfiguration.new
|
19
|
+
assert_equal( 'origin', cfg.track_remote )
|
20
|
+
assert_equal( 'master', cfg.track_branch )
|
21
|
+
cfg.track = 'myremote/mybranch'
|
22
|
+
assert_equal( 'myremote', cfg.track_remote )
|
23
|
+
assert_equal( 'mybranch', cfg.track_branch )
|
24
|
+
end
|
25
|
+
|
26
|
+
test 'Vcs() returns a git instance.' do
|
27
|
+
cfg = BuildTool::VCS::GitConfiguration.new
|
28
|
+
# :TODO:
|
29
|
+
# assert( cfg.vcs.is_a?( BuildTool::VCS::Git ), "vcs() returns a instance of Git." )
|
30
|
+
end
|
31
|
+
|
32
|
+
test 'track() accessor works.' do
|
33
|
+
cfg = create_configuration
|
34
|
+
assert_equal( 'myremote/mybranch', cfg.track )
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'track() accessor works with inheritance.' do
|
38
|
+
parent = create_configuration
|
39
|
+
# Create a empty object with a parent
|
40
|
+
cfg = BuildTool::VCS::GitConfiguration.new
|
41
|
+
cfg.parent = parent
|
42
|
+
# Value is taken from parent
|
43
|
+
assert_equal( 'myremote/mybranch', cfg.track )
|
44
|
+
# Unless we set it locally
|
45
|
+
cfg.track = 'repo1/test'
|
46
|
+
assert_equal( 'repo1/test', cfg.track )
|
47
|
+
# After a reset
|
48
|
+
cfg.track = nil
|
49
|
+
assert_equal( 'myremote/mybranch', cfg.track )
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'options() accessor works.' do
|
53
|
+
cfg = create_configuration
|
54
|
+
assert_equal( 'option 1', cfg.options[:option1] )
|
55
|
+
assert_equal( 'option 2', cfg.options[:option2] )
|
56
|
+
assert_nil( cfg.options[:option3] )
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'options() accessor works with inheritance.' do
|
60
|
+
parent = create_configuration
|
61
|
+
# Create a empty object with a parent
|
62
|
+
cfg = BuildTool::VCS::GitConfiguration.new
|
63
|
+
cfg.parent = parent
|
64
|
+
# Options are not merged.
|
65
|
+
assert_nil( cfg.options[:option1] )
|
66
|
+
assert_nil( cfg.options[:option2] )
|
67
|
+
assert_nil( cfg.options[:option3] )
|
68
|
+
# Merged_options is merged with the parent.
|
69
|
+
assert_equal( 'option 1', cfg.merged_options[:option1] )
|
70
|
+
assert_equal( 'option 2', cfg.merged_options[:option2] )
|
71
|
+
assert_nil( cfg.merged_options[:option3] )
|
72
|
+
# But ours have priority
|
73
|
+
cfg.options[:option1] = 'overwritten'
|
74
|
+
assert_equal( 'overwritten', cfg.merged_options[:option1] )
|
75
|
+
end
|
76
|
+
|
77
|
+
test 'options() accessor works with global configuration.' do
|
78
|
+
cfg = create_configuration
|
79
|
+
create_global_configuration
|
80
|
+
assert_equal( 'option 1', cfg.merged_options[:option1] )
|
81
|
+
assert_equal( 'option 2', cfg.merged_options[:option2] )
|
82
|
+
assert_equal( 'option 3(set globally)', cfg.merged_options[:option3] )
|
83
|
+
end
|
84
|
+
|
85
|
+
test 'options() accessor works with global configuration and inheritance.' do
|
86
|
+
parent = create_configuration
|
87
|
+
# Create a empty object with a parent
|
88
|
+
cfg = BuildTool::VCS::GitConfiguration.new
|
89
|
+
cfg.parent = parent
|
90
|
+
cfg.options[:option1] = 'overwritten'
|
91
|
+
# Merged_options is merged with the parent and global
|
92
|
+
create_global_configuration
|
93
|
+
assert_equal( 'overwritten', cfg.merged_options[:option1] )
|
94
|
+
assert_equal( 'option 2', cfg.merged_options[:option2] )
|
95
|
+
assert_equal( 'option 3(set globally)', cfg.merged_options[:option3] )
|
96
|
+
# And we can reset them
|
97
|
+
cfg.options.delete(:option1)
|
98
|
+
assert_equal( 'option 1', cfg.merged_options[:option1] )
|
99
|
+
end
|
100
|
+
|
101
|
+
test 'global_options() works.' do
|
102
|
+
cfg = create_configuration
|
103
|
+
assert_equal( {}, cfg.global_options )
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'global_options() works with global configuration.' do
|
107
|
+
cfg = create_configuration
|
108
|
+
create_global_configuration
|
109
|
+
assert_equal( 'global option 1', cfg.merged_global_options[:globaloption1] )
|
110
|
+
assert_equal( 'global option 2', cfg.merged_global_options[:globaloption2] )
|
111
|
+
end
|
112
|
+
|
113
|
+
test 'remote() accessor works.' do
|
114
|
+
cfg = create_configuration
|
115
|
+
assert_equal( 'GitRemoteObject 1', cfg.remote['origin'] )
|
116
|
+
assert_equal( 'GitRemoteObject 1', cfg.merged_remote['origin'] )
|
117
|
+
end
|
118
|
+
|
119
|
+
test 'remote() accessor works with inheritance.' do
|
120
|
+
parent = create_configuration
|
121
|
+
cfg = BuildTool::VCS::GitConfiguration.new
|
122
|
+
cfg.parent = parent
|
123
|
+
cfg.remote['other'] = 'other'
|
124
|
+
assert_nil( cfg.remote['origin'] )
|
125
|
+
assert_equal( 'GitRemoteObject 1', cfg.merged_remote['origin'] )
|
126
|
+
assert_equal( 'other', cfg.merged_remote['other'] )
|
127
|
+
cfg.remote['origin'] = 'test'
|
128
|
+
assert_equal( 'test', cfg.merged_remote['origin'] )
|
129
|
+
assert_equal( 'other', cfg.merged_remote['other'] )
|
130
|
+
end
|
131
|
+
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def create_configuration
|
136
|
+
# Reset global configuration
|
137
|
+
BuildTool::VCS::GitConfiguration.global_config = nil
|
138
|
+
# Create a configuration object
|
139
|
+
cfg = BuildTool::VCS::GitConfiguration.new
|
140
|
+
cfg.track = 'myremote/mybranch'
|
141
|
+
cfg.options = {
|
142
|
+
:option1 => "option 1",
|
143
|
+
:option2 => "option 2" }
|
144
|
+
cfg.remote['origin'] = 'GitRemoteObject 1'
|
145
|
+
cfg.remote['private'] = 'GitRemoteObject 2'
|
146
|
+
cfg
|
147
|
+
end
|
148
|
+
|
149
|
+
def create_global_configuration
|
150
|
+
# Add a global configuration object
|
151
|
+
global = BuildTool::VCS::GitConfiguration.new
|
152
|
+
BuildTool::VCS::GitConfiguration.global_config = global
|
153
|
+
global.options = {
|
154
|
+
:option1 => "option 1(set globally)",
|
155
|
+
:option3 => "option 3(set globally)" }
|
156
|
+
global.global_options = {
|
157
|
+
:globaloption1 => "global option 1",
|
158
|
+
:globaloption2 => "global option 2" }
|
159
|
+
global
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
end
|