Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to GitHub Actions and add test infrastructure with Catch2 #96

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Actions

on:
push:
branches: [master]
pull_request:
branches: [master]

env:
BUILD_TYPE: Release

jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- uses: actions/checkout@v2
- uses: actions/checkout@v4

with:
submodules: recursive
- name: Install dependencies
run: sudo apt-get install cmake g++
- name: Configure CMake
run: cmake -S . -B build -DMIDIFILE_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build project
run: cmake --build build
- name: Run tests
run: ./build/midifile_test

windows:
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- uses: actions/checkout@v2
- uses: actions/checkout@v4

with:
submodules: recursive
- name: Configure CMake
run: cmake -S . -B build -DMIDIFILE_BUILD_TESTS=ON -G "Visual Studio 16 2019" -A x64
- name: Build project
run: cmake --build build --config ${{env.BUILD_TYPE}}
- name: Run tests
run: ./build/${{env.BUILD_TYPE}}/midifile_test.exe

macos:
runs-on: macos-11
steps:
- uses: actions/checkout@v2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- uses: actions/checkout@v2
- uses: actions/checkout@v4

with:
submodules: recursive
- name: Configure CMake
run: cmake -S . -B build -DMIDIFILE_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build project
run: cmake --build build
- name: Run tests
run: ./build/midifile_test
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

.*
!.gitignore
_site
temp
Expand All @@ -24,3 +22,4 @@ err
*.idb
*.ilk
*.opendb
build*
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "Catch2"]
path = external_libraries/Catch2
url = https://github.com/catchorg/Catch2.git
branch = v2.x
81 changes: 0 additions & 81 deletions .travis.yml

This file was deleted.

10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8)
cmake_minimum_required(VERSION 3.0)

project(midifile C CXX)
set(CMAKE_CXX_STANDARD 11)
Expand Down Expand Up @@ -70,6 +70,14 @@ add_library(midifile STATIC ${SRCS} ${HDRS})
## Programs:
##

if(MIDIFILE_BUILD_TESTS)
add_executable(midifile_test test/test.cpp)
target_include_directories(
midifile_test PRIVATE external_libraries/Catch2/single_include/
)
target_link_libraries(midifile_test midifile)
endif()

add_executable(80off tools/80off.cpp)
add_executable(asciimidi tools/asciimidi.cpp)
add_executable(binasc tools/binasc.cpp)
Expand Down
45 changes: 0 additions & 45 deletions appveyor.yml

This file was deleted.

1 change: 1 addition & 0 deletions external_libraries/Catch2
Submodule Catch2 added at 958944
46 changes: 46 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <sstream>
#include <vector>
#include <tuple>

#define CATCH_CONFIG_MAIN
#include "catch2/catch.hpp"

#include "MidiFile.h"

TEST_CASE("Writing and reading an empty MIDI file works") {
smf::MidiFile midifile1;
REQUIRE(midifile1.size() == 1);
std::stringstream stream;
midifile1.write(stream);
REQUIRE(midifile1.status());
smf::MidiFile midifile2;
midifile2.read(stream);
REQUIRE(midifile2.size() == 1);
REQUIRE(midifile2.status());
}

TEST_CASE("Writing and reading a MIDI file with note on and note off messages works") {
smf::MidiFile midifile1;

std::vector<uint8_t> noteOnMessage = { 0x90, 0x3c, 0x7F };
smf::MidiEvent noteOn(0, 1, noteOnMessage);
std::vector<uint8_t> noteOffMessage = { 0x80, 0x3c, 0x7F };
smf::MidiEvent noteOff(100, 1, noteOffMessage);
std::vector<uint8_t> trackEndMessage = { 0xFF, 0x2F, 0x00 };
smf::MidiEvent trackEnd(200, 1, trackEndMessage);
midifile1[0].push_back(noteOn);
midifile1[0].push_back(noteOff);
midifile1[0].push_back(trackEnd);

std::stringstream stream;
midifile1.write(stream);
REQUIRE(midifile1.status());
smf::MidiFile midifile2;
midifile2.read(stream);

REQUIRE(midifile1.size() == midifile2.size());
REQUIRE(midifile1[0].size() == midifile2[0].size());
for (int i = 0; i < midifile1[0].size(); i++) {
REQUIRE(midifile1[0][i] == midifile2[0][i]);
}
}