2012-10-19 22:53:03 +00:00
|
|
|
--
|
|
|
|
-- tests/base/test_context.lua
|
|
|
|
-- Test suite for the configuration context API.
|
2014-03-08 14:28:37 +00:00
|
|
|
-- Copyright (c) 2012-2014 Jason Perkins and the Premake project
|
2012-10-19 22:53:03 +00:00
|
|
|
--
|
|
|
|
|
2014-03-08 14:28:37 +00:00
|
|
|
local suite = test.declare("context")
|
2012-10-19 22:53:03 +00:00
|
|
|
|
|
|
|
local context = premake.context
|
|
|
|
local configset = premake.configset
|
2014-03-08 21:03:34 +00:00
|
|
|
local field = premake.field
|
2012-10-19 22:53:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Setup and teardown
|
|
|
|
--
|
|
|
|
|
2014-03-08 14:28:37 +00:00
|
|
|
local ctx, cset
|
2012-10-19 22:53:03 +00:00
|
|
|
|
|
|
|
function suite.setup()
|
2014-03-08 14:28:37 +00:00
|
|
|
cset = configset.new()
|
|
|
|
ctx = context.new(cset)
|
2012-10-19 22:53:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Make sure that new() returns a valid object.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.new_returnsValidObject()
|
|
|
|
test.isequal("table", type(ctx))
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Context should be able to retrieve a default value from
|
|
|
|
-- the configuration set, using the field name.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.returnsConfigValue_onExistingValue()
|
2014-03-08 21:03:34 +00:00
|
|
|
configset.store(cset, field.get("targetextension"), ".so")
|
2012-10-19 22:53:03 +00:00
|
|
|
test.isequal(".so", ctx.targetextension)
|
|
|
|
end
|
2012-11-04 14:21:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Tokens encountered in enabled fields should be expanded.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.doesExpandTokens()
|
2014-03-08 21:03:34 +00:00
|
|
|
configset.store(cset, field.get("targetname"), "MyProject%{1 + 1}")
|
2012-11-04 14:21:58 +00:00
|
|
|
test.isequal("MyProject2", ctx.targetname)
|
|
|
|
end
|
2016-08-22 23:06:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Token environment in extended context overrides context.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.extent()
|
|
|
|
-- set in toplevel context.
|
|
|
|
configset.store(cset, field.get("targetname"), "%{value}")
|
|
|
|
|
|
|
|
-- detoken in toplevel context should result in empty string.
|
|
|
|
test.isequal("", ctx.targetname)
|
|
|
|
|
|
|
|
-- create an extended context with a local environ.
|
|
|
|
local environ = {
|
|
|
|
value = "text"
|
|
|
|
}
|
|
|
|
local ext = context.extent(ctx, environ)
|
|
|
|
|
|
|
|
-- detoken in extended context should result in value set in that environ.
|
|
|
|
test.isequal("text", ext.targetname)
|
|
|
|
end
|