2017-04-15 12:45:56 +00:00
|
|
|
describe("Version module", function()
|
|
|
|
local Version
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
Version = require("version")
|
|
|
|
end)
|
|
|
|
it("should get current revision", function()
|
2017-04-22 08:09:07 +00:00
|
|
|
local rev = Version:getCurrentRevision()
|
|
|
|
local year, month, revision = rev:match("v(%d%d%d%d)%.(%d%d)-?(%d*)")
|
2018-07-03 21:16:45 +00:00
|
|
|
local commit = rev:match("-%d*-g(%x*)[%d_%-]*")
|
2017-04-22 08:09:07 +00:00
|
|
|
assert.is_truthy(year)
|
|
|
|
assert.is_truthy(month)
|
|
|
|
assert.is_truthy(revision)
|
|
|
|
assert.is_truthy(commit)
|
2018-07-03 21:16:45 +00:00
|
|
|
assert.is_true(4 == year:len())
|
2017-04-22 08:09:07 +00:00
|
|
|
assert.is_true(2 == month:len())
|
|
|
|
assert.is_true(1 <= revision:len())
|
2018-07-03 21:16:45 +00:00
|
|
|
assert.is_true(7 <= commit:len())
|
2017-04-15 12:45:56 +00:00
|
|
|
end)
|
|
|
|
it("should get normalized current version", function()
|
2018-07-03 21:16:45 +00:00
|
|
|
assert.is_true(10 == tostring(Version:getNormalizedCurrentVersion()):len())
|
2017-04-15 12:45:56 +00:00
|
|
|
end)
|
|
|
|
it("should get normalized version", function()
|
|
|
|
local rev = "v2015.11-982-g704d4238"
|
|
|
|
local version, commit = Version:getNormalizedVersion(rev)
|
2018-07-03 21:16:45 +00:00
|
|
|
local expected_version = 2015110982
|
2017-04-15 12:45:56 +00:00
|
|
|
local expected_commit = "704d4238"
|
|
|
|
assert.are.same(expected_version, version)
|
|
|
|
assert.are.same(expected_commit, commit)
|
|
|
|
end)
|
2018-07-03 21:16:45 +00:00
|
|
|
it("should also get normalized version", function()
|
|
|
|
local rev = "v2015.11-1755-gecd7b5b_2018-07-02"
|
|
|
|
local version, commit = Version:getNormalizedVersion(rev)
|
|
|
|
local expected_version = 2015111755
|
|
|
|
local expected_commit = "ecd7b5b"
|
|
|
|
assert.are.same(expected_version, version)
|
|
|
|
assert.are.same(expected_commit, commit)
|
|
|
|
end)
|
2017-04-15 12:45:56 +00:00
|
|
|
it("should fail gracefully", function()
|
|
|
|
local version, commit = Version:getNormalizedVersion()
|
|
|
|
local expected_version = nil
|
|
|
|
local expected_commit = nil
|
|
|
|
assert.are.same(expected_version, version)
|
|
|
|
assert.are.same(expected_commit, commit)
|
|
|
|
end)
|
|
|
|
end)
|