Skip to content

Commit

Permalink
Add tests and publish actions (#5)
Browse files Browse the repository at this point in the history
* Add tests and publish actions
* Only preapproved build types are allowed on Windows
  • Loading branch information
Erik Corry authored Jan 14, 2024
1 parent dd2e5a1 commit 78e6e6b
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
File renamed without changes.

0 comments on commit 78e6e6b

Please sign in to comment.