test_vpaths.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. --
  2. -- tests/project/test_vpaths.lua
  3. -- Automated test suite for the project support functions.
  4. -- Copyright (c) 2011-2012 Jason Perkins and the Premake project
  5. --
  6. T.project_vpaths = { }
  7. local suite = T.project_vpaths
  8. local project = premake.project
  9. --
  10. -- Setup and teardown
  11. --
  12. local sln
  13. function suite.setup()
  14. sln = test.createsolution()
  15. end
  16. local function run()
  17. premake.bake.buildconfigs()
  18. local prj = premake.solution.getproject(sln, 1)
  19. local cfg = premake.getconfig(prj, "Debug")
  20. return project.getvpath(prj, cfg.files[1])
  21. end
  22. --
  23. -- Test simple replacements
  24. --
  25. function suite.ReturnsOriginalPath_OnNoVpaths()
  26. files { "hello.c" }
  27. test.isequal("hello.c", run())
  28. end
  29. function suite.ReturnsOriginalPath_OnNoMatches()
  30. files { "hello.c" }
  31. vpaths { ["Headers"] = "**.h" }
  32. test.isequal("hello.c", run())
  33. end
  34. function suite.CanStripPaths()
  35. files { "src/myproject/hello.c" }
  36. vpaths { [""] = "src" }
  37. run()
  38. test.isequal("hello.c", run())
  39. end
  40. function suite.CanTrimLeadingPaths()
  41. files { "src/myproject/hello.c" }
  42. vpaths { ["*"] = "src" }
  43. test.isequal("myproject/hello.c", run())
  44. end
  45. function suite.PatternMayIncludeTrailingSlash()
  46. files { "src/myproject/hello.c" }
  47. vpaths { [""] = "src/myproject/" }
  48. test.isequal("hello.c", run())
  49. end
  50. function suite.SimpleReplacementPatterns()
  51. files { "src/myproject/hello.c" }
  52. vpaths { ["sources"] = "src/myproject" }
  53. test.isequal("sources/hello.c", run())
  54. end
  55. function suite.ExactFilenameMatch()
  56. files { "src/hello.c" }
  57. vpaths { ["sources"] = "src/hello.c" }
  58. test.isequal("sources/hello.c", run())
  59. end
  60. --
  61. -- Test wildcard patterns
  62. --
  63. function suite.MatchFilePattern_ToGroup_Flat()
  64. files { "src/myproject/hello.h" }
  65. vpaths { ["Headers"] = "**.h" }
  66. test.isequal("Headers/hello.h", run())
  67. end
  68. function suite.MatchFilePattern_ToNone_Flat()
  69. files { "src/myproject/hello.h" }
  70. vpaths { [""] = "**.h" }
  71. test.isequal("hello.h", run())
  72. end
  73. function suite.MatchFilePattern_ToNestedGroup_Flat()
  74. files { "src/myproject/hello.h" }
  75. vpaths { ["Source/Headers"] = "**.h" }
  76. test.isequal("Source/Headers/hello.h", run())
  77. end
  78. function suite.MatchFilePattern_ToGroup_WithTrailingSlash()
  79. files { "src/myproject/hello.h" }
  80. vpaths { ["Headers/"] = "**.h" }
  81. test.isequal("Headers/hello.h", run())
  82. end
  83. function suite.MatchFilePattern_ToNestedGroup_Flat()
  84. files { "src/myproject/hello.h" }
  85. vpaths { ["Group/Headers"] = "**.h" }
  86. test.isequal("Group/Headers/hello.h", run())
  87. end
  88. function suite.MatchFilePattern_ToGroup_Nested()
  89. files { "src/myproject/hello.h" }
  90. vpaths { ["Headers/*"] = "**.h" }
  91. test.isequal("Headers/src/myproject/hello.h", run())
  92. end
  93. function suite.MatchFilePattern_ToGroup_Nested_OneStar()
  94. files { "src/myproject/hello.h" }
  95. vpaths { ["Headers/*"] = "**.h" }
  96. test.isequal("Headers/src/myproject/hello.h", run())
  97. end
  98. function suite.MatchFilePatternWithPath_ToGroup_Nested()
  99. files { "src/myproject/hello.h" }
  100. vpaths { ["Headers/*"] = "src/**.h" }
  101. test.isequal("Headers/myproject/hello.h", run())
  102. end
  103. function suite.matchBaseFileName_onWildcardExtension()
  104. files { "hello.cpp" }
  105. vpaths { ["Sources"] = "hello.*" }
  106. test.isequal("Sources/hello.cpp", run())
  107. end
  108. --
  109. -- Test with project locations
  110. --
  111. function suite.MatchPath_OnProjectLocationSet()
  112. location "build"
  113. files "src/hello.h"
  114. vpaths { [""] = "src" }
  115. test.isequal("hello.h", run())
  116. end
  117. function suite.MatchFilePattern_OnProjectLocationSet()
  118. location "build"
  119. files "src/hello.h"
  120. vpaths { ["Headers"] = "**.h" }
  121. test.isequal("Headers/hello.h", run())
  122. end
  123. function suite.MatchFilePatternWithPath_OnProjectLocationSet()
  124. location "build"
  125. files "src/hello.h"
  126. vpaths { ["Headers"] = "src/**.h" }
  127. test.isequal("Headers/hello.h", run())
  128. end