test_filename.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. --
  2. -- tests/base/test_filename.lua
  3. -- Verify generation of project/workspace/rule filenames.
  4. -- Copyright (c) 2008-2014 Jason Perkins and the Premake project
  5. --
  6. local suite = test.declare("project_filename")
  7. local p = premake
  8. --
  9. -- Setup
  10. --
  11. local wks
  12. function suite.setup()
  13. wks = test.createWorkspace()
  14. end
  15. local function prepare()
  16. prj = test.getproject(wks, 1)
  17. end
  18. --
  19. -- Should return name as an absolute path.
  20. --
  21. function suite.isAbsolutePath()
  22. prepare()
  23. test.isequal(os.getcwd(), path.getdirectory(p.filename(prj)))
  24. end
  25. --
  26. -- Should use the project name, if no filename was specified.
  27. --
  28. function suite.isProjectName_onNoFilename()
  29. prepare()
  30. test.isequal("MyProject", path.getname(p.filename(prj)))
  31. end
  32. --
  33. -- Should use filename, if set via API.
  34. --
  35. function suite.doesUseFilename()
  36. filename "Howdy"
  37. prepare()
  38. test.isequal("Howdy", path.getname(p.filename(prj)))
  39. end
  40. --
  41. -- Appends file extension, if supplied.
  42. --
  43. function suite.doesUseExtension()
  44. prepare()
  45. test.isequal(".xc", path.getextension(p.filename(prj, ".xc")))
  46. end
  47. --
  48. -- Should also work with workspaces.
  49. --
  50. function suite.worksWithWorkspace()
  51. prepare()
  52. test.isequal("MyWorkspace", path.getname(p.filename(wks)))
  53. end
  54. --
  55. -- Value should not propagate down to projects.
  56. --
  57. function suite.doesNotPropagate()
  58. workspace ("MyWorkspace")
  59. filename ("Howdy")
  60. prepare()
  61. test.isequal("MyProject", path.getname(p.filename(prj)))
  62. end
  63. --
  64. -- If extension is provided without a leading dot, it should override any
  65. -- project filename.
  66. --
  67. function suite.canOverrideFilename()
  68. prepare()
  69. test.isequal("Makefile", path.getname(p.filename(prj, "Makefile")))
  70. end