test_sources.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. --
  2. -- tests/project/test_sources.lua
  3. -- Automated test suite for the source tree, including tokens and wildcards.
  4. -- Copyright (c) 2011-2013 Jason Perkins and the Premake project
  5. --
  6. local p = premake
  7. local suite = test.declare("project_sources")
  8. local project = p.project
  9. --
  10. -- Setup and teardown
  11. --
  12. local wks, prj
  13. local cwd = os.getcwd()
  14. local oldcwd
  15. function suite.setup()
  16. wks, prj = test.createWorkspace()
  17. -- We change the directory to get nice relative paths
  18. oldcwd = os.getcwd()
  19. os.chdir(cwd)
  20. -- Create a token to be used in search paths
  21. p.api.register { name = "mytoken", kind = "string", scope = "config" }
  22. mytoken "test"
  23. end
  24. function suite.teardown()
  25. mytoken = nil
  26. os.chdir(oldcwd)
  27. end
  28. local function run()
  29. local cfg = test.getconfig(prj, "Debug")
  30. local files = {}
  31. for _, file in ipairs(cfg.files) do
  32. table.insert(files, path.getrelative(cwd, file))
  33. end
  34. return files
  35. end
  36. --
  37. -- Test single file
  38. --
  39. function suite.SingleFile()
  40. files { "test_sources.lua" }
  41. test.isequal({"test_sources.lua"}, run())
  42. end
  43. --
  44. -- Test tokens
  45. --
  46. function suite.SingleFileWithToken()
  47. files { "%{cfg.mytoken}_sources.lua" }
  48. test.isequal({"test_sources.lua"}, run())
  49. end
  50. --
  51. -- Test wildcards
  52. --
  53. function suite.FilesWithWildcard()
  54. files { "test_*.lua" }
  55. test.contains("test_sources.lua", run())
  56. end
  57. function suite.FilesWithRecursiveWildcard()
  58. files { "../**_sources.lua" }
  59. test.contains("test_sources.lua", run())
  60. end
  61. --
  62. -- Test wildcards and tokens combined
  63. --
  64. function suite.FilesWithWildcardAndToken()
  65. files { "%{cfg.mytoken}_*.lua" }
  66. test.contains("test_sources.lua", run())
  67. end
  68. function suite.FilesWithRecursiveWildcardAndToken()
  69. files { "../**/%{cfg.mytoken}_sources.lua" }
  70. test.contains("test_sources.lua", run())
  71. end