test_getconfig.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --
  2. -- tests/project/test_getconfig.lua
  3. -- Test the project object configuration accessor.
  4. -- Copyright (c) 2011-2014 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("project_getconfig")
  8. --
  9. -- Setup and teardown
  10. --
  11. local wks, prj, cfg
  12. function suite.setup()
  13. wks = workspace("MyWorkspace")
  14. configurations { "Debug", "Release" }
  15. end
  16. local function prepare(buildcfg, platform)
  17. prj = wks.projects[1]
  18. cfg = test.getconfig(prj, buildcfg or "Debug", platform)
  19. end
  20. --
  21. -- If the target system is not specified, the current operating environment
  22. -- should be used as the default.
  23. --
  24. function suite.usesCurrentOS_onNoSystemSpecified()
  25. _TARGET_OS = "linux"
  26. project ("MyProject")
  27. filter { "system:linux" }
  28. defines { "correct" }
  29. prepare()
  30. test.isequal("correct", cfg.defines[1])
  31. end
  32. --
  33. -- If the current action specifies a target operating environment (i.e.
  34. -- Visual Studio targets Windows), that should override the current
  35. -- operating environment.
  36. --
  37. function suite.actionOverridesOS()
  38. _TARGET_OS = "linux"
  39. p.action.set("vs2005")
  40. project ("MyProject")
  41. filter { "system:windows" }
  42. defines { "correct" }
  43. prepare()
  44. test.isequal("correct", cfg.defines[1])
  45. end
  46. --
  47. -- If a target system is specified in a configuration, it should override
  48. -- the current operating environment, as well as the tool's target OS.
  49. --
  50. function suite.usesCfgSystem()
  51. _TARGET_OS = "linux"
  52. p.action.set("vs2005")
  53. project ("MyProject")
  54. system "macosx"
  55. filter { "system:macosx" }
  56. defines { "correct" }
  57. prepare()
  58. test.isequal("correct", cfg.defines[1])
  59. end
  60. --
  61. -- The current action should be taken into account.
  62. --
  63. function suite.appliesActionToFilters()
  64. p.action.set("vs2005")
  65. project ("MyProject")
  66. filter { "action:vs2005" }
  67. defines { "correct" }
  68. prepare()
  69. test.isequal("correct", cfg.defines[1])
  70. end
  71. --
  72. -- If the platform matches an architecture identifier, and none was set,
  73. -- the configuration's architecture should be set to match.
  74. --
  75. function suite.setsArchitecture_onMatchingPlatform()
  76. platforms { "x86", "x86_64" }
  77. project ("MyProject")
  78. prepare("Debug", "x86")
  79. test.isequal("x86", cfg.architecture)
  80. end
  81. --
  82. -- If the platform matches an architecture, it should not modify any
  83. -- currently set value.
  84. --
  85. function suite.doesNotOverride_onMatchingPlatform()
  86. platforms { "x86", "x64" }
  87. project ("MyProject")
  88. architecture "x86_64"
  89. prepare("Debug", "x86")
  90. test.isequal("x86_64", cfg.architecture)
  91. end