test_versions.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. --
  2. -- tests/base/test_versions.lua
  3. -- Verify the version comparisons.
  4. -- Copyright (c) 2015 Jason Perkins and the Premake project
  5. --
  6. local suite = test.declare("premake_versions")
  7. local p = premake
  8. --
  9. -- If only major version is specified, anything after should pass.
  10. --
  11. function suite.pass_majorOnly_sameMajor()
  12. test.istrue(p.checkVersion("1.0.0", "1"))
  13. end
  14. function suite.pass_majorOnly_laterMajor()
  15. test.istrue(p.checkVersion("2.0.0", "1"))
  16. end
  17. function suite.pass_majorOnly_laterMinor()
  18. test.istrue(p.checkVersion("1.1.0", "1"))
  19. end
  20. function suite.pass_majorOnly_laterPatch()
  21. test.istrue(p.checkVersion("1.0.1", "1"))
  22. end
  23. --
  24. -- prereleases should be fail against true release.
  25. --
  26. function suite.fail_majorOnly_alpha()
  27. test.isfalse(p.checkVersion("1.0.0-alpha1", "1"))
  28. end
  29. function suite.fail_majorOnly_dev()
  30. test.isfalse(p.checkVersion("1.0.0-dev", "1"))
  31. end
  32. --
  33. -- ealier versions should be fail against major release.
  34. --
  35. function suite.fail_earlierMajor()
  36. test.isfalse(p.checkVersion("0.9.0", "1"))
  37. end
  38. --
  39. -- If major and minor are specified, anything after should pass
  40. --
  41. function suite.pass_majorMinor_sameMajorMinor()
  42. test.istrue(p.checkVersion("1.1.0", "1.1"))
  43. end
  44. function suite.pass_majorMinor_sameMajorLaterMinor()
  45. test.istrue(p.checkVersion("1.2.0", "1.1"))
  46. end
  47. function suite.pass_majorMinor_sameMajorLaterPath()
  48. test.istrue(p.checkVersion("1.1.1", "1.1"))
  49. end
  50. function suite.pass_majorMinor_laterMajorSameMinor()
  51. test.istrue(p.checkVersion("2.0.0", "1.1"))
  52. end
  53. function suite.pass_majorMinor_laterMajorEarlierMinor()
  54. test.istrue(p.checkVersion("2.0.0", "1.1"))
  55. end
  56. function suite.pass_majorMinor_laterMajorLaterMinor()
  57. test.istrue(p.checkVersion("2.2.0", "1.1"))
  58. end
  59. function suite.fail_majorMinor_sameMajorEarlierMinor()
  60. test.isfalse(p.checkVersion("1.0.0", "1.1"))
  61. end
  62. function suite.fail_majorMinor_earlierMajor()
  63. test.isfalse(p.checkVersion("0.9.0", "1.1"))
  64. end
  65. --
  66. -- Alpha comes before beta comes before dev
  67. --
  68. function suite.pass_alphaBeforeBeta()
  69. test.istrue(p.checkVersion("1.0.0-beta1", "1.0.0-alpha1"))
  70. end
  71. function suite.fail_alphaBeforeBeta()
  72. test.isfalse(p.checkVersion("1.0.0-alpha1", "1.0.0-beta1"))
  73. end
  74. function suite.pass_betaBeforeDev()
  75. test.istrue(p.checkVersion("1.0.0-dev", "1.0.0-beta1"))
  76. end
  77. function suite.fail_betaBeforeDev()
  78. test.isfalse(p.checkVersion("1.0.0-beta1", "1.0.0-dev"))
  79. end
  80. --
  81. -- Check ">=" operator
  82. --
  83. function suite.pass_ge_sameMajorMinorPatch()
  84. test.istrue(p.checkVersion("1.1.0", ">=1.1"))
  85. end
  86. function suite.pass_ge_sameMajorMinorLaterPatch()
  87. test.istrue(p.checkVersion("1.1.1", ">=1.1"))
  88. end
  89. function suite.pass_ge_laterMajorEarlierMinor()
  90. test.istrue(p.checkVersion("2.0.1", ">=1.1"))
  91. end
  92. function suite.pass_ge_sameMajorLaterMinor()
  93. test.istrue(p.checkVersion("1.2.1", ">=1.1"))
  94. end
  95. function suite.fail_ge_earlierMajor()
  96. test.isfalse(p.checkVersion("0.1.1", ">=1.1"))
  97. end
  98. function suite.fail_ge_earlierMinor()
  99. test.isfalse(p.checkVersion("1.0.1", ">=1.1"))
  100. end
  101. --
  102. -- Check ">" operator
  103. --
  104. function suite.pass_gt_sameMajorMinorLaterPatch()
  105. test.istrue(p.checkVersion("1.1.1", ">1.1"))
  106. end
  107. function suite.pass_gt_laterMajor()
  108. test.istrue(p.checkVersion("2.0.1", ">1.1"))
  109. end
  110. function suite.pass_gt_laterMinor()
  111. test.istrue(p.checkVersion("1.2.1", ">1.1"))
  112. end
  113. function suite.fail_gt_sameMajorMinorPatch()
  114. test.isfalse(p.checkVersion("1.1.0", ">1.1"))
  115. end
  116. function suite.fail_gt_earlierMajor()
  117. test.isfalse(p.checkVersion("0.1.1", ">1.1"))
  118. end
  119. function suite.fail_gt_earlierMinor()
  120. test.isfalse(p.checkVersion("1.0.1", ">1.1"))
  121. end
  122. --
  123. -- Check multiple conditions
  124. --
  125. function suite.pass_onMultipleConditions()
  126. test.istrue(p.checkVersion("1.2.0", ">=1.0 <2.0"))
  127. end
  128. function suite.fail_onMultipleConditions()
  129. test.isfalse(p.checkVersion("2.2.0", ">=1.0 <2.0"))
  130. end
  131. --
  132. -- If there is no version information, fails.
  133. --
  134. function suite.fail_onNoVersion()
  135. test.isfalse(p.checkVersion(nil, "1.0"))
  136. end