Skip to content

Commit 5acb1dd

Browse files
committed
CI: Test OTP29 multi value comprehension
https://ampcode.com/threads/T-019c756b-07dd-745f-86c2-c609e54a434b Signed-off-by: Peter M <petermm@gmail.com>
1 parent 270bbc8 commit 5acb1dd

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

tests/erlang_tests/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ compile_erlang(reraise_reraiser)
636636
compile_erlang(reraise_raiser)
637637

638638
compile_erlang(stacktrace_function_args)
639+
compile_erlang(test_multi_value_comprehension)
639640

640641
if(Erlang_VERSION VERSION_GREATER_EQUAL "23")
641642
set(OTP23_OR_GREATER_TESTS
@@ -1183,6 +1184,8 @@ set(erlang_test_beams
11831184

11841185
stacktrace_function_args.beam
11851186

1187+
test_multi_value_comprehension.beam
1188+
11861189
${OTP23_OR_GREATER_TESTS}
11871190
${OTP25_OR_GREATER_TESTS}
11881191
)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2025 Peter Madsen-Mygdal
5+
%
6+
% Licensed under the Apache License, Version 2.0 (the "License");
7+
% you may not use this file except in compliance with the License.
8+
% You may obtain a copy of the License at
9+
%
10+
% http://www.apache.org/licenses/LICENSE-2.0
11+
%
12+
% Unless required by applicable law or agreed to in writing, software
13+
% distributed under the License is distributed on an "AS IS" BASIS,
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
% See the License for the specific language governing permissions and
16+
% limitations under the License.
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
21+
-module(test_multi_value_comprehension).
22+
23+
-export([start/0, id/1]).
24+
25+
%% Test multi-valued comprehensions (EEP 78, OTP 29+)
26+
27+
-ifdef(OTP_RELEASE).
28+
-if(?OTP_RELEASE >= 29).
29+
-define(OTP29_OR_LATER, true).
30+
-endif.
31+
-endif.
32+
33+
-ifdef(OTP29_OR_LATER).
34+
35+
start() ->
36+
ok = test_basic_multi_value(),
37+
ok = test_single_value(),
38+
ok = test_multi_value_with_filter(),
39+
ok = test_multi_value_binary_comprehension(),
40+
0.
41+
42+
test_basic_multi_value() ->
43+
[-1, 1, -2, 2, -3, 3] = [-I, I || I <- ?MODULE:id([1, 2, 3])],
44+
ok.
45+
46+
test_single_value() ->
47+
[1, 2, 3] = [I || I <- ?MODULE:id([1, 2, 3])],
48+
ok.
49+
50+
test_multi_value_with_filter() ->
51+
[-2, 2] = [-I, I || I <- ?MODULE:id([1, 2, 3]), I rem 2 =:= 0],
52+
ok.
53+
54+
test_multi_value_binary_comprehension() ->
55+
<<1, 2, 3, 4>> = <<<<I, (I + 1)>> || I <- ?MODULE:id([1, 3])>>,
56+
ok.
57+
58+
-else.
59+
60+
start() ->
61+
0.
62+
63+
-endif.
64+
65+
id(X) -> X.

tests/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ struct Test tests[] = {
564564
TEST_CASE(test_op_bs_start_match),
565565
TEST_CASE(test_op_bs_create_bin),
566566

567+
TEST_CASE(test_multi_value_comprehension),
568+
567569
TEST_CASE(test_code_server_nifs),
568570

569571
// noisy tests, keep them at the end

0 commit comments

Comments
 (0)