Skip to content

Commit a927a04

Browse files
committed
move keyword tests to new xlat argument parser
with a bit of good fortune, not all tests had to be updated. However, there are still many tests which do unnecessary expansions, ala %foo(%{User-Name} which is no longer necessary. It may be useful to forbid that, or to at least print an error message complaining about it.
1 parent 6517739 commit a927a04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+201
-197
lines changed

src/tests/keywords/all.mk

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ $(OUTPUT)/${1}: $(BUILD_DIR)/lib/local/libfreeradius-dhcpv4.la $(BUILD_DIR)/lib/
8686
endif
8787
endif
8888

89+
#
90+
# Always use the new xlat parser
91+
#
92+
$(OUTPUT)/${1}: NEW_COND += -S xlat_func_bare_words=no
93+
8994
endef
9095
$(foreach x,$(FILES),$(eval $(call KEYWORD_TEST,$x)))
9196

@@ -152,7 +157,7 @@ KEYWORD_LIBS := $(addsuffix .la,$(addprefix rlm_,$(KEYWORD_MODULES))) rlm_csv.la
152157
# (make -k test.keywords 2>&1) | grep 'KEYWORD=' | sed 's/KEYWORD=//;s/ .*$//'
153158
#
154159
$(OUTPUT)/%: $(DIR)/% $(TEST_BIN_DIR)/unit_test_module | $(KEYWORD_RADDB) $(KEYWORD_LIBS) build.raddb rlm_test.la rlm_csv.la rlm_unpack.la
155-
$(eval CMD:=KEYWORD=$(notdir $@) $(TEST_BIN)/unit_test_module $(NEW_COND) -S xlat_func_bare_words=yes $(UNIT_TEST_KEYWORD_ARGS.$(subst -,_,$(notdir $@))) -D share/dictionary -d src/tests/keywords/ -i "$@.attrs" -f "$@.attrs" -r "$@" -xx )
160+
$(eval CMD:=KEYWORD=$(notdir $@) $(TEST_BIN)/unit_test_module $(NEW_COND) $(UNIT_TEST_KEYWORD_ARGS.$(subst -,_,$(notdir $@))) -D share/dictionary -d src/tests/keywords/ -i "$@.attrs" -f "$@.attrs" -r "$@" -xx )
156161
@echo "KEYWORD-TEST $(notdir $@)"
157162
${Q}if ! $(CMD) > "$@.log" 2>&1 || ! test -f "$@"; then \
158163
if ! grep ERROR $< 2>&1 > /dev/null; then \

src/tests/keywords/attr-index-eval

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ index := 1
88
#
99
# Dynamically create an attribute reference
1010
#
11-
ref = "&Filter-Id[" + (string) index + "]"
11+
ref = "Filter-Id[" + (string) index + "]"
1212

1313
#
14-
# Evaluate the attribute as an unlang expression.
14+
# Evaluate the contents of the attribute as an unlang expression.
1515
#
16-
foo = %eval(%{ref})
16+
foo = %eval(ref)
1717

1818
if (foo != "b") {
1919
test_fail
2020
}
2121

2222
ref = "1 + 2"
2323

24-
foo = %eval(%{ref})
24+
foo = %eval(ref)
2525

2626
if (foo != 3) {
2727
test_fail

src/tests/keywords/base64

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,73 +29,73 @@ test_int64 = 1152921505566832445
2929
test_ipv4prefix = 57.56.55.62/32
3030

3131
# String - bin 0x39383730
32-
test_output := %base64.encode(%{test_string})
32+
test_output := %base64.encode(test_string)
3333
if (!(test_output == 'OTg3MA==')) {
3434
test_fail
3535
}
3636

3737
# Octets - bin 0x39383731
38-
test_output := %base64.encode(%{test_octets})
38+
test_output := %base64.encode(test_octets)
3939
if (!(test_output == 'OTg3MQ==')) {
4040
test_fail
4141
}
4242

4343
# IP Address - bin 0x39383732
44-
test_output := %base64.encode(%{test_ipaddr})
44+
test_output := %base64.encode(test_ipaddr)
4545
if (!(test_output == 'OTg3Mg==')) {
4646
test_fail
4747
}
4848

4949
# Integer - bin 0x39383734
50-
test_output := %base64.encode(%{test_int})
50+
test_output := %base64.encode(test_int)
5151
if (!(test_output == 'OTg3NA==')) {
5252
test_fail
5353
}
5454

5555
# ifid - bin 0x0000000039383737
56-
test_output := %base64.encode(%{test_ifid})
56+
test_output := %base64.encode(test_ifid)
5757
if (!(test_output == 'AAAAADk4Nzc=')) {
5858
test_fail
5959
}
6060

6161
# ipv6addr - bin 0x00000000000000000000000039383738
62-
test_output := %base64.encode(%{test_ipv6addr})
62+
test_output := %base64.encode(test_ipv6addr)
6363
if (!(test_output == 'AAAAAAAAAAAAAAAAOTg3OA==')) {
6464
test_fail
6565
}
6666

6767
# ipv6addrprefix - bin 0x008000000000000000000000000039383739
68-
test_output := %base64.encode(%{test_ipv6prefix})
68+
test_output := %base64.encode(test_ipv6prefix)
6969
if (!(test_output == 'AIAAAAAAAAAAAAAAAAA5ODc5')) {
7070
test_fail
7171
}
7272

7373
# byte - bin 0x3a
74-
test_output := %base64.encode(%{test_byte})
74+
test_output := %base64.encode(test_byte)
7575
if (!(test_output == 'Og==')) {
7676
test_fail
7777
}
7878

7979
# short - bin 0x373b
80-
test_output := %base64.encode(%{test_short})
80+
test_output := %base64.encode(test_short)
8181
if (!(test_output == 'Nzs=')) {
8282
test_fail
8383
}
8484

8585
# ethernet - bin 0x00003938373c
86-
test_output := %base64.encode(%{test_ether})
86+
test_output := %base64.encode(test_ether)
8787
if (!(test_output == 'AAA5ODc8')) {
8888
test_fail
8989
}
9090

9191
# integer64 - bin 0x100000003938373d
92-
test_output := %base64.encode(%{test_int64})
92+
test_output := %base64.encode(test_int64)
9393
if (!(test_output == 'EAAAADk4Nz0=')) {
9494
test_fail
9595
}
9696

9797
# ipv4prefix - bin 0x203938373e
98-
test_output := %base64.encode(%{test_ipv4prefix})
98+
test_output := %base64.encode(test_ipv4prefix)
9999
if (!(test_output == 'IDk4Nz4=')) {
100100
test_fail
101101
}
@@ -107,25 +107,25 @@ if (!(test_output == 'IDk4Nz4=')) {
107107
#}
108108

109109
# Regression test, this used to crash...
110-
test_octets := %base64.decode(Zm9v)
110+
test_octets := %base64.decode('Zm9v')
111111
if (!(test_octets == "foo")) {
112112
debug_request
113113
test_fail
114114
}
115115

116-
test_octets := %base64.decode(AIAAAAAAAAAAAAAAAAA5ODc5)
116+
test_octets := %base64.decode('AIAAAAAAAAAAAAAAAAA5ODc5')
117117
if (!(test_octets == 0x008000000000000000000000000039383739)) {
118118
test_fail
119119
}
120120

121121
# Regression tests
122-
test_octets := %base64.decode(5RNqNl8iYLbkCc7JhR8as4TtDDCX6otuuWtcja8rITUyx9zrnHSe9tTHGmKK)
122+
test_octets := %base64.decode('5RNqNl8iYLbkCc7JhR8as4TtDDCX6otuuWtcja8rITUyx9zrnHSe9tTHGmKK')
123123

124124
if (!(test_octets == 0xe5136a365f2260b6e409cec9851f1ab384ed0c3097ea8b6eb96b5c8daf2b213532c7dceb9c749ef6d4c71a628a)) {
125125
test_fail
126126
}
127127

128-
test_octets := %base64.decode(eHfXPKZ+2iv9cnMV1MOmE/moYYA1Uk5xTmw4aVlMYmtDYzdKaFI4YXM0VHRERENYNm90dXVXdGNqYThySVRVeXg5enJuSFNlOXRUSEdtS0s=)
128+
test_octets := %base64.decode('eHfXPKZ+2iv9cnMV1MOmE/moYYA1Uk5xTmw4aVlMYmtDYzdKaFI4YXM0VHRERENYNm90dXVXdGNqYThySVRVeXg5enJuSFNlOXRUSEdtS0s=')
129129

130130
if (!(test_octets == 0x7877d73ca67eda2bfd727315d4c3a613f9a8618035524e714e6c3869594c626b4363374a685238617334547444444358366f7475755774636a6138724954557978397a726e48536539745448476d4b4b)) {
131131
test_fail

src/tests/keywords/bin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ request += {
4343
NAS-Identifier = '0x030405'
4444
}
4545

46-
Class := %bin(%{NAS-Identifier[*]})
46+
Class := %bin(NAS-Identifier[*])
4747

4848
if (Class[#] != 2) {
4949
test_fail

src/tests/keywords/cast-time_delta

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if (diff != 60s) {
3939
#
4040
# Cast the time delta to milliseconds
4141
#
42-
num = %cast("ms", %{diff})
42+
num = %cast("ms", diff)
4343

4444
#
4545
# This results in 60, because the conversion to fr_value_box_cast() doesn't pass dst->enumv?

src/tests/keywords/cbor

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
octets cbor
22
string foo
33

4-
cbor = %cbor.encode(User-Name)
4+
#
5+
# @todo - this should be a dcursor
6+
#
7+
cbor = %cbor.encode('User-Name')
58

69
#
710
# 9f array of indefinite length
@@ -28,7 +31,7 @@ if (User-Name) {
2831
#
2932
# @todo - change this to be configurable :(
3033
#
31-
%cbor.decode(%{cbor})
34+
%cbor.decode(cbor)
3235

3336
if (User-Name != "bob") {
3437
test_fail

src/tests/keywords/cmp-list-empty

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# {} == {} --> true
55
#
6-
if !(%test.fail() == %test.fail()) {
6+
if (%test.fail() != %test.fail()) {
77
test_fail
88
}
99

src/tests/keywords/date

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,23 @@ date test_date
1111
test_integer := 1506101100
1212

1313
# Convert to string representation
14-
result_string1 := %date(%{test_integer})
14+
result_string1 := %date(test_integer)
1515

1616
# Some systems report GMT some UTC...
1717
if (!(result_string1 == "Fri 22 Sep 17:25:00 GMT 2017")) && (!(result_string1 == "Fri 22 Sep 17:25:00 UTC 2017")) {
1818
test_fail
1919
}
2020

2121
# Convert string to integer
22-
result_integer := %date(%{result_string1})
22+
result_integer := %date(result_string1)
2323

2424

2525
if (!(result_integer == test_integer)) {
2626
test_fail
2727
}
2828

2929
# Compare two methods of reading request timestamp in local timezone
30-
result_string1 := %localdate(request)
30+
result_string1 := %localdate('request')
3131
result_string2 := %S
3232

3333
if (!(result_string1 == result_string2)) {
@@ -37,23 +37,23 @@ if (!(result_string1 == result_string2)) {
3737
# Convert different string format
3838
result_string1 := "2017-09-22 17:25:00"
3939

40-
result_integer := %sqldate(%{result_string1})
40+
result_integer := %sqldate(result_string1)
4141

4242
if (!(result_integer == test_integer)) {
4343
test_fail
4444
}
4545

4646
# Use a date attribute
4747
test_date := 1659985459
48-
result_string1 := %sqldate(%{test_date})
48+
result_string1 := %sqldate(test_date)
4949

5050
if !(result_string1 == '2022-08-08 19:04:19') {
5151
test_fail
5252
}
5353

5454
# Invalid format
5555
result_string1 := '201-32-22 17:25:00'
56-
result_string2 := %sqldate(%{result_string1})
56+
result_string2 := %sqldate(result_string1)
5757

5858
# This shouldn't exist, as the RHS above is NULL, and therefore the assignment will fail
5959
if (result_string2) {
@@ -66,7 +66,7 @@ if (!(Module-Failure-Message == "Failed to parse time string \"201-32-22 17:25:0
6666

6767
# Invalid type
6868
NAS-IP-Address := "192.168.1.1"
69-
result_string2 := %date(%{NAS-IP-Address})
69+
result_string2 := %date(NAS-IP-Address)
7070

7171
if (result_string2) {
7272
test_fail

src/tests/keywords/debug

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ if (!(%debug(3) == 4)) {
1212
}
1313

1414
# Call with NULL arg, should report current level
15-
if (!(%debug(%{dummy_string}) == 3)) {
15+
if (!(%debug(dummy_string) == 3)) {
1616
test_fail
1717
}
1818

1919
# ...and again
20-
if (!(%debug(%{dummy_string}) == 3)) {
20+
if (!(%debug(dummy_string) == 3)) {
2121
test_fail
2222
}
2323

src/tests/keywords/edit-eval-rhs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uint32 foo
33
Tmp-Integer-0 := 1
44
Tmp-Integer-1 := { 3, 6, 9 }
55

6-
foo = %eval(%{'%{Tmp-Integer-1[' + "%{Tmp-Integer-0}" + ']}'})
6+
foo = %eval('%{Tmp-Integer-1[' + "%{Tmp-Integer-0}" + ']}')
77

88
if (foo != 6) {
99
test_fail

0 commit comments

Comments
 (0)