Skip to content

Commit 2bece88

Browse files
committed
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>
1 parent 316d55d commit 2bece88

13 files changed

Lines changed: 191 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
# 'info' prints the argument to stdout.
4+
$(info,hello world 0)
5+
6+
# 'warning-if', if the first argument is y, sends the second argument to stderr,
7+
# and the message is prefixed with the current file name and line number.
8+
$(warning-if,y,hello world 1)
9+
10+
# 'error-if' is similar, but it terminates the parsing immediately.
11+
# The following is just no-op since the first argument is not y.
12+
$(error-if,n,this should not be printed)
13+
14+
# Shorthand
15+
warning = $(warning-if,y,$(1))
16+
17+
# 'shell' executes a command, and returns its stdout.
18+
$(warning,$(shell,echo hello world 3))
19+
20+
# Every newline in the output is replaced with a space,
21+
# but any trailing newlines are deleted.
22+
$(warning,$(shell,printf 'hello\nworld\n\n4\n\n\n'))
23+
24+
# 'filename' is expanded to the currently parsed file name,
25+
# 'lineno' to the line number.
26+
$(warning,filename=$(filename))
27+
$(warning,lineno=$(lineno))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
"""
3+
Built-in function tests.
4+
"""
5+
6+
def test(conf):
7+
assert conf.oldaskconfig() == 0
8+
assert conf.stdout_contains('expected_stdout')
9+
assert conf.stderr_matches('expected_stderr')
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Kconfig:8: hello world 1
2+
Kconfig:18: hello world 3
3+
Kconfig:22: hello world 4
4+
Kconfig:26: filename=Kconfig
5+
Kconfig:27: lineno=27
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello world 0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
X = $(Y)
4+
Y = $(X)
5+
$(info $(X))
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
"""
3+
Detect circular variable expansion.
4+
5+
If a recursively expanded variable references itself (eventually),
6+
it should fail with an error message.
7+
"""
8+
9+
def test(conf):
10+
assert conf.oldaskconfig() != 0
11+
assert conf.stderr_matches('expected_stderr')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Kconfig:5: Recursive variable 'X' references itself (eventually)
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
3+
# Shorthand
4+
warning = $(warning-if,y,$(1))
5+
6+
# You can not pass commas directly to a function since they are treated as
7+
# delimiters. You can use the following trick to do so.
8+
comma := ,
9+
$(warning,hello$(comma) world)
10+
11+
# Like Make, single quotes, double quotes, spaces are treated verbatim.
12+
# The following prints the text as-is.
13+
$(warning, ' " '" ' ''' "'")
14+
15+
# Unlike Make, '$' has special meaning only when it is followed by '('.
16+
# No need to escape '$' itself.
17+
$(warning,$)
18+
$(warning,$$)
19+
$ := 1
20+
$(warning,$($))
21+
22+
# You need a trick to escape '$' followed by '('
23+
# The following should print "$(X)". It should not be expanded further.
24+
dollar := $
25+
$(warning,$(dollar)(X))
26+
27+
# You need a trick to treat unbalanced parentheses.
28+
# The following should print "(".
29+
left_paren := (
30+
$(warning,$(left_paren))
31+
32+
# A simple expanded should not be expanded multiple times.
33+
# The following should print "$(X)". It should not be expanded further.
34+
Y := $(dollar)(X)
35+
$(warning,$(Y))
36+
37+
# The following should print "$(X)" as well.
38+
Y = $(dollar)(X)
39+
$(warning,$(Y))
40+
41+
# The following should print "$(".
42+
# It should not be emit "unterminated reference" error.
43+
unterminated := $(dollar)(
44+
$(warning,$(unterminated))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
"""
3+
Escape sequence tests.
4+
"""
5+
6+
def test(conf):
7+
assert conf.oldaskconfig() == 0
8+
assert conf.stderr_matches('expected_stderr')
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Kconfig:9: hello, world
2+
Kconfig:13: ' " '" ' ''' "'"
3+
Kconfig:17: $
4+
Kconfig:18: $$
5+
Kconfig:20: 1
6+
Kconfig:25: $(X)
7+
Kconfig:30: (
8+
Kconfig:35: $(X)
9+
Kconfig:39: $(X)
10+
Kconfig:44: $(

0 commit comments

Comments
 (0)