test_vpaths.lua 3.5 KB

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