From 8ed20f50b976420abc6868693c4d2fcffa19159c Mon Sep 17 00:00:00 2001 From: James Ball Date: Sat, 10 Feb 2024 12:05:19 +0000 Subject: [PATCH] Add test suite --- .github/workflows/build.yaml | 7 ++++ Source/TestMain.cpp | 48 ++++++++++++++++++++++++ ci/build.sh | 44 ---------------------- ci/setup-env.sh | 45 ++++++++++++++++++++++ ci/test.sh | 41 ++++++++++++++++++++ osci-render-test.jucer | 73 ++++++++++++++++++++++++++++++++++++ 6 files changed, 214 insertions(+), 44 deletions(-) create mode 100644 Source/TestMain.cpp create mode 100644 ci/setup-env.sh create mode 100644 ci/test.sh create mode 100644 osci-render-test.jucer diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1c8e7a2..48b2f7c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,6 +3,7 @@ on: push: branches: - release + - 3d-audio jobs: build-linux: name: Build Linux @@ -18,6 +19,8 @@ jobs: - name: "Run script" run: | export OS="linux" + ./ci/setup-env.sh + ./ci/test.sh ./ci/build.sh shell: bash - name: Upload Artifact @@ -40,6 +43,8 @@ jobs: - name: "Run script" run: | export OS="mac" + ./ci/setup-env.sh + ./ci/test.sh ./ci/build.sh shell: bash - name: Upload Artifact @@ -62,6 +67,8 @@ jobs: - name: "Run script" run: | export OS="win" + ./ci/setup-env.sh + ./ci/test.sh ./ci/build.sh shell: bash - name: Upload Artifact diff --git a/Source/TestMain.cpp b/Source/TestMain.cpp new file mode 100644 index 0000000..abb91df --- /dev/null +++ b/Source/TestMain.cpp @@ -0,0 +1,48 @@ +#include + +class MyTest : public juce::UnitTest { +public: + MyTest() : juce::UnitTest("Foobar testing") {} + + void runTest() override { + beginTest("Part 1"); + + expect(true); + + beginTest("Part 2"); + + expect(true); + } +}; + +class MyTest2 : public juce::UnitTest { +public: + MyTest2() : juce::UnitTest("Foobar testing 2") {} + + void runTest() override { + beginTest("Part A"); + + expect(true); + + beginTest("Part B"); + + expect(false); + } +}; + +static MyTest2 test2; + +int main(int argc, char* argv[]) { + juce::UnitTestRunner runner; + + runner.runAllTests(); + + for (int i = 0; i < runner.getNumResults(); ++i) { + const juce::UnitTestRunner::TestResult* result = runner.getResult(i); + if (result->failures > 0) { + return 1; + } + } + + return 0; +} diff --git a/ci/build.sh b/ci/build.sh index fbc3cb3..d788224 100755 --- a/ci/build.sh +++ b/ci/build.sh @@ -2,50 +2,6 @@ PLUGIN="osci-render" -# linux specific stiff -if [ $OS = "linux" ]; then - sudo apt-get update - sudo apt-get install clang git ladspa-sdk freeglut3-dev g++ libasound2-dev libcurl4-openssl-dev libfreetype6-dev libjack-jackd2-dev libx11-dev libxcomposite-dev libxcursor-dev libxinerama-dev libxrandr-dev mesa-common-dev webkit2gtk-4.0 juce-tools xvfb -fi - -ROOT=$(cd "$(dirname "$0")/.."; pwd) -cd "$ROOT" -echo "$ROOT" -rm -Rf bin -mkdir bin - -BRANCH=${GITHUB_REF##*/} -echo "$BRANCH" - -cd "$ROOT/ci" -rm -Rf bin -mkdir bin - -# Get the Projucer -cd "$ROOT/ci/bin" -PROJUCER_OS=$OS -if [ "$OS" = "win" ]; then - PROJUCER_OS="windows" -elif [ "$OS" = "mac" ]; then - PROJUCER_OS="osx" -fi - -curl -s -S -L "https://api.juce.com/api/v1/download/juce/latest/$PROJUCER_OS" -o Projucer.zip -unzip Projucer.zip - -# Set Projucer path based on OS -if [ "$OS" = "mac" ]; then - PROJUCER_PATH="$ROOT/ci/bin/JUCE/Projucer.app/Contents/MacOS/Projucer" -elif [ "$OS" = "linux" ]; then - PROJUCER_PATH="$ROOT/ci/bin/JUCE/Projucer" -else - PROJUCER_PATH="$ROOT/ci/bin/JUCE/Projucer.exe" -fi - -# Set global path -GLOBAL_PATH_COMMAND="$PROJUCER_PATH --set-global-search-path $PROJUCER_OS 'defaultJuceModulePath' '$ROOT/ci/bin/JUCE/modules'" -eval "$GLOBAL_PATH_COMMAND" - # Resave jucer file RESAVE_COMMAND="$PROJUCER_PATH --resave '$ROOT/$PLUGIN.jucer'" eval "$RESAVE_COMMAND" diff --git a/ci/setup-env.sh b/ci/setup-env.sh new file mode 100644 index 0000000..7c73c84 --- /dev/null +++ b/ci/setup-env.sh @@ -0,0 +1,45 @@ +#!/bin/bash -e + +# linux specific stiff +if [ $OS = "linux" ]; then + sudo apt-get update + sudo apt-get install clang git ladspa-sdk freeglut3-dev g++ libasound2-dev libcurl4-openssl-dev libfreetype6-dev libjack-jackd2-dev libx11-dev libxcomposite-dev libxcursor-dev libxinerama-dev libxrandr-dev mesa-common-dev webkit2gtk-4.0 juce-tools xvfb +fi + +ROOT=$(cd "$(dirname "$0")/.."; pwd) +cd "$ROOT" +echo "$ROOT" +rm -Rf bin +mkdir bin + +BRANCH=${GITHUB_REF##*/} +echo "$BRANCH" + +cd "$ROOT/ci" +rm -Rf bin +mkdir bin + +# Get the Projucer +cd "$ROOT/ci/bin" +PROJUCER_OS=$OS +if [ "$OS" = "win" ]; then + PROJUCER_OS="windows" +elif [ "$OS" = "mac" ]; then + PROJUCER_OS="osx" +fi + +curl -s -S -L "https://api.juce.com/api/v1/download/juce/latest/$PROJUCER_OS" -o Projucer.zip +unzip Projucer.zip + +# Set Projucer path based on OS +if [ "$OS" = "mac" ]; then + PROJUCER_PATH="$ROOT/ci/bin/JUCE/Projucer.app/Contents/MacOS/Projucer" +elif [ "$OS" = "linux" ]; then + PROJUCER_PATH="$ROOT/ci/bin/JUCE/Projucer" +else + PROJUCER_PATH="$ROOT/ci/bin/JUCE/Projucer.exe" +fi + +# Set global path +GLOBAL_PATH_COMMAND="$PROJUCER_PATH --set-global-search-path $PROJUCER_OS 'defaultJuceModulePath' '$ROOT/ci/bin/JUCE/modules'" +eval "$GLOBAL_PATH_COMMAND" diff --git a/ci/test.sh b/ci/test.sh new file mode 100644 index 0000000..9bab5ad --- /dev/null +++ b/ci/test.sh @@ -0,0 +1,41 @@ +#!/bin/bash -e + +PLUGIN="osci-render-test" + +# Resave jucer file +RESAVE_COMMAND="$PROJUCER_PATH --resave '$ROOT/$PLUGIN.jucer'" +eval "$RESAVE_COMMAND" + +# Build mac version +if [ "$OS" = "mac" ]; then + cd "$ROOT/Builds/Test/MacOSX" + xcodebuild -configuration Release || exit 1 + cd "build/Release" + # Run the test using the .app file + open -a "$PLUGIN.app" +fi + +# Build linux version +if [ "$OS" = "linux" ]; then + cd "$ROOT/Builds/LinuxMakefile" + make CONFIG=Release + + cd build + # Run the test using the binary + xvfb-run -a -s "-screen 0 1280x720x24" ./$PLUGIN +fi + +# Build Win version +if [ "$OS" = "win" ]; then + VS_WHERE="C:/Program Files (x86)/Microsoft Visual Studio/Installer/vswhere.exe" + + MSBUILD_EXE=$("$VS_WHERE" -latest -requires Microsoft.Component.MSBuild -find "MSBuild\**\Bin\MSBuild.exe") + echo $MSBUILD_EXE + + cd "$ROOT/Builds/VisualStudio2022" + "$MSBUILD_EXE" "$PLUGIN.sln" "//p:VisualStudioVersion=16.0" "//m" "//t:Build" "//p:Configuration=Release" "//p:Platform=x64" "//p:PreferredToolArchitecture=x64" + + cd "x64/Release/Standalone Plugin" + # Run the test using the .exe file + ./$PLUGIN.exe +fi diff --git a/osci-render-test.jucer b/osci-render-test.jucer new file mode 100644 index 0000000..042c17c --- /dev/null +++ b/osci-render-test.jucer @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +