Skip to content

Commit 5afb4b8

Browse files
committed
Unit tests
1 parent d5973dd commit 5afb4b8

File tree

3 files changed

+162
-4
lines changed

3 files changed

+162
-4
lines changed

src/base/oven.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,6 @@
959959
local properties = {}
960960
local srcprj = src.project
961961

962-
verbosef('Applying properties from %s:%s:%s to %s:%s', srcprj.name, src.usage.name, src.name, tgt.project.name, tgt.shortname)
963-
964962
local blocks = fetchConfigSetBlocks(src)
965963
local n = #blocks
966964
local srccfgpath = src.basedir
@@ -1013,7 +1011,7 @@
10131011
local uses = collectUsages(usagecfg)
10141012

10151013
result = table.join(result, uses)
1016-
result = table.insert(result, usagecfg)
1014+
table.insert(result, usagecfg)
10171015

10181016
return result
10191017
end
@@ -1042,10 +1040,21 @@
10421040
toconsume = table.join(toconsume, children)
10431041
end
10441042

1043+
toconsume = table.unique(toconsume)
1044+
1045+
local allprops = {}
1046+
10451047
for _, usage in ipairs(toconsume) do
10461048
local props = fetchPropertiesToApply(usage, cfg)
1047-
table.insert(cfg._cfgset.blocks, props)
1049+
for k, v in pairs(props) do
1050+
local field = p.field.get(k)
1051+
if field then
1052+
allprops[k] = p.field.store(field, allprops[k], v)
1053+
end
1054+
end
10481055
end
1056+
1057+
table.insert(cfg._cfgset.blocks, allprops)
10491058
end
10501059
end
10511060
end

tests/_tests.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ return {
4444
-- Baking tests
4545
"oven/test_filtering.lua",
4646
"oven/test_objdirs.lua",
47+
"oven/test_usages.lua",
4748

4849
-- API tests
4950
"api/test_boolean_kind.lua",

tests/oven/test_usages.lua

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
---
2+
-- tests/oven/test_usages.lua
3+
-- Test the building of usages
4+
-- Copyright (c) 2014-2025 Jess Perkins and the Premake project
5+
---
6+
7+
local p = premake
8+
local suite = test.declare("oven_usages")
9+
local oven = p.oven
10+
11+
---
12+
-- Setup
13+
---
14+
15+
local wks, prj
16+
17+
function suite.setup()
18+
wks = workspace("MyWorkspace")
19+
configurations { "Debug", "Release" }
20+
platforms { "x86", "x86_64" }
21+
22+
prj = project "MyProject1"
23+
usage "PUBLIC"
24+
defines { "PROJECT_1_PUBLIC" }
25+
usage "INTERFACE"
26+
defines { "PROJECT_1_INTERFACE" }
27+
usage "PRIVATE"
28+
defines { "PROJECT_1_PRIVATE" }
29+
end
30+
31+
---
32+
-- Tests to ensure that the PUBLIC and PRIVATE usages are correctly applied to the owning project
33+
---
34+
function suite.singleproject_checkusages()
35+
p.oven.bake()
36+
37+
local cfg = test.getconfig(prj, "Debug", "x86")
38+
test.isequal({ "PROJECT_1_PUBLIC", "PROJECT_1_PRIVATE" }, cfg.defines) -- Interface defines should not be included
39+
end
40+
41+
---
42+
-- Tests to ensure that the PUBLIC and INTERFACE usages are correctly applied to the dependent project
43+
---
44+
function suite.twoprojects_withdependency()
45+
prj2 = project "MyProject2"
46+
usage "PUBLIC"
47+
defines { "PROJECT_2_PUBLIC" }
48+
usage "INTERFACE"
49+
defines { "PROJECT_2_INTERFACE" }
50+
usage "PRIVATE"
51+
defines { "PROJECT_2_PRIVATE" }
52+
53+
uses { "MyProject1" }
54+
55+
p.oven.bake()
56+
57+
local cfg = test.getconfig(prj2, "Debug", "x86")
58+
59+
-- Order is important here, as the test treats different order as a failure
60+
-- However, the order of the defines is not important in the actual implementation
61+
test.isequal({ "PROJECT_2_PUBLIC", "PROJECT_1_PUBLIC", "PROJECT_1_INTERFACE", "PROJECT_2_PRIVATE" }, cfg.defines) -- Interface defines should not be included
62+
end
63+
64+
---
65+
-- Tests to ensure that the PUBLIC and INTERFACE usages are correctly applied to the dependent project via a transitve dependency
66+
---
67+
function suite.multipleprojects_transitivedependency()
68+
prj2 = project "MyProject2"
69+
usage "PUBLIC"
70+
defines { "PROJECT_2_PUBLIC" }
71+
uses { "MyProject1" }
72+
usage "INTERFACE"
73+
defines { "PROJECT_2_INTERFACE" }
74+
usage "PRIVATE"
75+
defines { "PROJECT_2_PRIVATE" }
76+
77+
prj3 = project "MyProject3"
78+
uses { "MyProject2" }
79+
defines { "PROJECT_3" }
80+
81+
p.oven.bake()
82+
83+
local cfg = test.getconfig(prj3, "Debug", "x86")
84+
85+
-- Order is important here, as the test treats different order as a failure
86+
-- However, the order of the defines is not important in the actual implementation
87+
test.isequal({ "PROJECT_3", "PROJECT_1_PUBLIC", "PROJECT_1_INTERFACE", "PROJECT_2_PUBLIC", "PROJECT_2_INTERFACE" }, cfg.defines) -- Interface defines should not be included
88+
end
89+
90+
---
91+
-- Test to ensure that usages with custom names
92+
---
93+
function suite.twoprojects_customname()
94+
prj2 = project "MyProject2"
95+
uses { "Custom" }
96+
usage "Custom"
97+
defines { "MY_CUSTOM_USAGE" }
98+
99+
p.oven.bake()
100+
101+
local cfg = test.getconfig(prj2, "Debug", "x86")
102+
103+
-- Order is important here, as the test treats different order as a failure
104+
-- However, the order of the defines is not important in the actual implementation
105+
test.isequal({ "MY_CUSTOM_USAGE" }, cfg.defines) -- Interface defines should not be included
106+
end
107+
108+
109+
function suite.multipleprojects_customname_transitive()
110+
prj2 = project "MyProject2"
111+
usage "Custom"
112+
defines { "MY_CUSTOM_USAGE" }
113+
114+
prj3 = project "MyProject3"
115+
usage "Custom2"
116+
uses { "Custom" }
117+
118+
prj4 = project "MyProject4"
119+
uses { "Custom2" }
120+
121+
p.oven.bake()
122+
123+
local cfg = test.getconfig(prj4, "Debug", "x86")
124+
125+
-- Order is important here, as the test treats different order as a failure
126+
-- However, the order of the defines is not important in the actual implementation
127+
test.isequal({ "MY_CUSTOM_USAGE" }, cfg.defines) -- Interface defines should not be included
128+
end
129+
130+
131+
function suite.twoprojects_noprojectinheritance()
132+
-- Ensure that no variables come in from the default project scope
133+
134+
prj2 = project "MyProject2"
135+
defines { "IMPLICIT_PRIVATE_DEFINE" }
136+
usage "PUBLIC"
137+
defines { "PROJECT_2_PUBLIC" }
138+
139+
prj3 = project "MyProject3"
140+
uses { "MyProject2" }
141+
142+
p.oven.bake()
143+
144+
local cfg = test.getconfig(prj3, "Debug", "x86")
145+
146+
-- Ensure that the implicit scope's define is not included
147+
test.isequal({ "PROJECT_2_PUBLIC" }, cfg.defines)
148+
end

0 commit comments

Comments
 (0)