|
| 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