test_validation.lua 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. --
  2. -- tests/base/test_validation.lua
  3. -- Verify the project information sanity checking.
  4. -- Copyright (c) 2013-20124 Jason Perkins and the Premake project
  5. --
  6. local suite = test.declare("premake_validation")
  7. local p = premake
  8. --
  9. -- Setup
  10. --
  11. local function validate()
  12. return pcall(function() p.container.validate(p.api.rootContainer()) end)
  13. end
  14. --
  15. -- Validate should pass if the minimum requirements are met.
  16. --
  17. function suite.passes_onSane()
  18. workspace("MyWorkspace")
  19. configurations { "Debug", "Release" }
  20. project "MyProject"
  21. kind "ConsoleApp"
  22. language "C++"
  23. test.istrue(validate())
  24. end
  25. --
  26. -- Fail if no configurations are present on the workspace.
  27. --
  28. function suite.fails_onNoWorkspaceConfigs()
  29. workspace "MyWorkspace"
  30. project "MyProject"
  31. kind "ConsoleApp"
  32. language "C++"
  33. test.isfalse(validate())
  34. end
  35. --
  36. -- Fail on duplicate project UUIDs.
  37. --
  38. function suite.fails_onDuplicateProjectIDs()
  39. workspace "MyWorkspace"
  40. configurations { "Debug", "Release" }
  41. kind "ConsoleApp"
  42. language "C++"
  43. project "MyProject1"
  44. uuid "D4110D7D-FB18-4A1C-A75B-CA432F4FE770"
  45. project "MyProject2"
  46. uuid "D4110D7D-FB18-4A1C-A75B-CA432F4FE770"
  47. test.isfalse(validate())
  48. end
  49. --
  50. -- Fail if no kind is set on the configuration.
  51. --
  52. function suite.fails_onNoConfigKind()
  53. workspace "MyWorkspace"
  54. configurations { "Debug", "Release" }
  55. project "MyProject"
  56. language "C++"
  57. test.isfalse(validate())
  58. end
  59. --
  60. -- Warn if a configuration value is set in the wrong scope.
  61. --
  62. function suite.warns_onWorkspaceStringField_inConfig()
  63. workspace "MyWorkspace"
  64. configurations { "Debug", "Release" }
  65. filter "Debug"
  66. startproject "MyProject"
  67. project "MyProject"
  68. kind "ConsoleApp"
  69. language "C++"
  70. validate()
  71. test.stderr("'startproject' on config")
  72. end
  73. function suite.warns_onProjectStringField_inConfig()
  74. workspace "MyWorkspace"
  75. configurations { "Debug", "Release" }
  76. project "MyProject"
  77. kind "ConsoleApp"
  78. language "C++"
  79. filter "Debug"
  80. location "MyProject"
  81. validate()
  82. test.stderr("'location' on config")
  83. end
  84. function suite.warns_onProjectListField_inConfig()
  85. workspace "MyWorkspace"
  86. configurations { "Debug", "Release" }
  87. project "MyProject"
  88. kind "ConsoleApp"
  89. language "C++"
  90. filter "Debug"
  91. configurations "Deployment"
  92. validate()
  93. test.stderr("'configurations' on config")
  94. end
  95. --
  96. -- If a rule is specified for inclusion, it must have been defined.
  97. --
  98. function suite.fails_onNoSuchRule()
  99. workspace "MyWorkspace"
  100. configurations { "Debug", "Release" }
  101. project "MyProject"
  102. rules { "NoSuchRule" }
  103. test.isfalse(validate())
  104. end