diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..5bacb9a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" # Necessary to update action hashs + directory: "/" + schedule: + interval: "weekly" + # Allow up to 3 opened pull requests for github-actions versions + open-pull-requests-limit: 3 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..976145e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,57 @@ +name: CI + +on: + push: + release: + types: [published] + +env: + TOIT_VERSION: v2.0.0-alpha.121 + +jobs: + build: + strategy: + matrix: + os: [ ubuntu-latest, windows-latest, macos-latest ] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup Toit + id: setup-toit + uses: toitlang/action-setup@v1 + with: + toit-version: ${{ env.TOIT_VERSION }} + + # Fetch the dependencies. Different for each platform. + - name: Install dependencies - Linux + if: runner.os == 'Linux' + run: | + sudo apt-get update + cmake --version + - name: Install dependencies - macOS + if: runner.os == 'macOS' + run: | + cmake --version + - name: Install dependencies - Windows + if: runner.os == 'Windows' + run: | + cmake --version + + - name: Run cmake + shell: bash + run: | + make rebuild-cmake + cmake build + + - name: Install packages + run: | + make install-pkgs + + - name: Test + run: | + make test diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..b137520 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,28 @@ +# Zero-Clause BSD License + +# Copyright (C) 2023 Toitware ApS. + +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted. + +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +# PERFORMANCE OF THIS SOFTWARE. + +name: Publish package +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - 'v[0-9]+.[0-9]+.[0-9]+-*' +jobs: + create-release: + name: Create new release + runs-on: ubuntu-latest + steps: + - name: Publish + uses: toitlang/pkg-publish@v1.4.0 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0a58e36 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +# Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +cmake_minimum_required(VERSION 3.22) + +# NONE means skip testing the C compiler. +project(case NONE) + +enable_testing() +add_subdirectory(tests) diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6288127 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +.PHONY: all +all: test + +.PHONY: install-pkgs +install-pkgs: rebuild-cmake + cmake --build build --target install-pkgs + +.PHONY: test +test: install-pkgs rebuild-cmake + cmake --build build --target check + +# We rebuild the cmake file all the time. +# We use "glob" in the cmakefile, and wouldn't otherwise notice if a new +# file (for example a test) was added or removed. +# It takes <1s on Linux to run cmake, so it doesn't hurt to run it frequently. +.PHONY: rebuild-cmake +rebuild-cmake: + mkdir -p build + cmake -B build -DCMAKE_BUILD_TYPE=Release diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..685b3c6 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,55 @@ +# Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +file(GLOB TESTS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*-test.toit") + +set(TOITRUN toit.run${CMAKE_EXECUTABLE_SUFFIX} CACHE FILEPATH "The executable used to run the tests") +set(TOITPKG toit.pkg${CMAKE_EXECUTABLE_SUFFIX} CACHE FILEPATH "The executable used to install the packages") +set(TEST_TIMEOUT 40 CACHE STRING "The maximal amount of time each test is allowed to run") +set(SLOW_TEST_TIMEOUT 200 CACHE STRING "The maximal amount of time each slow test is allowed to run") + +message("TPKG: ${TOITPKG}") +add_custom_target( + "install-pkgs" + COMMAND "${TOITPKG}" install + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} +) + +include(ProcessorCount) +ProcessorCount(NUM_CPU) + +add_custom_target( + check + COMMAND ${CMAKE_CTEST_COMMAND} -j${NUM_CPU} --output-on-failure -C Release + USES_TERMINAL +) + +set(TEST_PREFIX "") +include(fail.cmake OPTIONAL) + +message("Failing tests: ${FAILING_TESTS}") +message("Skipped tests: ${SKIP_TESTS}") + +foreach(file ${TESTS}) + set(test_name "/tests/${file}") + if("${test_name}" IN_LIST SKIP_TESTS) + continue() + endif() + + add_test( + NAME "${test_name}" + COMMAND ${TOITRUN} "tests/${file}" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/.. + ) + + if ("${file}" MATCHES "slow.toit") + set_tests_properties(${test_name} PROPERTIES TIMEOUT ${SLOW_TEST_TIMEOUT}) + else() + set_tests_properties(${test_name} PROPERTIES TIMEOUT ${TEST_TIMEOUT}) + endif() + + if("${test_name}" IN_LIST FAILING_TESTS) + set_tests_properties("${test_name}" PROPERTIES WILL_FAIL TRUE) + endif() +endforeach() diff --git a/tests/case.toit b/tests/case-test.toit similarity index 100% rename from tests/case.toit rename to tests/case-test.toit