vmlib 1.0.1 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ee5054308d7ff971afe60377aff456feb410ccc
4
- data.tar.gz: 6abf38e737a186e617337a812ce0b7795fa13af5
3
+ metadata.gz: f1234c2c56688c3796a8099567295462c049abea
4
+ data.tar.gz: e3fe4d2e0dfff686ecd8d461afff583b2dab1641
5
5
  SHA512:
6
- metadata.gz: f323ee88c8b9679e2503338a936e244fca2db1602e001decf1503a2442b1bda784e40cacc22d225ef6e0595bcd991c7edac0a7c65ea4b6a5598b30768b2193a9
7
- data.tar.gz: 093c81e62e7b55d9e98085957d166eca86dc90654be7cfb8478caefd6634dc86a9648a5fd5723b5e2e731136e9d34a928906ec3c4d4380ac6ba344123e951d94
6
+ metadata.gz: 92e567aed02872b0000f97049a4dae7f10b94d8556eab8ee9ebd47c88661a42199351da72677b936c172e25c8cf747efd1f3cc4712c2f86cd5998066e674037a
7
+ data.tar.gz: 7296242755d93a2cd46f69fa092a8883d548e86258384b7fea0d21b3cdc2162e5f38868ecda3d178ae57260eec2d2b1f4228b6baeb15bd045fabecca7b080bf9
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3
data/README.md CHANGED
@@ -3,7 +3,7 @@ Version Manager Library
3
3
 
4
4
  The Version manager library (VMLib) is a generic library to handle
5
5
  semantic versioning as specified at <http://semver.org>. In addition to
6
- complying with semantic versioning v2.0.0-rc.1, it adds additional API
6
+ complying with semantic versioning v2.0.0, it adds additional API
7
7
  calls to bump the major, minor and patch versions as well as handle
8
8
  distinct types of releases (development, alpha, beta, release candidate,
9
9
  final as well as a custom type)
data/Version CHANGED
@@ -1 +1 @@
1
- vmlib 1.0.1
1
+ vmlib 1.1.0
data/bin/vmlib CHANGED
@@ -90,16 +90,24 @@ module VMLib
90
90
 
91
91
  #########################################################################
92
92
  # Updates all the source files with the bumped version
93
- # Also writes the changes to the git repository
93
+ # Accepts an optional format string. If not specified, uses %M.%m.%p%r%b
94
94
  #########################################################################
95
95
  when 'update' # update
96
- sfile = Source.new
96
+ # Allow the user to specify the format
97
+ foption = ARGV.shift || '"%M.%m.%p%r%b"'
98
+
99
+ sfile = Source.new(foption)
97
100
  sfile.update
101
+
102
+ #########################################################################
103
+ # Writes all local changes to the git repository. SHOULD be preceded
104
+ # immediately by an update command.
105
+ #########################################################################
106
+ when 'commit' # commit
98
107
  version = File.new.read.tag
99
108
 
100
109
  puts "Committing changed files in #{version}"
101
110
  system("git commit -am 'Bumped version to #{version}'")
102
-
103
111
 
104
112
  #########################################################################
105
113
  # Display the version as a format
@@ -136,8 +144,8 @@ module VMLib
136
144
  #if fstr.nil?
137
145
  puts <<EOM
138
146
  #{$0} is a utility to help manage project versions in accordance with
139
- the Semantic Versioning specifications v2.0.0-rc.1. The specifications
140
- can be found at http://semver.org
147
+ the Semantic Versioning specifications v2.0.0. The specifications can
148
+ be found at http://semver.org
141
149
 
142
150
  Usage: #{$0} <command> [arguments]
143
151
 
@@ -165,7 +173,9 @@ Supported commands are:
165
173
 
166
174
  update Updates source files with the (new) version
167
175
  information and also writes the changes to
168
- the git repository.
176
+ the git repository. You may optionally specify
177
+ a format string, failing which it will use the
178
+ default format string of "%M.%m.%p%r%b"
169
179
 
170
180
  format Formats the version information as a string.
171
181
  You can specify an optional format string
data/lib/vmlib/base.rb CHANGED
@@ -208,6 +208,7 @@ module VMLib
208
208
  true
209
209
  end
210
210
 
211
+
211
212
  end
212
213
 
213
214
 
data/lib/vmlib/bump.rb CHANGED
@@ -52,7 +52,7 @@ module VMLib
52
52
  when :rel_type_custom
53
53
  lastfield = @relcustom.pop
54
54
  if lastfield.kind_of? Integer
55
- @relcustom.push (lastfield + 1)
55
+ @relcustom.push lastfield + 1
56
56
  else
57
57
  @relcustom.push lastfield
58
58
  raise Errors::BumpError, "cannot bump a non-numeric prerelease field"
@@ -0,0 +1,57 @@
1
+ ###############################################################################
2
+ # VMLib class attributes
3
+ ###############################################################################
4
+ # Copyright (C) 2013 Nirenjan Krishnan
5
+ # All rights reserved.
6
+ ###############################################################################
7
+
8
+ ;
9
+
10
+ module VMLib
11
+
12
+ # This is the primary version number class for the version manager library
13
+ class Version
14
+
15
+ #==================================================================
16
+ # Compare build operator - this is false by default
17
+ #==================================================================
18
+ @@compare_build = false
19
+
20
+ def self.compare_build= (val) #:nodoc:
21
+ unless val == true or val == false
22
+ raise Errors::ParameterError, "invalid value #{val}"
23
+ end
24
+
25
+ @@compare_build = val
26
+ end
27
+
28
+ # Specify whether to compare build metadata or not between two versions
29
+ def self.compare_build
30
+ @@compare_build
31
+ end
32
+
33
+ #==================================================================
34
+ # Prerelease parser - this is enabled by default
35
+ #==================================================================
36
+ @@enable_prerelease_parser = true
37
+
38
+ def self.enable_prerelease_parser= (val) #:nodoc:
39
+ unless val == true or val == false
40
+ raise Errors::ParameterError, "invalid value #{val}"
41
+ end
42
+
43
+ @@enable_prerelease_parser = val
44
+ end
45
+
46
+ # Specify whether to use the prerelease parser or not. Disabling this
47
+ # will cause an error to be thrown in the following cases:
48
+ # * Calling the bump_release_type functionality
49
+ # * Calling bump_prerelease with a non-numeric identifier at the end
50
+ def self.enable_prerelease_parser
51
+ @@enable_prerelease_parser
52
+ end
53
+
54
+ end
55
+
56
+
57
+ end
data/lib/vmlib/compare.rb CHANGED
@@ -90,13 +90,15 @@ module VMLib
90
90
  cmp = -1 if cmp == 1 and other_pre.length == 0
91
91
  return cmp unless cmp == 0
92
92
 
93
- # Check build arrays
94
- myown_bld = self.build.split('.')
95
- convert_to_integer(myown_bld)
96
- other_bld = other.build.split('.')
97
- convert_to_integer(other_bld)
98
- cmp = compare_arrays(myown_bld, other_bld)
99
- return cmp unless cmp == 0
93
+ # Check build arrays, but only if specified
94
+ # As with the parser, leave identifiers as strings so they can
95
+ # be compared lexically
96
+ if (@@compare_build)
97
+ myown_bld = self.build.split('.')
98
+ other_bld = other.build.split('.')
99
+ cmp = compare_arrays(myown_bld, other_bld)
100
+ return cmp unless cmp == 0
101
+ end
100
102
 
101
103
  return 0
102
104
  end
data/lib/vmlib/parse.rb CHANGED
@@ -103,6 +103,11 @@ module VMLib
103
103
  @reltype = :rel_type_custom
104
104
  end
105
105
 
106
+ # The user may have disabled the prerelease parser
107
+ unless (@@enable_prerelease_parser)
108
+ @reltype = :rel_type_custom
109
+ end
110
+
106
111
  # Done parsing, clear the relcustom array if it's not a custom type
107
112
  @relcustom = [] unless @reltype == :rel_type_custom
108
113
  convert_to_integer(@relcustom)
@@ -130,7 +135,8 @@ module VMLib
130
135
 
131
136
  # Done parsing, clear the array if it's not a custom type
132
137
  @buildcustom = [] unless @buildtype == :bld_type_custom
133
- convert_to_integer(@buildcustom)
138
+ # Converting to integer breaks some of the sample test cases on
139
+ # semver.org. Therefore, we will leave the strings as is.
134
140
  else # if !match
135
141
  # It may be an empty string, so set the buildtype to final in that case
136
142
  if str.empty?
@@ -147,6 +153,8 @@ module VMLib
147
153
  # With the exception of the root parse function
148
154
  public
149
155
 
156
+ # Parse a string containing the project name and version number into
157
+ # its individual components
150
158
  def parse(ver)
151
159
  unless ver.kind_of? String
152
160
  raise Errors::ParameterError, "expected a string to be parsed"
@@ -160,9 +168,10 @@ module VMLib
160
168
  if match
161
169
  @name = match[:name]
162
170
  ver = ver.sub(NAME_REGEX, '')
163
- #else
164
- # Sometimes we may not get a name to be parsed. If that's the case
165
- # then simply ignore it.
171
+ else
172
+ # Sometimes we may not get a name to be parsed. If that's the case
173
+ # then ensure we clear the name field.
174
+ @name = ''
166
175
  end
167
176
 
168
177
  # Match the major, minor and patch versions
data/lib/vmlib/source.rb CHANGED
@@ -13,7 +13,7 @@ module VMLib
13
13
  class Source
14
14
 
15
15
  # Set up the tree to find the root of the source repository
16
- def initialize(dir = nil)
16
+ def initialize(vformat = '"%M.%m.%p%r%b"', dir = nil)
17
17
  # Find the primary version file and get the root path
18
18
  version = File.new.find_file(dir)
19
19
  root = ::File.dirname(version)
@@ -27,7 +27,7 @@ module VMLib
27
27
  verdata = ::File.read(version)
28
28
  v = Version.new
29
29
  v.parse verdata
30
- @verstring = v.format '"%M.%m.%p%r%b"'
30
+ @verstring = v.format vformat
31
31
  end
32
32
 
33
33
  # Update the specified file
data/lib/vmlib/version.rb CHANGED
@@ -7,6 +7,11 @@
7
7
 
8
8
  module VMLib
9
9
 
10
- VERSION = "1.0.1" #:nodoc:
10
+ VERSION = "1.1.0" #:nodoc:
11
11
 
12
+ # This function is used by the gemspec file to generate a
13
+ # gem version number that corresponds to %M.%m.%p format
14
+ def VMLib.gem_version #:nodoc:
15
+ /\d+\.\d+\.\d+/.match(VERSION).to_s
16
+ end
12
17
  end
data/lib/vmlib.rb CHANGED
@@ -5,6 +5,9 @@
5
5
  # All rights reserved.
6
6
  ###############################################################################
7
7
 
8
+ # Class attributes
9
+ require 'vmlib/class'
10
+
8
11
  # Version processing
9
12
  require 'vmlib/base'
10
13
  require 'vmlib/bump'
@@ -104,6 +104,32 @@ module VMLib
104
104
  assert_equal '0.0.0', version.to_s
105
105
  end
106
106
 
107
+
108
+ # Test the build assignment
109
+ def test_build
110
+ version = VMLib::Version.new
111
+ version.build = '1'
112
+ assert_equal '0.0.0-0+1', version.to_s
113
+
114
+ version.prerelease = ''
115
+ assert_equal '0.0.0+1', version.to_s
116
+
117
+ version.build = 'foo.bar.baz'
118
+ assert_equal '0.0.0+foo.bar.baz', version.to_s
119
+
120
+ # Verify that the build identifiers get treated as strings,
121
+ # basically checking that we don't strip leading zeroes in fields
122
+ # with only digits
123
+ version.build = '001'
124
+ assert_equal '0.0.0+001', version.to_s
125
+
126
+ version.build = '20130313144700'
127
+ assert_equal '0.0.0+20130313144700', version.to_s
128
+
129
+ version.build = 'exp.sha.5114f85'
130
+ assert_equal '0.0.0+exp.sha.5114f85', version.to_s
131
+ end
132
+
107
133
  end
108
134
 
109
135
 
@@ -0,0 +1,207 @@
1
+ ###############################################################################
2
+ # VMLib bump test cases
3
+ ###############################################################################
4
+ # Copyright (C) 2013 Nirenjan Krishnan
5
+ # All rights reserved.
6
+ ###############################################################################
7
+
8
+ require 'test/unit'
9
+ require 'vmlib'
10
+
11
+ module VMLib
12
+
13
+ module Tests #:nodoc:
14
+
15
+ class TestBump < ::Test::Unit::TestCase #:nodoc:
16
+
17
+ # Test bumping the patch version
18
+ def test_bump_patch
19
+ version = VMLib::Version.new
20
+ assert_equal '0.0.0-0', version.to_s
21
+
22
+ version.bump_patch
23
+ assert_equal '0.0.1-0', version.to_s
24
+
25
+ version.prerelease = ''
26
+ version.bump_patch
27
+ assert_equal '0.0.2', version.to_s
28
+ end
29
+
30
+
31
+ # Test bumping the minor version
32
+ # Once with a zero patch, and again with a non-zero patch
33
+ def test_bump_minor
34
+ version = VMLib::Version.new
35
+ assert_equal '0.0.0-0', version.to_s
36
+
37
+ version.bump_minor
38
+ assert_equal '0.1.0-0', version.to_s
39
+
40
+ version.patch = 4
41
+ assert_equal '0.1.4-0', version.to_s
42
+
43
+ # Does bumping the minor version reset the patch to zero?
44
+ version.bump_minor
45
+ assert_equal '0.2.0-0', version.to_s
46
+
47
+ # Does bumping the minor version leave the prerelease unaffected?
48
+ version.prerelease = 'rc.0'
49
+ version.bump_minor
50
+ assert_equal '0.3.0-rc.0', version.to_s
51
+ end
52
+
53
+
54
+ # Test bumping the major version
55
+ # Test with zero, and non-zero patch & minor versions
56
+ def test_bump_major
57
+ version = VMLib::Version.new
58
+ version.prerelease = ''
59
+ version.bump_major
60
+ assert_equal '1.0.0', version.to_s
61
+
62
+ version.patch = 1
63
+ assert_equal '1.0.1', version.to_s
64
+
65
+ # Does bumping the major version reset the patch to zero?
66
+ version.bump_major
67
+ assert_equal '2.0.0', version.to_s
68
+
69
+ version.minor = 2
70
+ assert_equal '2.2.0', version.to_s
71
+
72
+ # Does bumping the major version reset the minor version to zero?
73
+ version.bump_major
74
+ assert_equal '3.0.0', version.to_s
75
+
76
+ version.minor = 1
77
+ version.patch = 4
78
+ assert_equal '3.1.4', version.to_s
79
+
80
+ # Does bumping the major version reset minor & patch to zero?
81
+ version.bump_major
82
+ assert_equal '4.0.0', version.to_s
83
+ end
84
+
85
+
86
+ # Test bumping a dev version
87
+ def test_bump_pre_dev
88
+ version = VMLib::Version.new
89
+ version.bump_prerelease
90
+ assert_equal '0.0.0-1', version.to_s
91
+
92
+ version.bump_prerelease
93
+ assert_equal '0.0.0-2', version.to_s
94
+ end
95
+
96
+
97
+ # Test bumping dev to alpha and bumping alpha versions
98
+ def test_bump_pre_alpha
99
+ version = VMLib::Version.new
100
+ # Does type bumping a development version go to alpha?
101
+ version.bump_release_type
102
+ assert_equal '0.0.0-a.1', version.to_s
103
+
104
+ version.bump_prerelease
105
+ assert_equal '0.0.0-a.2', version.to_s
106
+ end
107
+
108
+
109
+ # Test bumping dev to alpha to beta & bumping beta versions
110
+ def test_bump_pre_beta
111
+ version = VMLib::Version.new
112
+ version.bump_release_type
113
+ assert_equal '0.0.0-a.1', version.to_s
114
+
115
+ # Does type bumping an alpha version go to beta?
116
+ version.bump_release_type
117
+ assert_equal '0.0.0-b.1', version.to_s
118
+
119
+ version.bump_prerelease
120
+ assert_equal '0.0.0-b.2', version.to_s
121
+ end
122
+
123
+
124
+ # Test bumping dev to alpha to beta to rc & bumping rc versions
125
+ def test_bump_pre_rc
126
+ version = VMLib::Version.new
127
+ version.bump_release_type
128
+ assert_equal '0.0.0-a.1', version.to_s
129
+
130
+ version.bump_release_type
131
+ assert_equal '0.0.0-b.1', version.to_s
132
+
133
+ # Does type bumping a beta version go to release candidate?
134
+ version.bump_release_type
135
+ assert_equal '0.0.0-rc.1', version.to_s
136
+
137
+ version.bump_prerelease
138
+ assert_equal '0.0.0-rc.2', version.to_s
139
+ end
140
+
141
+
142
+ # Test bumping dev to alpha to beta to rc to final & bumping final
143
+ def test_bump_pre_final
144
+ version = VMLib::Version.new
145
+ version.bump_release_type
146
+ assert_equal '0.0.0-a.1', version.to_s
147
+
148
+ version.bump_release_type
149
+ assert_equal '0.0.0-b.1', version.to_s
150
+
151
+ version.bump_release_type
152
+ assert_equal '0.0.0-rc.1', version.to_s
153
+
154
+ # Does type bumping a release candidate go to final?
155
+ version.bump_release_type
156
+ assert_equal '0.0.0', version.to_s
157
+
158
+ # Bumping type from final raises BumpError
159
+ assert_raise(VMLib::Errors::BumpError) do
160
+ version.bump_release_type
161
+ end
162
+
163
+ # Bumping from final raises BumpError
164
+ assert_raise(VMLib::Errors::BumpError) do
165
+ version.bump_prerelease
166
+ end
167
+ end
168
+
169
+
170
+ # Test bumping a custom type
171
+ def test_bump_pre_custom
172
+ version = VMLib::Version.new
173
+
174
+ # Does bumping a custom prerelease string increment the last field
175
+ # (if numeric)?
176
+ version.prerelease = 'foo.9'
177
+ assert_equal '0.0.0-foo.9', version.to_s
178
+
179
+ version.bump_prerelease
180
+ assert_equal '0.0.0-foo.10', version.to_s
181
+
182
+ version.prerelease = '1.2.3.4.5.6.7.8.9'
183
+ assert_equal '0.0.0-1.2.3.4.5.6.7.8.9', version.to_s
184
+
185
+ version.bump_prerelease
186
+ assert_equal '0.0.0-1.2.3.4.5.6.7.8.10', version.to_s
187
+
188
+ # Error raised when bumping a non-numeric final field
189
+ version.prerelease = 'foo'
190
+ assert_raise(VMLib::Errors::BumpError) do
191
+ version.bump_prerelease
192
+ end
193
+
194
+ version.prerelease = '1.2.3.4.5.foo'
195
+ assert_raise(VMLib::Errors::BumpError) do
196
+ version.bump_prerelease
197
+ end
198
+ end
199
+
200
+
201
+ end
202
+
203
+
204
+ end
205
+
206
+
207
+ end
@@ -0,0 +1,190 @@
1
+ ###############################################################################
2
+ # VMLib version comparision test cases
3
+ ###############################################################################
4
+ # Copyright (C) 2013 Nirenjan Krishnan
5
+ # All rights reserved.
6
+ ###############################################################################
7
+
8
+ require 'test/unit'
9
+ require 'vmlib'
10
+
11
+ module VMLib
12
+
13
+ module Tests #:nodoc:
14
+
15
+ class TestCompare < ::Test::Unit::TestCase #:nodoc:
16
+
17
+ # Test comparing two versions with different major, minor & patch
18
+ def test_compare_regular
19
+ version1 = VMLib::Version.new
20
+ version2 = VMLib::Version.new
21
+
22
+ # Test if having identical version strings is working
23
+ assert_equal 0, version1 <=> version2
24
+
25
+ # Test if having different major versions shows up correctly
26
+ version1.major = 1
27
+ assert_equal 1, version1 <=> version2
28
+
29
+ # Test if having different minor versions shows up correctly
30
+ version2.major = 1
31
+ version2.minor = 1
32
+ assert_equal -1, version1 <=> version2
33
+
34
+ # Test if having different patch versions shows up correctly
35
+ version1.minor = 1
36
+ version2.patch = 10
37
+ assert_equal -1, version1 <=> version2
38
+
39
+ # Test if setting the versions to identical one shows up as equal
40
+ version1.patch = 10
41
+ assert_equal 0, version1 <=> version2
42
+
43
+ # Test using digits of different length in the patch
44
+ version2.patch = 9
45
+ assert_equal 1, version1 <=> version2
46
+ end
47
+
48
+ # Test comparing two versions with different prerelease info
49
+ def test_compare_prerelease
50
+ version1 = VMLib::Version.new
51
+ version2 = VMLib::Version.new
52
+
53
+ # Test that a prerelease sorts lower than non-prerelease version
54
+ version1.prerelease = ''
55
+ assert_equal 1, version1 <=> version2
56
+
57
+ # Test that two dev releases sort in order
58
+ version1.prerelease = '1'
59
+ assert_equal 1, version1 <=> version2
60
+
61
+ # Test that a dev and an alpha sort with dev lower
62
+ version1.bump_release_type
63
+ assert_equal 1, version1 <=> version2
64
+
65
+ # Test that a dev and a beta sort with dev lower
66
+ version1.bump_release_type
67
+ assert_equal 1, version1 <=> version2
68
+
69
+ # Test that a dev and a rc sort with dev lower
70
+ version1.bump_release_type
71
+ assert_equal 1, version1 <=> version2
72
+
73
+ # Test that an alpha and alpha are sorted in order
74
+ version1.prerelease = 'alpha.1'
75
+ version2.prerelease = 'alpha.1'
76
+ assert_equal 0, version1 <=> version2
77
+
78
+ version1.prerelease = 'alpha.2'
79
+ assert_equal 1, version1 <=> version2
80
+
81
+ # Test that an alpha and a beta sort with alpha lower
82
+ version1.bump_release_type
83
+ assert_equal 1, version1 <=> version2
84
+
85
+ # Test that an alpha and a rc sort with alpha lower
86
+ version1.bump_release_type
87
+ assert_equal 1, version1 <=> version2
88
+
89
+ # Test that a beta and beta are sorted in order
90
+ version1.prerelease = 'beta.1'
91
+ version2.prerelease = 'beta.1'
92
+ assert_equal 0, version1 <=> version2
93
+
94
+ version1.prerelease = 'beta.2'
95
+ assert_equal 1, version1 <=> version2
96
+
97
+ # Test that a beta and a rc sort with beta lower
98
+ version1.bump_release_type
99
+ assert_equal 1, version1 <=> version2
100
+
101
+ # Test that a rc and rc are sorted in order
102
+ version1.prerelease = 'rc.1'
103
+ version2.prerelease = 'rc.1'
104
+ assert_equal 0, version1 <=> version2
105
+
106
+ version1.prerelease = 'rc.2'
107
+ assert_equal 1, version1 <=> version2
108
+ end
109
+
110
+
111
+ # Test that a custom prerelease sorts the same way as a defined one
112
+ def test_compare_custom_prerelease
113
+ version1 = VMLib::Version.new
114
+ version2 = VMLib::Version.new
115
+
116
+ version1.prerelease = 'foo.bar.baz'
117
+ version2.prerelease = 'foo.bar.baz'
118
+ assert_equal 0, version1 <=> version2
119
+
120
+ # Test that two alphanumeric prerelease strings get sorted lexically
121
+ version1.prerelease = 'foo.bas.baz'
122
+ assert_equal 1, version1 <=> version2
123
+
124
+ version1.prerelease = 'foo.bars.baz'
125
+ assert_equal 1, version1 <=> version2
126
+
127
+ # Test that numeric identifiers get compared numerically
128
+ version1.prerelease = 'foo.123'
129
+ version2.prerelease = 'foo.21'
130
+ assert_equal 1, version1 <=> version2
131
+
132
+ # Test sample test cases from mojombo/semver#100
133
+ version1.prerelease = 'a.3.b.54'
134
+ version2.prerelease = 'a.2.b.55'
135
+ assert_equal 1, version1 <=> version2
136
+
137
+ version1.prerelease = 'a.b.2'
138
+ version2.prerelease = 'a.1.b'
139
+ assert_equal 1, version1 <=> version2
140
+
141
+ version1.prerelease = 'a.99.c.1'
142
+ version2.prerelease = 'a.1.b.2'
143
+ assert_equal 1, version1 <=> version2
144
+
145
+ version1.prerelease = 'a.b'
146
+ version2.prerelease = 'a.1.b.2'
147
+ assert_equal 1, version1 <=> version2
148
+
149
+ # Test that longer identifiers sort higher than shorter ones
150
+ version1.prerelease = 'a.1.b.2.c'
151
+ assert_equal 1, version1 <=> version2
152
+ end
153
+
154
+
155
+ # Test that build metadata is ignored in sorts unless explicitly enabled
156
+ def test_compare_build
157
+ version1 = VMLib::Version.new
158
+ version2 = VMLib::Version.new
159
+
160
+ version1.build = '5c08ad0'
161
+ version2.build = '44cbb6c'
162
+ assert_equal 0, version1 <=> version2
163
+
164
+ VMLib::Version.compare_build = true
165
+ assert_equal 1, version1 <=> version2
166
+
167
+ # Test that having a build metadata sorts higher than none
168
+ version2.build = ''
169
+ assert_equal 1, version1 <=> version2
170
+
171
+ version2.build = '5c08ad0'
172
+ assert_equal 0, version1 <=> version2
173
+
174
+ # Test that longer build meta data sorts higher than shorter
175
+ version1.build = '5c08ad0.20130618'
176
+ assert_equal 1, version1 <=> version2
177
+
178
+ # Test that numeric identifiers sort lexically
179
+ version2.build = '5c08ad0.102467890'
180
+ assert_equal 1, version1 <=> version2
181
+ end
182
+
183
+
184
+ end
185
+
186
+
187
+ end
188
+
189
+
190
+ end
@@ -0,0 +1,209 @@
1
+ ###############################################################################
2
+ # VMLib version formatting test cases
3
+ ###############################################################################
4
+ # Copyright (C) 2013 Nirenjan Krishnan
5
+ # All rights reserved.
6
+ ###############################################################################
7
+
8
+ require 'test/unit'
9
+ require 'vmlib'
10
+
11
+ module VMLib
12
+
13
+ module Tests #:nodoc:
14
+
15
+ class TestFormat < ::Test::Unit::TestCase #:nodoc:
16
+
17
+
18
+ # Test if printing the name comes out correctly
19
+ def test_format_name
20
+ version = VMLib::Version.new
21
+ # Test if an empty name corresponds to an empty string
22
+ assert_equal '', version.format('%n')
23
+
24
+ # Test if a valid name corresponds to the name plus a space
25
+ version.name = 'foo'
26
+ assert_equal 'foo ', version.format('%n')
27
+ assert_equal 'foo bar', version.format('%nbar')
28
+ assert_equal 'foo bar', version.format('%n bar')
29
+ end
30
+
31
+
32
+ # Test if printing the major version comes out correctly
33
+ def test_format_major
34
+ version = VMLib::Version.new
35
+ assert_equal '0', version.format('%M')
36
+
37
+ version.major = 42
38
+ assert_equal '42', version.format('%M')
39
+ end
40
+
41
+
42
+ # Test if printing the minor version comes out correctly
43
+ def test_format_minor
44
+ version = VMLib::Version.new
45
+ assert_equal '0', version.format('%m')
46
+
47
+ version.minor = 13
48
+ assert_equal '13', version.format('%m')
49
+ end
50
+
51
+
52
+ # Test if printing the patch version comes out correctly
53
+ def test_format_patch
54
+ version = VMLib::Version.new
55
+ assert_equal '0', version.format('%p')
56
+
57
+ version.patch = 16
58
+ assert_equal '16', version.format('%p')
59
+ end
60
+
61
+
62
+ # Test if printing the prerelease version comes out correctly
63
+ def test_format_prerelease
64
+ version = VMLib::Version.new
65
+
66
+ # Test that an empty prerelease corresponds to an empty string
67
+ version.prerelease = ''
68
+ assert_equal '', version.format('%r')
69
+
70
+ # Test that a dev release corresponds to a -# string
71
+ version.prerelease = '0'
72
+ assert_equal '-0', version.format('%r')
73
+ version.prerelease = '1'
74
+ assert_equal '-1', version.format('%r')
75
+
76
+ # Test that an alpha prerelease corresponds to a -a.# string
77
+ version.prerelease = 'alpha.1'
78
+ assert_equal '-a.1', version.format('%r')
79
+ version.prerelease = 'a.2'
80
+ assert_equal '-a.2', version.format('%r')
81
+
82
+ # Test that a beta prerelease corresponds to a -b.# string
83
+ version.prerelease = 'beta.3'
84
+ assert_equal '-b.3', version.format('%r')
85
+ version.prerelease = 'b.4'
86
+ assert_equal '-b.4', version.format('%r')
87
+
88
+ # Test that a rc prerelease corresponds to a -rc.# string
89
+ version.prerelease = 'rc.5'
90
+ assert_equal '-rc.5', version.format('%r')
91
+
92
+ # Test that a custom prerelease prints as entered
93
+ version.prerelease = 'foo.bar.baz'
94
+ assert_equal '-foo.bar.baz', version.format('%r')
95
+ version.prerelease = '1.2.3.4.5.6.7.8.9.0'
96
+ assert_equal '-1.2.3.4.5.6.7.8.9.0', version.format('%r')
97
+
98
+ # Verify that numeric fields are stripped of leading zeroes
99
+ version.prerelease = '1.2.3.4.5.6.7.8.9.09'
100
+ assert_equal '-1.2.3.4.5.6.7.8.9.9', version.format('%r')
101
+
102
+ end
103
+
104
+
105
+ # Test if printing the prerelease version comes out correctly
106
+ def test_format_build
107
+ version = VMLib::Version.new
108
+
109
+ # Test that an emtpy build corresponds to an empty string
110
+ version.build = ''
111
+ assert_equal '', version.format('%b')
112
+
113
+ # Test that a custom build prints exactly as entered
114
+ version.build = '001'
115
+ assert_equal '+001', version.format('%b')
116
+
117
+ version.build = '20130313144700'
118
+ assert_equal '+20130313144700', version.format('%b')
119
+
120
+ version.build = 'exp.sha.5114f85'
121
+ assert_equal '+exp.sha.5114f85', version.format('%b')
122
+ end
123
+
124
+
125
+ # Test if the tag format comes out as expected
126
+ def test_format_tag
127
+ version = VMLib::Version.new 'foo', 1, 2, 3, 'rc.1', 'sha.5114f85'
128
+
129
+ # Make sure all fields are included in the tag
130
+ assert_equal 'v1.2.3-rc.1+sha.5114f85', version.tag
131
+
132
+ # Changing the build should reflect in the tag
133
+ version.build = 'sha.0012312'
134
+ assert_equal 'v1.2.3-rc.1+sha.0012312', version.tag
135
+
136
+ # Removing the build should reflect in the tag
137
+ version.build = ''
138
+ assert_equal 'v1.2.3-rc.1', version.tag
139
+
140
+ # Changing the prerelease should reflect in the tag
141
+ version.prerelease = 'alpha.02'
142
+ assert_equal 'v1.2.3-a.2', version.tag
143
+
144
+ # Removing the prerelease should reflect in the tag
145
+ version.prerelease = ''
146
+ assert_equal 'v1.2.3', version.tag
147
+
148
+ # Having a build metadata and no prerelease should reflect in the tag
149
+ version.build = 'sha.12ab32d'
150
+ assert_equal 'v1.2.3+sha.12ab32d', version.tag
151
+ end
152
+
153
+
154
+ # Test if the to_s function works as expected
155
+ def test_format_to_s
156
+ version = VMLib::Version.new 'foo', 1, 2, 3, 'rc.1', 'sha.5114f85'
157
+
158
+ # Make sure all fields are included in the to_s
159
+ assert_equal 'foo 1.2.3-rc.1+sha.5114f85', version.to_s
160
+
161
+ # Changing the name should reflect in the to_s
162
+ version.name = 'bar'
163
+ assert_equal 'bar 1.2.3-rc.1+sha.5114f85', version.to_s
164
+
165
+ # Changing the major number should reflect in the to_s
166
+ version.major = 4
167
+ assert_equal 'bar 4.2.3-rc.1+sha.5114f85', version.to_s
168
+
169
+ # Changing the minor number should reflect in the to_s
170
+ version.minor = 5
171
+ assert_equal 'bar 4.5.3-rc.1+sha.5114f85', version.to_s
172
+
173
+ # Changing the patch number should reflect in the to_s
174
+ version.patch = 6
175
+ assert_equal 'bar 4.5.6-rc.1+sha.5114f85', version.to_s
176
+
177
+ version.major = 1
178
+ version.minor = 2
179
+ version.patch = 3
180
+
181
+ # Changing the build should reflect in the to_s
182
+ version.build = 'sha.0012312'
183
+ assert_equal 'bar 1.2.3-rc.1+sha.0012312', version.to_s
184
+
185
+ # Removing the build should reflect in the to_s
186
+ version.build = ''
187
+ assert_equal 'bar 1.2.3-rc.1', version.to_s
188
+
189
+ # Changing the prerelease should reflect in the to_s
190
+ version.prerelease = 'alpha.02'
191
+ assert_equal 'bar 1.2.3-a.2', version.to_s
192
+
193
+ # Removing the prerelease should reflect in the to_s
194
+ version.prerelease = ''
195
+ assert_equal 'bar 1.2.3', version.to_s
196
+
197
+ # Having a build metadata and no prerelease should reflect in the to_s
198
+ version.build = 'sha.12ab32d'
199
+ assert_equal 'bar 1.2.3+sha.12ab32d', version.to_s
200
+ end
201
+
202
+
203
+ end
204
+
205
+
206
+ end
207
+
208
+
209
+ end
@@ -0,0 +1,207 @@
1
+ ###############################################################################
2
+ # VMLib version parsing test cases
3
+ ###############################################################################
4
+ # Copyright (C) 2013 Nirenjan Krishnan
5
+ # All rights reserved.
6
+ ###############################################################################
7
+
8
+ require 'test/unit'
9
+ require 'vmlib'
10
+
11
+ module VMLib
12
+
13
+ module Tests #:nodoc:
14
+
15
+ class TestVersionParse < ::Test::Unit::TestCase #:nodoc:
16
+
17
+
18
+ # Test parsing individual components
19
+ def test_version_parse
20
+ v = VMLib::Version.new
21
+
22
+ # Test parsing the version with name and prerelease
23
+ v.parse 'vmlib v1.1.0-2'
24
+
25
+ assert_equal 'vmlib', v.name
26
+ assert_equal 1, v.major
27
+ assert_equal 1, v.minor
28
+ assert_equal 0, v.patch
29
+ assert_equal '-2', v.prerelease
30
+ assert_equal '', v.build
31
+
32
+ # Test parsing a version without the name
33
+ v.parse 'v1.1.0-2'
34
+
35
+ assert_equal '', v.name
36
+ assert_equal 1, v.major
37
+ assert_equal 1, v.minor
38
+ assert_equal 0, v.patch
39
+ assert_equal '-2', v.prerelease
40
+ assert_equal '', v.build
41
+
42
+ # Test parsing a version with the format as name version X.Y.Z
43
+ v.parse 'vmlib version 1.1.0-2'
44
+
45
+ assert_equal 'vmlib', v.name
46
+ assert_equal 1, v.major
47
+ assert_equal 1, v.minor
48
+ assert_equal 0, v.patch
49
+ assert_equal '-2', v.prerelease
50
+ assert_equal '', v.build
51
+
52
+ # Test parsing a version with the format as name X.Y.Z
53
+ v.parse 'vmlib 1.1.0-2'
54
+
55
+ assert_equal 'vmlib', v.name
56
+ assert_equal 1, v.major
57
+ assert_equal 1, v.minor
58
+ assert_equal 0, v.patch
59
+ assert_equal '-2', v.prerelease
60
+ assert_equal '', v.build
61
+
62
+ # Right now, vmlib does not support having the format
63
+ # version X.Y.Z, i.e., no name, but the string 'version'
64
+ # followed by the version number. If you need to use the
65
+ # 'version' string format, then you must have a program
66
+ # name, otherwise, it will treat the program name as 'version'
67
+ end
68
+
69
+ # Check parsing of strings with various prerelease combinations
70
+ def test_parse_pre
71
+ v = VMLib::Version.new
72
+
73
+ # Default case - prerelease parser enabled
74
+ v.parse 'v1.1.0-2'
75
+ assert_equal '', v.name
76
+ assert_equal 1, v.major
77
+ assert_equal 1, v.minor
78
+ assert_equal 0, v.patch
79
+ assert_equal '-2', v.prerelease
80
+ assert_equal '', v.build
81
+
82
+ # Check alpha case
83
+ v.parse 'v1.1.0-a.2'
84
+ assert_equal '', v.name
85
+ assert_equal 1, v.major
86
+ assert_equal 1, v.minor
87
+ assert_equal 0, v.patch
88
+ assert_equal '-a.2', v.prerelease
89
+ assert_equal '', v.build
90
+
91
+ v.parse 'v1.1.0-alpha.2'
92
+ assert_equal '', v.name
93
+ assert_equal 1, v.major
94
+ assert_equal 1, v.minor
95
+ assert_equal 0, v.patch
96
+ assert_equal '-a.2', v.prerelease
97
+ assert_equal '', v.build
98
+
99
+ # Check beta case
100
+ v.parse 'v1.1.0-b.2'
101
+ assert_equal '', v.name
102
+ assert_equal 1, v.major
103
+ assert_equal 1, v.minor
104
+ assert_equal 0, v.patch
105
+ assert_equal '-b.2', v.prerelease
106
+ assert_equal '', v.build
107
+
108
+ v.parse 'v1.1.0-beta.2'
109
+ assert_equal '', v.name
110
+ assert_equal 1, v.major
111
+ assert_equal 1, v.minor
112
+ assert_equal 0, v.patch
113
+ assert_equal '-b.2', v.prerelease
114
+ assert_equal '', v.build
115
+
116
+ # Check rc case
117
+ v.parse 'v1.1.0-rc.2'
118
+ assert_equal '', v.name
119
+ assert_equal 1, v.major
120
+ assert_equal 1, v.minor
121
+ assert_equal 0, v.patch
122
+ assert_equal '-rc.2', v.prerelease
123
+ assert_equal '', v.build
124
+
125
+ # Check final case
126
+ v.parse 'v1.1.0'
127
+ assert_equal '', v.name
128
+ assert_equal 1, v.major
129
+ assert_equal 1, v.minor
130
+ assert_equal 0, v.patch
131
+ assert_equal '', v.prerelease
132
+ assert_equal '', v.build
133
+
134
+ # Check custom case
135
+ v.parse 'v1.1.0-alpha.1a'
136
+ assert_equal '', v.name
137
+ assert_equal 1, v.major
138
+ assert_equal 1, v.minor
139
+ assert_equal 0, v.patch
140
+ assert_equal '-alpha.1a', v.prerelease
141
+ assert_equal '', v.build
142
+
143
+ # Check with prerelease parser disabled
144
+ # This mainly addresses the alpha and beta cases, since it reduces
145
+ # the output to a.X and b.Y for alpha.X and beta.Y respectively
146
+ VMLib::Version.enable_prerelease_parser = false
147
+ # Check alpha case
148
+ v.parse 'v1.1.0-alpha.2'
149
+ assert_equal '-alpha.2', v.prerelease
150
+
151
+ # Check beta case
152
+ v.parse 'v1.1.0-beta.2'
153
+ assert_equal '-beta.2', v.prerelease
154
+
155
+ # Re-enable the prerelease parser and check if it works as expected
156
+ VMLib::Version.enable_prerelease_parser = true
157
+ # Check alpha case
158
+ v.parse 'v1.1.0-alpha.2'
159
+ assert_equal '-a.2', v.prerelease
160
+
161
+ # Check beta case
162
+ v.parse 'v1.1.0-beta.2'
163
+ assert_equal '-b.2', v.prerelease
164
+ end
165
+
166
+ # Test that the build combinations are stored as entered
167
+ def test_parse_build
168
+ v = VMLib::Version.new
169
+
170
+ v.parse 'vmlib v1.2.0+20130628.0354.gef3c66c'
171
+ assert_equal 'vmlib', v.name
172
+ assert_equal 1, v.major
173
+ assert_equal 2, v.minor
174
+ assert_equal 0, v.patch
175
+ assert_equal '', v.prerelease
176
+ assert_equal '+20130628.0354.gef3c66c', v.build
177
+ end
178
+
179
+ # Test that you can store any combination of pre and build, and
180
+ # it works as expected
181
+ def test_parse_pre_build_combo
182
+ v = VMLib::Version.new
183
+
184
+ v.parse 'vmlib version 1.1.0-3+20130628.0354.gef3c66c'
185
+ assert_equal 'vmlib', v.name
186
+ assert_equal 1, v.major
187
+ assert_equal 1, v.minor
188
+ assert_equal 0, v.patch
189
+ assert_equal '-3', v.prerelease
190
+ assert_equal '+20130628.0354.gef3c66c', v.build
191
+
192
+ v.parse 'vmlib version 1.1.0+20130628.0354.gef3c66c-3'
193
+ assert_equal 'vmlib', v.name
194
+ assert_equal 1, v.major
195
+ assert_equal 1, v.minor
196
+ assert_equal 0, v.patch
197
+ assert_equal '', v.prerelease
198
+ assert_equal '+20130628.0354.gef3c66c-3', v.build
199
+ end
200
+
201
+ end
202
+
203
+
204
+ end
205
+
206
+
207
+ end
data/vmlib.gemspec CHANGED
@@ -5,7 +5,7 @@ require 'vmlib/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'vmlib'
8
- s.version = VMLib::VERSION
8
+ s.version = VMLib::gem_version
9
9
  s.date = '2013-03-12'
10
10
  s.summary = "Version Manager Library"
11
11
  s.description = "A gem to handle software versions"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vmlib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nirenjan Krishnan
@@ -45,6 +45,7 @@ executables:
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - .ruby-version
48
49
  - Gemfile
49
50
  - README.md
50
51
  - Rakefile
@@ -53,6 +54,7 @@ files:
53
54
  - lib/vmlib.rb
54
55
  - lib/vmlib/base.rb
55
56
  - lib/vmlib/bump.rb
57
+ - lib/vmlib/class.rb
56
58
  - lib/vmlib/compare.rb
57
59
  - lib/vmlib/errors.rb
58
60
  - lib/vmlib/file.rb
@@ -62,6 +64,10 @@ files:
62
64
  - lib/vmlib/source.rb
63
65
  - lib/vmlib/version.rb
64
66
  - test/test_version_basic.rb
67
+ - test/test_version_bump.rb
68
+ - test/test_version_compare.rb
69
+ - test/test_version_format.rb
70
+ - test/test_version_parse.rb
65
71
  - vmlib.gemspec
66
72
  homepage: http://rubygems.org/gems/vmlib
67
73
  licenses:
@@ -89,3 +95,7 @@ specification_version: 4
89
95
  summary: Version Manager Library
90
96
  test_files:
91
97
  - test/test_version_basic.rb
98
+ - test/test_version_bump.rb
99
+ - test/test_version_compare.rb
100
+ - test/test_version_format.rb
101
+ - test/test_version_parse.rb