aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/tests/preprocess/variable
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 05:21:57 -0400
committerMasahiro Yamada <yamada.masahiro@socionext.com>2018-05-28 14:31:19 -0400
commit2bece88f89faad8d2e5499652e2bd5f2045ec92a (patch)
tree9e327ae63fc7449e44d65da043c4ecec9ccf1d24 /scripts/kconfig/tests/preprocess/variable
parent316d55d55f49eca442e4fd948f5fa92bab0c8312 (diff)
kconfig: test: add Kconfig macro language tests
Here are the test cases I used for developing the text expansion feature. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'scripts/kconfig/tests/preprocess/variable')
-rw-r--r--scripts/kconfig/tests/preprocess/variable/Kconfig53
-rw-r--r--scripts/kconfig/tests/preprocess/variable/__init__.py8
-rw-r--r--scripts/kconfig/tests/preprocess/variable/expected_stderr9
3 files changed, 70 insertions, 0 deletions
diff --git a/scripts/kconfig/tests/preprocess/variable/Kconfig b/scripts/kconfig/tests/preprocess/variable/Kconfig
new file mode 100644
index 000000000000..9ce2f95cbd24
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/variable/Kconfig
@@ -0,0 +1,53 @@
1# SPDX-License-Identifier: GPL-2.0
2
3# Shorthand
4warning = $(warning-if,y,$(1))
5
6# Simply expanded variable.
7X := 1
8SIMPLE := $(X)
9X := 2
10$(warning,SIMPLE = $(SIMPLE))
11
12# Recursively expanded variable.
13X := 1
14RECURSIVE = $(X)
15X := 2
16$(warning,RECURSIVE = $(RECURSIVE))
17
18# Append something to a simply expanded variable.
19Y := 3
20SIMPLE += $(Y)
21Y := 4
22$(warning,SIMPLE = $(SIMPLE))
23
24# Append something to a recursively expanded variable.
25Y := 3
26RECURSIVE += $(Y)
27Y := 4
28$(warning,RECURSIVE = $(RECURSIVE))
29
30# Use += operator to an undefined variable.
31# This works as a recursively expanded variable.
32Y := 3
33UNDEFINED_VARIABLE += $(Y)
34Y := 4
35$(warning,UNDEFINED_VARIABLE = $(UNDEFINED_VARIABLE))
36
37# You can use variable references for the lefthand side of assignment statement.
38X := A
39Y := B
40$(X)$(Y) := 5
41$(warning,AB = $(AB))
42
43# User-defined function.
44greeting = $(1), my name is $(2).
45$(warning,$(greeting,Hello,John))
46
47# The number of arguments is not checked for user-defined functions.
48# If some arguments are optional, it is useful to pass fewer parameters.
49# $(2) will be blank in this case.
50$(warning,$(greeting,Hello))
51
52# Unreferenced parameters are just ignored.
53$(warning,$(greeting,Hello,John,ignored,ignored))
diff --git a/scripts/kconfig/tests/preprocess/variable/__init__.py b/scripts/kconfig/tests/preprocess/variable/__init__.py
new file mode 100644
index 000000000000..e88b1708d6d4
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/variable/__init__.py
@@ -0,0 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0
2"""
3Variable and user-defined function tests.
4"""
5
6def test(conf):
7 assert conf.oldaskconfig() == 0
8 assert conf.stderr_matches('expected_stderr')
diff --git a/scripts/kconfig/tests/preprocess/variable/expected_stderr b/scripts/kconfig/tests/preprocess/variable/expected_stderr
new file mode 100644
index 000000000000..a4841c3fdff5
--- /dev/null
+++ b/scripts/kconfig/tests/preprocess/variable/expected_stderr
@@ -0,0 +1,9 @@
1Kconfig:10: SIMPLE = 1
2Kconfig:16: RECURSIVE = 2
3Kconfig:22: SIMPLE = 1 3
4Kconfig:28: RECURSIVE = 2 4
5Kconfig:35: UNDEFINED_VARIABLE = 4
6Kconfig:41: AB = 5
7Kconfig:45: Hello, my name is John.
8Kconfig:50: Hello, my name is .
9Kconfig:53: Hello, my name is John.