diff --git a/CHANGES.txt b/CHANGES.txt index 8d1b77a6..d11f2d1a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,8 +1,9 @@ ------ - 4.3 (in progress) ------ +------- + 4.2.1 (in progress) +------- * Patch 2928029: Add EnableSSE, EnableSSE2 flags +* Patch 2936443: Expose configuration terms to scripts (Laurent Humbertclaude) * Bug 2928775: Error loading external Lua module with require() * Bug 2942438: Wrong runtime library linked diff --git a/src/actions/make/make_csharp.lua b/src/actions/make/make_csharp.lua index 880ad156..fbb424b7 100644 --- a/src/actions/make/make_csharp.lua +++ b/src/actions/make/make_csharp.lua @@ -57,7 +57,7 @@ local action = csc.getbuildaction(fcfg) if action == "Compile" then table.insert(sources, fcfg.name) - elseif action == "EmbeddedResource" then + elseif action == "EmbeddedResource" then table.insert(embedded, fcfg.name) elseif action == "Content" then copypairs["$(TARGETDIR)/" .. _MAKE.esc(path.getname(fcfg.name))] = _MAKE.esc(fcfg.name) diff --git a/src/base/api.lua b/src/base/api.lua index 45ba664c..4a3ebf41 100644 --- a/src/base/api.lua +++ b/src/base/api.lua @@ -541,8 +541,8 @@ -- Project object constructors. -- - function configuration(keywords) - if not keywords then + function configuration(terms) + if not terms then return premake.CurrentConfiguration end @@ -552,27 +552,18 @@ end local cfg = { } + cfg.terms = table.flatten({terms}) + table.insert(container.blocks, cfg) premake.CurrentConfiguration = cfg - -- create a keyword list using just the indexed keyword items + -- create a keyword list using just the indexed keyword items. This is a little + -- confusing: "terms" are what the user specifies in the script, "keywords" are + -- the Lua patterns that result. I'll refactor to better names. cfg.keywords = { } - for _, word in ipairs(table.join({}, keywords)) do + for _, word in ipairs(cfg.terms) do table.insert(cfg.keywords, path.wildcards(word):lower()) end - - -- if file patterns are specified, convert them to Lua patterns and add them too - if keywords.files then - for _, pattern in ipairs(table.join({}, keywords.files)) do - pattern = pattern:gsub("%.", "%%.") - if pattern:find("**", nil, true) then - pattern = pattern:gsub("%*%*", ".*") - else - pattern = pattern:gsub("%*", "[^/]*") - end - table.insert(cfg.keywords, "^" .. pattern .. "$") - end - end -- initialize list-type fields to empty tables for name, field in pairs(premake.fields) do diff --git a/src/base/table.lua b/src/base/table.lua index 03e7f32f..8ca0d080 100644 --- a/src/base/table.lua +++ b/src/base/table.lua @@ -34,6 +34,29 @@ +-- +-- Flattens a hierarchy of tables into a single array containing all +-- of the values. +-- + + function table.flatten(arr) + local result = { } + + local function flatten(arr) + for _, v in ipairs(arr) do + if type(v) == "table" then + flatten(v) + else + table.insert(result, v) + end + end + end + + flatten(arr) + return result + end + + -- -- Merges an array of items into a string. -- diff --git a/src/host/scripts.c b/src/host/scripts.c index 322dc88d..d1d60b0c 100644 --- a/src/host/scripts.c +++ b/src/host/scripts.c @@ -18,8 +18,8 @@ const char* builtin_scripts[] = { "function string.explode(s, pattern, plain)\nif (pattern == '') then return false end\nlocal pos = 0\nlocal arr = { }\nfor st,sp in function() return s:find(pattern, pos, plain) end do\ntable.insert(arr, s:sub(pos, st-1))\npos = sp + 1\nend\ntable.insert(arr, s:sub(pos))\nreturn arr\nend\nfunction string.findlast(s, pattern, plain)\nlocal curr = 0\nrepeat\nlocal next = s:find(pattern, curr + 1, plain)\nif (next) then curr = next end\nuntil (not next)\nif (curr > 0) then\nreturn curr\nend\nend\nfunction string.startswith(haystack, needle)\nreturn (haystack:find(needle, 1, true) == 1)\nend\n", /* base/table.lua */ - "function table.contains(t, value)\nfor _,v in pairs(t) do\nif (v == value) then\nreturn true\nend\nend\nreturn false\nend\nfunction table.extract(arr, fname)\nlocal result = { }\nfor _,v in ipairs(arr) do\ntable.insert(result, v[fname])\nend\nreturn result\nend\nfunction table.implode(arr, before, after, between)\nlocal result = \"\"\nfor _,v in ipairs(arr) do\nif (result ~= \"\" and between) then\nresult = result .. between\nend\nresult = result .. before .. v .. after\nend\nreturn result\nend\nfunction table.isempty(t)\nreturn not next(t)\nend\nfunction table.join(...)\nlocal result = { }\nfor _,t in ipairs(arg) do\nif type(t) == \"table\" then\nfor _,v in ipairs(t) do\ntable.insert(result, v)\nend\nelse\ntable.insert(result, t)\nend\nend\nreturn result\nend\nfunction table.keys(tbl)\nlocal keys = {}\nfor k, _ in pairs(tbl) do\ntable.insert(keys, k)\nend\nreturn keys\nend\nfunction table.translate(arr, translation)\nlocal result = { }\nfor _, value in ipairs(arr) do\nlocal tvalue\nif type(translation) == \"f" - "unction\" then\ntvalue = translation(value)\nelse\ntvalue = translation[value]\nend\nif (tvalue) then\ntable.insert(result, tvalue)\nend\nend\nreturn result\nend\n", + "function table.contains(t, value)\nfor _,v in pairs(t) do\nif (v == value) then\nreturn true\nend\nend\nreturn false\nend\nfunction table.extract(arr, fname)\nlocal result = { }\nfor _,v in ipairs(arr) do\ntable.insert(result, v[fname])\nend\nreturn result\nend\nfunction table.flatten(arr)\nlocal result = { }\nlocal function flatten(arr)\nfor _, v in ipairs(arr) do\nif type(v) == \"table\" then\nflatten(v)\nelse\ntable.insert(result, v)\nend\nend\nend\nflatten(arr)\nreturn result\nend\nfunction table.implode(arr, before, after, between)\nlocal result = \"\"\nfor _,v in ipairs(arr) do\nif (result ~= \"\" and between) then\nresult = result .. between\nend\nresult = result .. before .. v .. after\nend\nreturn result\nend\nfunction table.isempty(t)\nreturn not next(t)\nend\nfunction table.join(...)\nlocal result = { }\nfor _,t in ipairs(arg) do\nif type(t) == \"table\" then\nfor _,v in ipairs(t) do\ntable.insert(result, v)\nend\nelse\ntable.insert(result, t)\nend\nend\nreturn result\nend\nfunction table.keys(tbl)" + "\nlocal keys = {}\nfor k, _ in pairs(tbl) do\ntable.insert(keys, k)\nend\nreturn keys\nend\nfunction table.translate(arr, translation)\nlocal result = { }\nfor _, value in ipairs(arr) do\nlocal tvalue\nif type(translation) == \"function\" then\ntvalue = translation(value)\nelse\ntvalue = translation[value]\nend\nif (tvalue) then\ntable.insert(result, tvalue)\nend\nend\nreturn result\nend\n", /* base/io.lua */ "function io.capture()\nio.captured = ''\nend\nfunction io.endcapture()\nlocal captured = io.captured\nio.captured = nil\nreturn captured\nend\nlocal builtin_open = io.open\nfunction io.open(fname, mode)\nif (mode) then\nif (mode:find(\"w\")) then\nlocal dir = path.getdirectory(fname)\nok, err = os.mkdir(dir)\nif (not ok) then\nerror(err, 0)\nend\nend\nend\nreturn builtin_open(fname, mode)\nend\nfunction io.printf(msg, ...)\nif (not io.eol) then\nio.eol = \"\\n\"\nend\nlocal s\nif type(msg) == \"number\" then\ns = string.rep(\"\\t\", msg) .. string.format(unpack(arg))\nelse\ns = string.format(msg, unpack(arg))\nend\nif io.captured then\nio.captured = io.captured .. s .. io.eol\nelse\nio.write(s)\nio.write(io.eol)\nend\nend\n_p = io.printf\n", @@ -71,9 +71,8 @@ const char* builtin_scripts[] = { "make.getobject(t)\nlocal container\nif (t == \"container\" or t == \"solution\") then\ncontainer = premake.CurrentContainer\nelse\ncontainer = premake.CurrentConfiguration\nend\nif t == \"solution\" then\nif type(container) == \"project\" then\ncontainer = container.solution\nend\nif type(container) ~= \"solution\" then\ncontainer = nil\nend\nend\nlocal msg\nif (not container) then\nif (t == \"container\") then\nmsg = \"no active solution or project\"\nelseif (t == \"solution\") then\nmsg = \"no active solution\"\nelse\nmsg = \"no active solution, project, or configuration\"\nend\nend\nreturn container, msg\nend\nfunction premake.setarray(ctype, fieldname, value, allowed)\nlocal container, err = premake.getobject(ctype)\nif (not container) then\nerror(err, 4)\nend\nif (not container[fieldname]) then\ncontainer[fieldname] = { }\nend\nlocal function doinsert(value, depth)\nif (type(value) == \"table\") then\nfor _,v in ipairs(value) do\ndoinsert(v, depth + 1)\nend\nelse\nvalue, err = premake.checkvalue(value, al" "lowed)\nif (not value) then\nerror(err, depth)\nend\ntable.insert(container[fieldname], value)\nend\nend\nif (value) then\ndoinsert(value, 5)\nend\nreturn container[fieldname]\nend\nlocal function domatchedarray(ctype, fieldname, value, matchfunc)\nlocal result = { }\nfunction makeabsolute(value)\nif (type(value) == \"table\") then\nfor _,item in ipairs(value) do\nmakeabsolute(item)\nend\nelse\nif value:find(\"*\") then\nmakeabsolute(matchfunc(value))\nelse\ntable.insert(result, path.getabsolute(value))\nend\nend\nend\nmakeabsolute(value)\nreturn premake.setarray(ctype, fieldname, result)\nend\nfunction premake.setdirarray(ctype, fieldname, value)\nreturn domatchedarray(ctype, fieldname, value, os.matchdirs)\nend\nfunction premake.setfilearray(ctype, fieldname, value)\nreturn domatchedarray(ctype, fieldname, value, os.matchfiles)\nend\nfunction premake.setstring(ctype, fieldname, value, allowed)\nlocal container, err = premake.getobject(ctype)\nif (not container) then\nerror(err, 4)\nend\nif (value) then\nvalu" "e, err = premake.checkvalue(value, allowed)\nif (not value) then \nerror(err, 4)\nend\ncontainer[fieldname] = value\nend\nreturn container[fieldname]\nend\nlocal function accessor(name, value)\nlocal kind = premake.fields[name].kind\nlocal scope = premake.fields[name].scope\nlocal allowed = premake.fields[name].allowed\nif (kind == \"string\" or kind == \"path\" and value) then\nif type(value) ~= \"string\" then\nerror(\"string value expected\", 3)\nend\nend\nif (kind == \"string\") then\nreturn premake.setstring(scope, name, value, allowed)\nelseif (kind == \"path\") then\nif value then value = path.getabsolute(value) end\nreturn premake.setstring(scope, name, value)\nelseif (kind == \"list\") then\nreturn premake.setarray(scope, name, value, allowed)\nelseif (kind == \"dirlist\") then\nreturn premake.setdirarray(scope, name, value)\nelseif (kind == \"filelist\") then\nreturn premake.setfilearray(scope, name, value)\nend\nend\nfor name,_ in pairs(premake.fields) do\n_G[name] = function(value)\nreturn acc" - "essor(name, value)\nend\nend\nfunction configuration(keywords)\nif not keywords then\nreturn premake.CurrentConfiguration\nend\nlocal container, err = premake.getobject(\"container\")\nif (not container) then\nerror(err, 2)\nend\nlocal cfg = { }\ntable.insert(container.blocks, cfg)\npremake.CurrentConfiguration = cfg\ncfg.keywords = { }\nfor _, word in ipairs(table.join({}, keywords)) do\ntable.insert(cfg.keywords, path.wildcards(word):lower())\nend\nif keywords.files then\nfor _, pattern in ipairs(table.join({}, keywords.files)) do\npattern = pattern:gsub(\"%.\", \"%%.\")\nif pattern:find(\"**\", nil, true) then\npattern = pattern:gsub(\"%*%*\", \".*\")\nelse\npattern = pattern:gsub(\"%*\", \"[^/]*\")\nend\ntable.insert(cfg.keywords, \"^\" .. pattern .. \"$\")\nend\nend\nfor name, field in pairs(premake.fields) do\nif (field.kind ~= \"string\" and field.kind ~= \"path\") then\ncfg[name] = { }\nend\nend\nreturn cfg\nend\nfunction project(name)\nif not name then\nreturn iif(type(premake.CurrentContainer) == \"p" - "roject\", premake.CurrentContainer, nil)\nend\nlocal sln\nif (type(premake.CurrentContainer) == \"project\") then\nsln = premake.CurrentContainer.solution\nelse\nsln = premake.CurrentContainer\nend\nif (type(sln) ~= \"solution\") then\nerror(\"no active solution\", 2)\nend\npremake.CurrentContainer = sln.projects[name]\nif (not premake.CurrentContainer) then\nlocal prj = { }\npremake.CurrentContainer = prj\ntable.insert(sln.projects, prj)\nsln.projects[name] = prj\nsetmetatable(prj, {\n__type = \"project\",\n})\nprj.solution = sln\nprj.name = name\nprj.basedir = os.getcwd()\nprj.uuid = os.uuid()\nprj.blocks = { }\nend\nconfiguration { }\nreturn premake.CurrentContainer\nend\nfunction solution(name)\nif not name then\nif type(premake.CurrentContainer) == \"project\" then\nreturn premake.CurrentContainer.solution\nelse\nreturn premake.CurrentContainer\nend\nend\npremake.CurrentContainer = premake.solution.get(name)\nif (not premake.CurrentContainer) then\npremake.CurrentC" - "ontainer = premake.solution.new(name)\nend\nconfiguration { }\nreturn premake.CurrentContainer\nend\nfunction newaction(a)\npremake.action.add(a)\nend\nfunction newoption(opt)\npremake.option.add(opt)\nend\n", + "essor(name, value)\nend\nend\nfunction configuration(terms)\nif not terms then\nreturn premake.CurrentConfiguration\nend\nlocal container, err = premake.getobject(\"container\")\nif (not container) then\nerror(err, 2)\nend\nlocal cfg = { }\ncfg.terms = table.flatten({terms})\ntable.insert(container.blocks, cfg)\npremake.CurrentConfiguration = cfg\ncfg.keywords = { }\nfor _, word in ipairs(cfg.terms) do\ntable.insert(cfg.keywords, path.wildcards(word):lower())\nend\nfor name, field in pairs(premake.fields) do\nif (field.kind ~= \"string\" and field.kind ~= \"path\") then\ncfg[name] = { }\nend\nend\nreturn cfg\nend\nfunction project(name)\nif not name then\nreturn iif(type(premake.CurrentContainer) == \"project\", premake.CurrentContainer, nil)\nend\nlocal sln\nif (type(premake.CurrentContainer) == \"project\") then\nsln = premake.CurrentContainer.solution\nelse\nsln = premake.CurrentContainer\nend\nif (type(sln) ~= \"solution\") then\nerror(\"no active solution\", 2)\nend\npremake.CurrentContainer = sln.project" + "s[name]\nif (not premake.CurrentContainer) then\nlocal prj = { }\npremake.CurrentContainer = prj\ntable.insert(sln.projects, prj)\nsln.projects[name] = prj\nsetmetatable(prj, {\n__type = \"project\",\n})\nprj.solution = sln\nprj.name = name\nprj.basedir = os.getcwd()\nprj.uuid = os.uuid()\nprj.blocks = { }\nend\nconfiguration { }\nreturn premake.CurrentContainer\nend\nfunction solution(name)\nif not name then\nif type(premake.CurrentContainer) == \"project\" then\nreturn premake.CurrentContainer.solution\nelse\nreturn premake.CurrentContainer\nend\nend\npremake.CurrentContainer = premake.solution.get(name)\nif (not premake.CurrentContainer) then\npremake.CurrentContainer = premake.solution.new(name)\nend\nconfiguration { }\nreturn premake.CurrentContainer\nend\nfunction newaction(a)\npremake.action.add(a)\nend\nfunction newoption(opt)\npremake.option.add(opt)\nend\n", /* base/cmdline.lua */ "newoption \n{\ntrigger = \"cc\",\nvalue = \"VALUE\",\ndescription = \"Choose a C/C++ compiler set\",\nallowed = {\n{ \"gcc\", \"GNU GCC (gcc/g++)\" },\n{ \"ow\", \"OpenWatcom\" },\n}\n}\nnewoption\n{\ntrigger = \"dotnet\",\nvalue = \"VALUE\",\ndescription = \"Choose a .NET compiler set\",\nallowed = {\n{ \"msnet\", \"Microsoft .NET (csc)\" },\n{ \"mono\", \"Novell Mono (mcs)\" },\n{ \"pnet\", \"Portable.NET (cscc)\" },\n}\n}\nnewoption\n{\ntrigger = \"file\",\nvalue = \"FILE\",\ndescription = \"Read FILE as a Premake script; default is 'premake4.lua'\"\n}\nnewoption\n{\ntrigger = \"help\",\ndescription = \"Display this information\"\n}\nnewoption\n{\ntrigger = \"os\",\nvalue = \"VALUE\",\ndescription = \"Generate files for a different operating system\",\nallowed = {\n{ \"bsd\", \"OpenBSD, NetBSD, or FreeBSD\" },\n{ \"linux\", \"Linux\" },\n{ \"macosx\", \"Apple Mac OS X\" },\n{ \"windows\", \"Microsoft Windows\" },\n}\n}\nnewoption\n{" diff --git a/tests/test_api.lua b/tests/base/test_api.lua similarity index 66% rename from tests/test_api.lua rename to tests/base/test_api.lua index 44262c1e..a214337a 100644 --- a/tests/test_api.lua +++ b/tests/base/test_api.lua @@ -1,13 +1,14 @@ -- --- tests/test_api.lua +-- tests/base/test_api.lua -- Automated test suite for the project API support functions. --- Copyright (c) 2008 Jason Perkins and the Premake project +-- Copyright (c) 2008-2010 Jason Perkins and the Premake project -- T.api = { } + local suite = T.api local sln - function T.api.setup() + function suite.setup() sln = solution "MySolution" end @@ -16,21 +17,21 @@ -- premake.getobject() tests -- - function T.api.getobject_RaisesError_OnNoContainer() + function suite.getobject_RaisesError_OnNoContainer() premake.CurrentContainer = nil c, err = premake.getobject("container") test.istrue(c == nil) test.isequal("no active solution or project", err) end - function T.api.getobject_RaisesError_OnNoActiveSolution() + function suite.getobject_RaisesError_OnNoActiveSolution() premake.CurrentContainer = { } c, err = premake.getobject("solution") test.istrue(c == nil) test.isequal("no active solution", err) end - function T.api.getobject_RaisesError_OnNoActiveConfig() + function suite.getobject_RaisesError_OnNoActiveConfig() premake.CurrentConfiguration = nil c, err = premake.getobject("config") test.istrue(c == nil) @@ -42,14 +43,14 @@ -- premake.setarray() tests -- - function T.api.setarray_Inserts_OnStringValue() + function suite.setarray_Inserts_OnStringValue() premake.CurrentConfiguration = { } premake.CurrentConfiguration.myfield = { } premake.setarray("config", "myfield", "hello") test.isequal("hello", premake.CurrentConfiguration.myfield[1]) end - function T.api.setarray_Inserts_OnTableValue() + function suite.setarray_Inserts_OnTableValue() premake.CurrentConfiguration = { } premake.CurrentConfiguration.myfield = { } premake.setarray("config", "myfield", { "hello", "goodbye" }) @@ -57,7 +58,7 @@ test.isequal("goodbye", premake.CurrentConfiguration.myfield[2]) end - function T.api.setarray_Appends_OnNewValues() + function suite.setarray_Appends_OnNewValues() premake.CurrentConfiguration = { } premake.CurrentConfiguration.myfield = { "hello" } premake.setarray("config", "myfield", "goodbye") @@ -65,7 +66,7 @@ test.isequal("goodbye", premake.CurrentConfiguration.myfield[2]) end - function T.api.setarray_FlattensTables() + function suite.setarray_FlattensTables() premake.CurrentConfiguration = { } premake.CurrentConfiguration.myfield = { } premake.setarray("config", "myfield", { {"hello"}, {"goodbye"} }) @@ -73,14 +74,14 @@ test.isequal("goodbye", premake.CurrentConfiguration.myfield[2]) end - function T.api.setarray_RaisesError_OnInvalidValue() + function suite.setarray_RaisesError_OnInvalidValue() premake.CurrentConfiguration = { } premake.CurrentConfiguration.myfield = { } ok, err = pcall(function () premake.setarray("config", "myfield", "bad", { "Good", "Better", "Best" }) end) test.isfalse(ok) end - function T.api.setarray_CorrectsCase_OnConstrainedValue() + function suite.setarray_CorrectsCase_OnConstrainedValue() premake.CurrentConfiguration = { } premake.CurrentConfiguration.myfield = { } premake.setarray("config", "myfield", "better", { "Good", "Better", "Best" }) @@ -93,26 +94,26 @@ -- premake.setstring() tests -- - function T.api.setstring_Sets_OnNewProperty() + function suite.setstring_Sets_OnNewProperty() premake.CurrentConfiguration = { } premake.setstring("config", "myfield", "hello") test.isequal("hello", premake.CurrentConfiguration.myfield) end - function T.api.setstring_Overwrites_OnExistingProperty() + function suite.setstring_Overwrites_OnExistingProperty() premake.CurrentConfiguration = { } premake.CurrentConfiguration.myfield = "hello" premake.setstring("config", "myfield", "goodbye") test.isequal("goodbye", premake.CurrentConfiguration.myfield) end - function T.api.setstring_RaisesError_OnInvalidValue() + function suite.setstring_RaisesError_OnInvalidValue() premake.CurrentConfiguration = { } ok, err = pcall(function () premake.setstring("config", "myfield", "bad", { "Good", "Better", "Best" }) end) test.isfalse(ok) end - function T.api.setstring_CorrectsCase_OnConstrainedValue() + function suite.setstring_CorrectsCase_OnConstrainedValue() premake.CurrentConfiguration = { } premake.setstring("config", "myfield", "better", { "Good", "Better", "Best" }) test.isequal("Better", premake.CurrentConfiguration.myfield) @@ -123,69 +124,69 @@ -- solution() tests -- - function T.api.solution_SetsCurrentContainer_OnName() + function suite.solution_SetsCurrentContainer_OnName() test.istrue(sln == premake.CurrentContainer) end - function T.api.solution_CreatesNewObject_OnNewName() + function suite.solution_CreatesNewObject_OnNewName() solution "MySolution2" test.isfalse(sln == premake.CurrentContainer) end - function T.api.solution_ReturnsPrevious_OnExistingName() + function suite.solution_ReturnsPrevious_OnExistingName() solution "MySolution2" local sln2 = solution "MySolution" test.istrue(sln == sln2) end - function T.api.solution_SetsCurrentContainer_OnExistingName() + function suite.solution_SetsCurrentContainer_OnExistingName() solution "MySolution2" solution "MySolution" test.istrue(sln == premake.CurrentContainer) end - function T.api.solution_ReturnsNil_OnNoActiveSolutionAndNoName() + function suite.solution_ReturnsNil_OnNoActiveSolutionAndNoName() premake.CurrentContainer = nil test.isnil(solution()) end - function T.api.solution_ReturnsCurrentSolution_OnActiveSolutionAndNoName() + function suite.solution_ReturnsCurrentSolution_OnActiveSolutionAndNoName() test.istrue(sln == solution()) end - function T.api.solution_ReturnsCurrentSolution_OnActiveProjectAndNoName() + function suite.solution_ReturnsCurrentSolution_OnActiveProjectAndNoName() project "MyProject" test.istrue(sln == solution()) end - function T.api.solution_LeavesProjectActive_OnActiveProjectAndNoName() + function suite.solution_LeavesProjectActive_OnActiveProjectAndNoName() local prj = project "MyProject" solution() test.istrue(prj == premake.CurrentContainer) end - function T.api.solution_LeavesConfigActive_OnActiveSolutionAndNoName() + function suite.solution_LeavesConfigActive_OnActiveSolutionAndNoName() local cfg = configuration "windows" solution() test.istrue(cfg == premake.CurrentConfiguration) end - function T.api.solution_LeavesConfigActive_OnActiveProjectAndNoName() + function suite.solution_LeavesConfigActive_OnActiveProjectAndNoName() project "MyProject" local cfg = configuration "windows" solution() test.istrue(cfg == premake.CurrentConfiguration) end - function T.api.solution_SetsName_OnNewName() + function suite.solution_SetsName_OnNewName() test.isequal("MySolution", sln.name) end - function T.api.solution_AddsNewConfig_OnNewName() + function suite.solution_AddsNewConfig_OnNewName() test.istrue(#sln.blocks == 1) end - function T.api.solution_AddsNewConfig_OnName() + function suite.solution_AddsNewConfig_OnName() local num = #sln.blocks solution "MySolution" test.istrue(#sln.blocks == num + 1) @@ -197,109 +198,124 @@ -- configuration() tests -- - function T.api.configuration_RaisesError_OnNoContainer() + function suite.configuration_RaisesError_OnNoContainer() premake.CurrentContainer = nil local fn = function() configuration{"Debug"} end ok, err = pcall(fn) test.isfalse(ok) end - function T.api.configuration_SetsCurrentConfiguration_OnKeywords() + function suite.configuration_SetsCurrentConfiguration_OnKeywords() local cfg = configuration {"Debug"} test.istrue(premake.CurrentConfiguration == cfg) end - function T.api.configuration_AddsToContainer_OnKeywords() + function suite.configuration_AddsToContainer_OnKeywords() local cfg = configuration {"Debug"} test.istrue(cfg == sln.blocks[#sln.blocks]) end - function T.api.configuration_ReturnsCurrent_OnNoKeywords() + function suite.configuration_ReturnsCurrent_OnNoKeywords() local cfg = configuration() test.istrue(cfg == sln.blocks[1]) end + 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 -- -- project() tests -- - function T.api.project_RaisesError_OnNoSolution() + function suite.project_RaisesError_OnNoSolution() premake.CurrentContainer = nil local fn = function() project("MyProject") end ok, err = pcall(fn) test.isfalse(ok) end - function T.api.project_SetsCurrentContainer_OnName() + function suite.project_SetsCurrentContainer_OnName() local prj = project "MyProject" test.istrue(prj == premake.CurrentContainer) end - function T.api.project_CreatesNewObject_OnNewName() + function suite.project_CreatesNewObject_OnNewName() local prj = project "MyProject" local pr2 = project "MyProject2" test.isfalse(prj == premake.CurrentContainer) end - function T.api.project_AddsToSolution_OnNewName() + function suite.project_AddsToSolution_OnNewName() local prj = project "MyProject" test.istrue(prj == sln.projects[1]) end - function T.api.project_ReturnsPrevious_OnExistingName() + function suite.project_ReturnsPrevious_OnExistingName() local prj = project "MyProject" local pr2 = project "MyProject2" local pr3 = project "MyProject" test.istrue(prj == pr3) end - function T.api.project_SetsCurrentContainer_OnExistingName() + function suite.project_SetsCurrentContainer_OnExistingName() local prj = project "MyProject" local pr2 = project "MyProject2" local pr3 = project "MyProject" test.istrue(prj == premake.CurrentContainer) end - function T.api.project_ReturnsNil_OnNoActiveProjectAndNoName() + function suite.project_ReturnsNil_OnNoActiveProjectAndNoName() test.isnil(project()) end - function T.api.project_ReturnsCurrentProject_OnActiveProjectAndNoName() + function suite.project_ReturnsCurrentProject_OnActiveProjectAndNoName() local prj = project "MyProject" test.istrue(prj == project()) end - function T.api.project_LeavesProjectActive_OnActiveProjectAndNoName() + function suite.project_LeavesProjectActive_OnActiveProjectAndNoName() local prj = project "MyProject" project() test.istrue(prj == premake.CurrentContainer) end - function T.api.project_LeavesConfigActive_OnActiveProjectAndNoName() + function suite.project_LeavesConfigActive_OnActiveProjectAndNoName() local prj = project "MyProject" local cfg = configuration "Windows" project() test.istrue(cfg == premake.CurrentConfiguration) end - function T.api.project_SetsName_OnNewName() + function suite.project_SetsName_OnNewName() prj = project("MyProject") test.isequal("MyProject", prj.name) end - function T.api.project_SetsSolution_OnNewName() + function suite.project_SetsSolution_OnNewName() prj = project("MyProject") test.istrue(sln == prj.solution) end - function T.api.project_SetsConfiguration() + function suite.project_SetsConfiguration() prj = project("MyProject") test.istrue(premake.CurrentConfiguration == prj.blocks[1]) end - function T.api.project_SetsUUID() + function suite.project_SetsUUID() local prj = project "MyProject" test.istrue(prj.uuid) end @@ -310,7 +326,7 @@ -- uuid() tests -- - function T.api.uuid_makes_uppercase() + function suite.uuid_makes_uppercase() premake.CurrentContainer = {} uuid "7CBB5FC2-7449-497f-947F-129C5129B1FB" test.isequal(premake.CurrentContainer.uuid, "7CBB5FC2-7449-497F-947F-129C5129B1FB") diff --git a/tests/test_table.lua b/tests/base/test_table.lua similarity index 52% rename from tests/test_table.lua rename to tests/base/test_table.lua index e1ddc25d..2bf26ed1 100644 --- a/tests/test_table.lua +++ b/tests/base/test_table.lua @@ -1,33 +1,44 @@ -- --- tests/test_table.lua +-- tests/base/test_table.lua -- Automated test suite for the new table functions. --- Copyright (c) 2008 Jason Perkins and the Premake project +-- Copyright (c) 2008-2010 Jason Perkins and the Premake project -- T.table = { } + local suite = T.table -- -- table.contains() tests -- - function T.table.contains_OnContained() + function suite.contains_OnContained() t = { "one", "two", "three" } test.istrue( table.contains(t, "two") ) end - function T.table.contains_OnNotContained() + function suite.contains_OnNotContained() t = { "one", "two", "three" } test.isfalse( table.contains(t, "four") ) end - + +-- +-- table.flatten() tests +-- + + function suite.flatten_OnMixedValues() + t = { "a", { "b", "c" }, "d" } + test.isequal({ "a", "b", "c", "d" }, table.flatten(t)) + end + + -- -- table.implode() tests -- - function T.table.implode() + function suite.implode() t = { "one", "two", "three", "four" } test.isequal("[one], [two], [three], [four]", table.implode(t, "[", "]", ", ")) end @@ -37,10 +48,10 @@ -- table.isempty() tests -- - function T.table.isempty_ReturnsTrueOnEmpty() + function suite.isempty_ReturnsTrueOnEmpty() test.istrue(table.isempty({})) end - function T.table.isempty_ReturnsFalseOnNotEmpty() + function suite.isempty_ReturnsFalseOnNotEmpty() test.isfalse(table.isempty({ 1 })) end diff --git a/tests/premake4.lua b/tests/premake4.lua index eabbd945..4a4b8a5d 100644 --- a/tests/premake4.lua +++ b/tests/premake4.lua @@ -39,12 +39,10 @@ dofile("test_dofile.lua") dofile("test_string.lua") - dofile("test_table.lua") dofile("test_premake.lua") dofile("test_project.lua") dofile("test_configs.lua") dofile("test_platforms.lua") - dofile("test_api.lua") dofile("test_targets.lua") dofile("test_keywords.lua") dofile("test_gcc.lua") @@ -55,9 +53,11 @@ dofile("test_vs200x_vcproj.lua") dofile("test_gmake_cpp.lua") dofile("test_gmake_cs.lua") + dofile("base/test_api.lua") dofile("base/test_action.lua") dofile("base/test_os.lua") dofile("base/test_path.lua") + dofile("base/test_table.lua") dofile("base/test_tree.lua") dofile("actions/test_clean.lua") diff --git a/tests/testfx.lua b/tests/testfx.lua index aada444b..55fbb0b2 100644 --- a/tests/testfx.lua +++ b/tests/testfx.lua @@ -79,7 +79,7 @@ function test.isequal(expected, actual) if (type(expected) == "table") then for k,v in pairs(expected) do - if (expected[k] ~= actual[k]) then + if not (test.isequal(expected[k], actual[k])) then test.fail("expected %s but was %s", expected, actual) end end @@ -88,6 +88,7 @@ test.fail("expected %s but was %s", expected, actual) end end + return true end