test_rule.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. --
  2. -- tests/base/test_rule.lua
  3. -- Automated test suite for custom rule.
  4. -- Copyright (c) 2008-2021 Jason Perkins and the Premake project
  5. --
  6. local suite = test.declare("rule")
  7. local p = premake
  8. function suite.setup()
  9. rule "TestRule"
  10. display "Test Rule"
  11. fileextension ".rule"
  12. propertydefinition {
  13. name = "TestPropertyFalse",
  14. kind = "boolean",
  15. value = false,
  16. switch = "-dummy"
  17. }
  18. propertydefinition {
  19. name = "TestPropertyTrue",
  20. kind = "boolean",
  21. value = false,
  22. switch = "-p"
  23. }
  24. propertydefinition {
  25. name = "TestListProperty",
  26. kind = "list"
  27. }
  28. propertydefinition {
  29. name = "TestListPropertyWithSwitch",
  30. kind = "list",
  31. switch = "-S"
  32. }
  33. propertydefinition {
  34. name = "TestListPropertySeparator",
  35. kind = "list",
  36. separator = ","
  37. }
  38. propertydefinition {
  39. name = "TestListPropertySeparatorWithSwitch",
  40. kind = "list",
  41. separator = ",",
  42. switch = "-O"
  43. }
  44. propertydefinition {
  45. name = "TestEnumProperty",
  46. values = { [0] = "V0", [1] = "V1"},
  47. switch = { [0] = "S0", [1] = "S1"},
  48. value = 0
  49. }
  50. end
  51. --
  52. -- rule tests
  53. --
  54. function suite.prepareEnvironment()
  55. local rule = premake.global.getRule("TestRule")
  56. local environ = {}
  57. local cfg = {
  58. ["_rule_TestRule_TestPropertyFalse"] = false,
  59. ["_rule_TestRule_TestPropertyTrue"] = true,
  60. ["_rule_TestRule_TestListProperty"] = {"a", "b"},
  61. ["_rule_TestRule_TestListPropertyWithSwitch"] = {"c", "d"},
  62. ["_rule_TestRule_TestListPropertySeparator"] = {"e", "f"},
  63. ["_rule_TestRule_TestListPropertySeparatorWithSwitch"] = {"1", "2"},
  64. ["_rule_TestRule_TestEnumProperty"] = 'V1'
  65. }
  66. p.rule.prepareEnvironment(rule, environ, cfg)
  67. test.isequal(nil, environ["TestPropertyFalse"])
  68. test.isequal("-p", environ["TestPropertyTrue"])
  69. test.isequal("a b", environ["TestListProperty"])
  70. test.isequal("-Sc -Sd", environ["TestListPropertyWithSwitch"])
  71. test.isequal("e,f", environ["TestListPropertySeparator"])
  72. test.isequal("-O1,2", environ["TestListPropertySeparatorWithSwitch"])
  73. test.isequal("S1", environ["TestEnumProperty"])
  74. end