Skip to content

Commit f46c78e

Browse files
committed
CI: Add Elixir pack_test
Need the ability to add modules to Elixir testing eg for GenServer tests (atomvm#1476) etc. Signed-off-by: Peter M <petermm@gmail.com>
1 parent 75d6d2d commit f46c78e

File tree

4 files changed

+93
-2
lines changed

4 files changed

+93
-2
lines changed

CMakeModules/BuildElixir.cmake

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,64 @@ macro(pack_runnable avm_name main)
9494
add_dependencies(${avm_name} ${avm_name}_main ${ARCHIVE_TARGETS} PackBEAM)
9595

9696
endmacro()
97+
98+
99+
macro(pack_test avm_name main)
100+
find_package(Elixir REQUIRED)
101+
102+
# Compile the main module
103+
add_custom_command(
104+
OUTPUT Elixir.${main}.beam
105+
COMMAND elixirc ${CMAKE_CURRENT_SOURCE_DIR}/${main}.ex
106+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${main}.ex
107+
COMMENT "Compiling ${main}.ex"
108+
VERBATIM
109+
)
110+
111+
add_custom_target(
112+
${avm_name}_main
113+
DEPENDS Elixir.${main}.beam
114+
)
115+
116+
# Compile test modules
117+
foreach(module_name ${ARGN})
118+
add_custom_command(
119+
OUTPUT Elixir.${module_name}.beam
120+
COMMAND elixirc ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.ex
121+
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${module_name}.ex
122+
COMMENT "Compiling ${module_name}.ex"
123+
VERBATIM
124+
)
125+
set(TEST_BEAMS ${TEST_BEAMS} Elixir.${module_name}.beam)
126+
endforeach()
127+
128+
add_custom_target(
129+
${avm_name}_tests
130+
DEPENDS ${TEST_BEAMS}
131+
)
132+
133+
if(AVM_RELEASE)
134+
set(INCLUDE_LINES "")
135+
else()
136+
set(INCLUDE_LINES "-i")
137+
endif()
138+
139+
# Set up standard libraries
140+
set(ARCHIVE_TARGETS estdlib eavmlib exavmlib etest)
141+
foreach(archive_name ${ARCHIVE_TARGETS})
142+
if(${archive_name} STREQUAL "exavmlib")
143+
set(ARCHIVES ${ARCHIVES} ${CMAKE_BINARY_DIR}/libs/${archive_name}/lib/${archive_name}.avm)
144+
else()
145+
set(ARCHIVES ${ARCHIVES} ${CMAKE_BINARY_DIR}/libs/${archive_name}/src/${archive_name}.avm)
146+
endif()
147+
endforeach()
148+
149+
add_custom_target(
150+
${avm_name} ALL
151+
COMMAND ${CMAKE_BINARY_DIR}/tools/packbeam/PackBEAM ${INCLUDE_LINES} ${avm_name}.avm Elixir.${main}.beam ${TEST_BEAMS} ${ARCHIVES}
152+
COMMENT "Packing test ${avm_name}.avm"
153+
VERBATIM
154+
)
155+
add_dependencies(${avm_name} ${avm_name}_main ${avm_name}_tests ${ARCHIVE_TARGETS} PackBEAM)
156+
157+
endmacro()

tests/libs/exavmlib/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ project(test_exavmlib)
2222

2323
include(BuildElixir)
2424

25-
pack_runnable(Tests Tests estdlib eavmlib exavmlib etest)
25+
set(TEST_MODULES
26+
Some.Submodule
27+
)
28+
29+
pack_test(Tests Tests ${TEST_MODULES})

tests/libs/exavmlib/Some.Submodule.ex

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#
2+
# This file is part of AtomVM.
3+
#
4+
# Copyright 2024 Davide Bettio <davide@uninstall.it>
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+
defmodule Some.Submodule do
22+
def start do
23+
:ok
24+
end
25+
end

tests/libs/exavmlib/Tests.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ defmodule Tests do
2828

2929
def start() do
3030
:ok = IO.puts("Running Elixir tests")
31+
:ok = Some.Submodule.start()
3132
:ok = test_enum()
3233
:ok = test_exception()
3334
:ok = test_chars_protocol()
@@ -122,7 +123,7 @@ defmodule Tests do
122123

123124
# Enum.flat_map
124125
[:a, :a, :b, :b, :c, :c] = Enum.flat_map([:a, :b, :c], fn x -> [x, x] end)
125-
[1, 2, 3, 4, 5, 6] = Enum.flat_map([{1, 3}, {4, 6}], fn {x, y} -> x..y end)
126+
[1, 2, 3, 4, 5, 6] = Enum.flat_map([{1, 3}, {4, 6}], fn {x, y} -> Range.new(x, y) end)
126127
[[:a], [:b], [:c]] = Enum.flat_map([:a, :b, :c], fn x -> [[x]] end)
127128

128129
# Enum.join

0 commit comments

Comments
 (0)