2008-12-15 15:00:35 +00:00
|
|
|
--
|
2010-02-17 22:11:25 +00:00
|
|
|
-- tests/base/test_api.lua
|
2008-12-15 15:00:35 +00:00
|
|
|
-- Automated test suite for the project API support functions.
|
2012-01-28 22:48:29 +00:00
|
|
|
-- Copyright (c) 2008-2012 Jason Perkins and the Premake project
|
2008-12-15 15:00:35 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
T.api = { }
|
2010-02-17 22:11:25 +00:00
|
|
|
local suite = T.api
|
2008-12-15 15:00:35 +00:00
|
|
|
|
2008-12-19 14:35:36 +00:00
|
|
|
local sln
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setup()
|
2008-12-19 14:35:36 +00:00
|
|
|
sln = solution "MySolution"
|
|
|
|
end
|
|
|
|
|
2008-12-15 15:00:35 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- premake.getobject() tests
|
|
|
|
--
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.getobject_RaisesError_OnNoContainer()
|
2008-12-15 15:00:35 +00:00
|
|
|
premake.CurrentContainer = nil
|
|
|
|
c, err = premake.getobject("container")
|
|
|
|
test.istrue(c == nil)
|
|
|
|
test.isequal("no active solution or project", err)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.getobject_RaisesError_OnNoActiveSolution()
|
2008-12-15 15:00:35 +00:00
|
|
|
premake.CurrentContainer = { }
|
|
|
|
c, err = premake.getobject("solution")
|
|
|
|
test.istrue(c == nil)
|
|
|
|
test.isequal("no active solution", err)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.getobject_RaisesError_OnNoActiveConfig()
|
2008-12-15 15:00:35 +00:00
|
|
|
premake.CurrentConfiguration = nil
|
|
|
|
c, err = premake.getobject("config")
|
|
|
|
test.istrue(c == nil)
|
|
|
|
test.isequal("no active solution, project, or configuration", err)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- premake.setarray() tests
|
|
|
|
--
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setarray_Inserts_OnStringValue()
|
2012-01-28 22:48:29 +00:00
|
|
|
local f = premake.setarray({}, "myfield", "hello")
|
|
|
|
test.isequal("hello", f[1])
|
2008-12-15 15:00:35 +00:00
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setarray_Inserts_OnTableValue()
|
2012-01-28 22:48:29 +00:00
|
|
|
local f = premake.setarray({}, "myfield", { "hello", "goodbye" })
|
|
|
|
test.isequal("hello", f[1])
|
|
|
|
test.isequal("goodbye", f[2])
|
2008-12-15 15:00:35 +00:00
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setarray_Appends_OnNewValues()
|
2012-01-28 22:48:29 +00:00
|
|
|
local obj = {
|
|
|
|
myfield = { "hello" }
|
|
|
|
}
|
|
|
|
local f = premake.setarray(obj, "myfield", "goodbye")
|
|
|
|
test.isequal("hello", f[1])
|
|
|
|
test.isequal("goodbye", f[2])
|
2008-12-15 15:00:35 +00:00
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setarray_FlattensTables()
|
2012-01-28 22:48:29 +00:00
|
|
|
local f = premake.setarray({}, "myfield", { {"hello"}, {"goodbye"} })
|
|
|
|
test.isequal("hello", f[1])
|
|
|
|
test.isequal("goodbye", f[2])
|
2008-12-15 15:00:35 +00:00
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setarray_RaisesError_OnInvalidValue()
|
2012-01-28 22:48:29 +00:00
|
|
|
ok, err = pcall(function () premake.setarray({}, "myfield", "bad", { "Good", "Better", "Best" }) end)
|
2008-12-15 15:00:35 +00:00
|
|
|
test.isfalse(ok)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setarray_CorrectsCase_OnConstrainedValue()
|
2012-01-28 22:48:29 +00:00
|
|
|
local f = premake.setarray({}, "myfield", "better", { "Good", "Better", "Best" })
|
|
|
|
test.isequal("Better", f[1])
|
2008-12-15 15:00:35 +00:00
|
|
|
end
|
2012-01-28 22:48:29 +00:00
|
|
|
|
2008-12-15 15:00:35 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- premake.setstring() tests
|
|
|
|
--
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setstring_Sets_OnNewProperty()
|
2008-12-15 15:00:35 +00:00
|
|
|
premake.CurrentConfiguration = { }
|
|
|
|
premake.setstring("config", "myfield", "hello")
|
|
|
|
test.isequal("hello", premake.CurrentConfiguration.myfield)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setstring_Overwrites_OnExistingProperty()
|
2008-12-15 15:00:35 +00:00
|
|
|
premake.CurrentConfiguration = { }
|
|
|
|
premake.CurrentConfiguration.myfield = "hello"
|
|
|
|
premake.setstring("config", "myfield", "goodbye")
|
|
|
|
test.isequal("goodbye", premake.CurrentConfiguration.myfield)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setstring_RaisesError_OnInvalidValue()
|
2008-12-15 15:00:35 +00:00
|
|
|
premake.CurrentConfiguration = { }
|
|
|
|
ok, err = pcall(function () premake.setstring("config", "myfield", "bad", { "Good", "Better", "Best" }) end)
|
|
|
|
test.isfalse(ok)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.setstring_CorrectsCase_OnConstrainedValue()
|
2008-12-15 15:00:35 +00:00
|
|
|
premake.CurrentConfiguration = { }
|
|
|
|
premake.setstring("config", "myfield", "better", { "Good", "Better", "Best" })
|
|
|
|
test.isequal("Better", premake.CurrentConfiguration.myfield)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-02-13 23:50:38 +00:00
|
|
|
--
|
|
|
|
-- premake.setfilearray() tests
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.setfilearray_onWildcards()
|
|
|
|
local f = premake.setfilearray({}, "files", "*.lua")
|
|
|
|
test.istrue(table.contains(f, path.join(os.getcwd(), "testfx.lua")))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2011-06-02 19:26:15 +00:00
|
|
|
--
|
|
|
|
-- premake.setkeyvalue() tests
|
|
|
|
--
|
|
|
|
|
2011-07-19 22:07:30 +00:00
|
|
|
function suite.setkeyvalue_Inserts_OnStringValue()
|
2011-06-02 19:26:15 +00:00
|
|
|
premake.CurrentConfiguration = { }
|
2011-07-19 22:07:30 +00:00
|
|
|
premake.setkeyvalue("config", "vpaths", { ["Headers"] = "*.h" })
|
|
|
|
test.isequal({"*.h"}, premake.CurrentConfiguration.vpaths["Headers"])
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.setkeyvalue_Inserts_OnTableValue()
|
|
|
|
premake.CurrentConfiguration = { }
|
|
|
|
premake.setkeyvalue("config", "vpaths", { ["Headers"] = {"*.h","*.hpp"} })
|
|
|
|
test.isequal({"*.h","*.hpp"}, premake.CurrentConfiguration.vpaths["Headers"])
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.setkeyvalue_Inserts_OnEmptyStringKey()
|
|
|
|
premake.CurrentConfiguration = { }
|
|
|
|
premake.setkeyvalue("config", "vpaths", { [""] = "src" })
|
|
|
|
test.isequal({"src"}, premake.CurrentConfiguration.vpaths[""])
|
2011-06-02 19:26:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function suite.setkeyvalue_RaisesError_OnString()
|
|
|
|
premake.CurrentConfiguration = { }
|
|
|
|
ok, err = pcall(function () premake.setkeyvalue("config", "vpaths", "Headers") end)
|
|
|
|
test.isfalse(ok)
|
|
|
|
end
|
|
|
|
|
2011-07-19 22:07:30 +00:00
|
|
|
function suite.setkeyvalue_InsertsString_IntoExistingKey()
|
2011-06-02 19:26:15 +00:00
|
|
|
premake.CurrentConfiguration = { }
|
2011-07-19 22:07:30 +00:00
|
|
|
premake.setkeyvalue("config", "vpaths", { ["Headers"] = "*.h" })
|
|
|
|
premake.setkeyvalue("config", "vpaths", { ["Headers"] = "*.hpp" })
|
|
|
|
test.isequal({"*.h","*.hpp"}, premake.CurrentConfiguration.vpaths["Headers"])
|
2011-06-02 19:26:15 +00:00
|
|
|
end
|
|
|
|
|
2011-07-19 22:07:30 +00:00
|
|
|
function suite.setkeyvalue_InsertsTable_IntoExistingKey()
|
2011-06-02 19:26:15 +00:00
|
|
|
premake.CurrentConfiguration = { }
|
2011-07-19 22:07:30 +00:00
|
|
|
premake.setkeyvalue("config", "vpaths", { ["Headers"] = {"*.h"} })
|
|
|
|
premake.setkeyvalue("config", "vpaths", { ["Headers"] = {"*.hpp"} })
|
|
|
|
test.isequal({"*.h","*.hpp"}, premake.CurrentConfiguration.vpaths["Headers"])
|
2011-06-02 19:26:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2008-12-19 14:35:36 +00:00
|
|
|
--
|
|
|
|
-- solution() tests
|
|
|
|
--
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_SetsCurrentContainer_OnName()
|
2008-12-19 14:35:36 +00:00
|
|
|
test.istrue(sln == premake.CurrentContainer)
|
|
|
|
end
|
2009-01-19 16:56:40 +00:00
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_CreatesNewObject_OnNewName()
|
2009-01-19 16:56:40 +00:00
|
|
|
solution "MySolution2"
|
|
|
|
test.isfalse(sln == premake.CurrentContainer)
|
2008-12-19 14:35:36 +00:00
|
|
|
end
|
2009-01-19 16:56:40 +00:00
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_ReturnsPrevious_OnExistingName()
|
2009-01-19 16:56:40 +00:00
|
|
|
solution "MySolution2"
|
|
|
|
local sln2 = solution "MySolution"
|
|
|
|
test.istrue(sln == sln2)
|
2008-12-19 14:35:36 +00:00
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_SetsCurrentContainer_OnExistingName()
|
2009-01-19 16:56:40 +00:00
|
|
|
solution "MySolution2"
|
|
|
|
solution "MySolution"
|
|
|
|
test.istrue(sln == premake.CurrentContainer)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_ReturnsNil_OnNoActiveSolutionAndNoName()
|
2008-12-19 14:35:36 +00:00
|
|
|
premake.CurrentContainer = nil
|
2009-01-19 16:56:40 +00:00
|
|
|
test.isnil(solution())
|
2008-12-19 14:35:36 +00:00
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_ReturnsCurrentSolution_OnActiveSolutionAndNoName()
|
2009-01-19 16:56:40 +00:00
|
|
|
test.istrue(sln == solution())
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_ReturnsCurrentSolution_OnActiveProjectAndNoName()
|
2009-01-19 16:56:40 +00:00
|
|
|
project "MyProject"
|
2008-12-19 14:35:36 +00:00
|
|
|
test.istrue(sln == solution())
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_LeavesProjectActive_OnActiveProjectAndNoName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local prj = project "MyProject"
|
|
|
|
solution()
|
|
|
|
test.istrue(prj == premake.CurrentContainer)
|
2008-12-19 14:35:36 +00:00
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_LeavesConfigActive_OnActiveSolutionAndNoName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local cfg = configuration "windows"
|
|
|
|
solution()
|
|
|
|
test.istrue(cfg == premake.CurrentConfiguration)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_LeavesConfigActive_OnActiveProjectAndNoName()
|
2009-01-19 16:56:40 +00:00
|
|
|
project "MyProject"
|
|
|
|
local cfg = configuration "windows"
|
|
|
|
solution()
|
|
|
|
test.istrue(cfg == premake.CurrentConfiguration)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_SetsName_OnNewName()
|
2009-01-19 16:56:40 +00:00
|
|
|
test.isequal("MySolution", sln.name)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_AddsNewConfig_OnNewName()
|
2009-01-19 16:56:40 +00:00
|
|
|
test.istrue(#sln.blocks == 1)
|
2008-12-19 14:35:36 +00:00
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.solution_AddsNewConfig_OnName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local num = #sln.blocks
|
|
|
|
solution "MySolution"
|
|
|
|
test.istrue(#sln.blocks == num + 1)
|
|
|
|
end
|
|
|
|
|
2008-12-19 14:35:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- configuration() tests
|
|
|
|
--
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.configuration_SetsCurrentConfiguration_OnKeywords()
|
2009-01-19 16:56:40 +00:00
|
|
|
local cfg = configuration {"Debug"}
|
2008-12-19 14:35:36 +00:00
|
|
|
test.istrue(premake.CurrentConfiguration == cfg)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.configuration_AddsToContainer_OnKeywords()
|
2009-01-19 16:56:40 +00:00
|
|
|
local cfg = configuration {"Debug"}
|
2008-12-19 14:35:36 +00:00
|
|
|
test.istrue(cfg == sln.blocks[#sln.blocks])
|
|
|
|
end
|
2009-01-19 16:56:40 +00:00
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.configuration_ReturnsCurrent_OnNoKeywords()
|
2009-01-19 16:56:40 +00:00
|
|
|
local cfg = configuration()
|
|
|
|
test.istrue(cfg == sln.blocks[1])
|
|
|
|
end
|
2008-12-19 14:35:36 +00:00
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.configuration_SetsTerms()
|
|
|
|
local cfg = configuration {"aa", "bb"}
|
|
|
|
test.isequal({"aa", "bb"}, cfg.terms)
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.configuration_SetsTermsWithNestedTables()
|
|
|
|
local cfg = configuration { {"aa", "bb"}, "cc" }
|
|
|
|
test.isequal({"aa", "bb", "cc"}, cfg.terms)
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.configuration_CanReuseTerms()
|
|
|
|
local cfg = configuration { "aa", "bb" }
|
|
|
|
local cfg2 = configuration { cfg.terms, "cc" }
|
|
|
|
test.isequal({"aa", "bb", "cc"}, cfg2.terms)
|
|
|
|
end
|
2008-12-19 14:35:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- project() tests
|
|
|
|
--
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_RaisesError_OnNoSolution()
|
2008-12-19 14:35:36 +00:00
|
|
|
premake.CurrentContainer = nil
|
|
|
|
local fn = function() project("MyProject") end
|
|
|
|
ok, err = pcall(fn)
|
|
|
|
test.isfalse(ok)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_SetsCurrentContainer_OnName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local prj = project "MyProject"
|
2008-12-19 14:35:36 +00:00
|
|
|
test.istrue(prj == premake.CurrentContainer)
|
|
|
|
end
|
2009-01-19 16:56:40 +00:00
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_CreatesNewObject_OnNewName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local prj = project "MyProject"
|
|
|
|
local pr2 = project "MyProject2"
|
|
|
|
test.isfalse(prj == premake.CurrentContainer)
|
|
|
|
end
|
2008-12-19 14:35:36 +00:00
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_AddsToSolution_OnNewName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local prj = project "MyProject"
|
2008-12-19 14:35:36 +00:00
|
|
|
test.istrue(prj == sln.projects[1])
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_ReturnsPrevious_OnExistingName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local prj = project "MyProject"
|
|
|
|
local pr2 = project "MyProject2"
|
|
|
|
local pr3 = project "MyProject"
|
|
|
|
test.istrue(prj == pr3)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_SetsCurrentContainer_OnExistingName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local prj = project "MyProject"
|
|
|
|
local pr2 = project "MyProject2"
|
|
|
|
local pr3 = project "MyProject"
|
|
|
|
test.istrue(prj == premake.CurrentContainer)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_ReturnsNil_OnNoActiveProjectAndNoName()
|
2009-01-19 16:56:40 +00:00
|
|
|
test.isnil(project())
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_ReturnsCurrentProject_OnActiveProjectAndNoName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local prj = project "MyProject"
|
|
|
|
test.istrue(prj == project())
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_LeavesProjectActive_OnActiveProjectAndNoName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local prj = project "MyProject"
|
|
|
|
project()
|
|
|
|
test.istrue(prj == premake.CurrentContainer)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_LeavesConfigActive_OnActiveProjectAndNoName()
|
2009-01-19 16:56:40 +00:00
|
|
|
local prj = project "MyProject"
|
|
|
|
local cfg = configuration "Windows"
|
|
|
|
project()
|
|
|
|
test.istrue(cfg == premake.CurrentConfiguration)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_SetsName_OnNewName()
|
2008-12-19 14:35:36 +00:00
|
|
|
prj = project("MyProject")
|
|
|
|
test.isequal("MyProject", prj.name)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_SetsSolution_OnNewName()
|
2008-12-19 14:35:36 +00:00
|
|
|
prj = project("MyProject")
|
|
|
|
test.istrue(sln == prj.solution)
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_SetsConfiguration()
|
2008-12-19 14:35:36 +00:00
|
|
|
prj = project("MyProject")
|
|
|
|
test.istrue(premake.CurrentConfiguration == prj.blocks[1])
|
|
|
|
end
|
|
|
|
|
2010-02-17 22:11:25 +00:00
|
|
|
function suite.project_SetsUUID()
|
2008-12-19 14:35:36 +00:00
|
|
|
local prj = project "MyProject"
|
|
|
|
test.istrue(prj.uuid)
|
|
|
|
end
|
|
|
|
|