test_os.lua 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. --
  2. -- tests/base/test_os.lua
  3. -- Automated test suite for the new OS functions.
  4. -- Copyright (c) 2008-2011 Jason Perkins and the Premake project
  5. --
  6. T.os = { }
  7. local suite = T.os
  8. --
  9. -- os.findlib() tests
  10. --
  11. function suite.findlib_FindSystemLib()
  12. if os.is("windows") then
  13. test.istrue(os.findlib("user32"))
  14. else
  15. test.istrue(os.findlib("m"))
  16. end
  17. end
  18. function suite.findlib_FailsOnBadLibName()
  19. test.isfalse(os.findlib("NoSuchLibraryAsThisOneHere"))
  20. end
  21. --
  22. -- os.isfile() tests
  23. --
  24. function suite.isfile_ReturnsTrue_OnExistingFile()
  25. test.istrue(os.isfile("premake4.lua"))
  26. end
  27. function suite.isfile_ReturnsFalse_OnNonexistantFile()
  28. test.isfalse(os.isfile("no_such_file.lua"))
  29. end
  30. --
  31. -- os.matchfiles() tests
  32. --
  33. function suite.matchfiles_OnNonRecursive()
  34. local result = os.matchfiles("*.lua")
  35. test.istrue(table.contains(result, "testfx.lua"))
  36. test.isfalse(table.contains(result, "folder/ok.lua"))
  37. end
  38. function suite.matchfiles_Recursive()
  39. local result = os.matchfiles("**.lua")
  40. test.istrue(table.contains(result, "folder/ok.lua"))
  41. end
  42. function suite.matchfiles_SkipsDotDirs_OnRecursive()
  43. local result = os.matchfiles("**.lua")
  44. test.isfalse(table.contains(result, ".svn/text-base/testfx.lua.svn-base"))
  45. end
  46. function suite.matchfiles_OnSubfolderMatch()
  47. local result = os.matchfiles("**/xcode/*")
  48. test.istrue(table.contains(result, "actions/xcode/test_xcode_project.lua"))
  49. test.isfalse(table.contains(result, "premake4.lua"))
  50. end
  51. function suite.matchfiles_OnDotSlashPrefix()
  52. local result = os.matchfiles("./**.lua")
  53. test.istrue(table.contains(result, "folder/ok.lua"))
  54. end
  55. function suite.matchfiles_OnImplicitEndOfString()
  56. local result = os.matchfiles("folder/*.lua")
  57. test.istrue(table.contains(result, "folder/ok.lua"))
  58. test.isfalse(table.contains(result, "folder/ok.lua.2"))
  59. end
  60. function suite.matchfiles_OnLeadingDotSlashWithPath()
  61. local result = os.matchfiles("./folder/*.lua")
  62. test.istrue(table.contains(result, "folder/ok.lua"))
  63. end
  64. --
  65. -- os.pathsearch() tests
  66. --
  67. function suite.pathsearch_ReturnsNil_OnNotFound()
  68. test.istrue( os.pathsearch("nosuchfile", "aaa;bbb;ccc") == nil )
  69. end
  70. function suite.pathsearch_ReturnsPath_OnFound()
  71. test.isequal(os.getcwd(), os.pathsearch("premake4.lua", os.getcwd()))
  72. end
  73. function suite.pathsearch_FindsFile_OnComplexPath()
  74. test.isequal(os.getcwd(), os.pathsearch("premake4.lua", "aaa;"..os.getcwd()..";bbb"))
  75. end
  76. function suite.pathsearch_NilPathsAllowed()
  77. test.isequal(os.getcwd(), os.pathsearch("premake4.lua", nil, os.getcwd(), nil))
  78. end
  79. --
  80. -- os.uuid() tests
  81. --
  82. function suite.guid_ReturnsValidUUID()
  83. local g = os.uuid()
  84. test.istrue(#g == 36)
  85. for i=1,36 do
  86. local ch = g:sub(i,i)
  87. test.istrue(ch:find("[ABCDEF0123456789-]"))
  88. end
  89. test.isequal("-", g:sub(9,9))
  90. test.isequal("-", g:sub(14,14))
  91. test.isequal("-", g:sub(19,19))
  92. test.isequal("-", g:sub(24,24))
  93. end