Skip to content

Commit

Permalink
DONT MERGE
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Apr 19, 2024
1 parent c138f63 commit a7bd8c8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmake/SetupGo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This code is licensed under the terms of the MIT License.
# Copyright (c) 2024 Alfi Maulana

include_guard(GLOBAL)

# Sets up the latest version of Go within this project.
function(setup_go)
file(MAKE_DIRECTORY ${CMAKE_BUILD_DIR}/_deps)
file(
DOWNLOAD https://go.dev/dl/go1.22.2.linux-amd64.tar.gz ${CMAKE_BUILD_DIR}/_deps/go.tar.gz
EXPECTED_MD5 f64eb5791a9dab9cbcdf6549b9583280
)

execute_process(COMMAND tar -xf ${CMAKE_BUILD_DIR}/_deps/go.tar.gz -C ${CMAKE_BUILD_DIR}/_deps)

set(GO_EXECUTABLE ${CMAKE_BUILD_DIR}/_deps/go/bin/go PARENT_SCOPE)
endfunction()
6 changes: 6 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ function(add_cmake_test FILE)
NAME ${NAME}
COMMAND ${CMAKE_COMMAND}
-D CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}
-D CMAKE_BUILD_DIR=${CMAKE_CURRENT_SOURCE_DIR}/build
-D TEST_MATCHES=^${NAME}$
-P ${CMAKE_CURRENT_SOURCE_DIR}/${FILE}
)
Expand All @@ -15,3 +16,8 @@ add_cmake_test(
"Create directory recursively"
# Add more test cases here.
)

add_cmake_test(
cmake/SetupGoTest.cmake
"Set up latest version of Go"
)
18 changes: 18 additions & 0 deletions test/cmake/SetupGoTest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Matches everything if not defined
if(NOT TEST_MATCHES)
set(TEST_MATCHES ".*")
endif()

set(TEST_COUNT 0)

if("Set up latest version of Go" MATCHES ${TEST_MATCHES})
math(EXPR TEST_COUNT "${TEST_COUNT} + 1")

include(SetupGo)

setup_go()
endif()

if(TEST_COUNT LESS_EQUAL 0)
message(FATAL_ERROR "Nothing to test with: ${TEST_MATCHES}")
endif()

0 comments on commit a7bd8c8

Please # to comment.