Skip to content

Commit

Permalink
run basic CLI test for every build
Browse files Browse the repository at this point in the history
This just tests that the exe can be run, that it understands
command line parameters, reads stdin, and prints to stdout,
on Linux, macOS, and Windows
  • Loading branch information
windytan committed Jul 19, 2024
1 parent a4b27bb commit 1c1d1fa
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 5 deletions.
26 changes: 21 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,47 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install dependencies (apt)
run: sudo apt install python3-pip ninja-build libsndfile1-dev libliquid-dev nlohmann-json3-dev
run: sudo apt install python3-pip ninja-build libsndfile1-dev libliquid-dev nlohmann-json3-dev perl
- name: Install meson (pip3)
run: pip3 install --user meson
- name: meson setup
run: meson setup -Dwerror=true build
- name: compile
run: cd build && meson compile
- name: Test command-line interface
run: perl test/cli.pl build/redsea

build-ubuntu-20-04:
runs-on: ubuntu-20.04

steps:
- uses: actions/checkout@v4
- name: Install dependencies (apt)
run: sudo apt install python3-pip ninja-build libsndfile1-dev libliquid-dev nlohmann-json3-dev
run: sudo apt install python3-pip ninja-build libsndfile1-dev libliquid-dev nlohmann-json3-dev perl
- name: Install meson (pip3)
run: pip3 install --user meson
- name: meson setup
run: meson setup -Dwerror=true build
- name: compile
run: cd build && meson compile
- name: Test command-line interface
run: perl test/cli.pl build/redsea

build-ubuntu-deb-package:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Install Debian packaging tools
run: sudo apt install build-essential devscripts debhelper equivs
run: sudo apt install build-essential devscripts debhelper equivs perl
- name: Install Build-Depends
run: sudo mk-build-deps --install --tool 'apt-get --yes'
- name: Build .deb
run: debuild -us -uc
- name: Install .deb
run: sudo dpkg -i ../redsea_*.deb
- name: Test command-line interface
run: perl test/cli.pl redsea --installed

build-debian-oldoldstable:
runs-on: ubuntu-latest
Expand All @@ -57,27 +63,31 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install dependencies (apt-get)
run: apt-get update && apt-get -y install python3-pip ninja-build build-essential libsndfile1-dev libliquid-dev nlohmann-json3-dev
run: apt-get update && apt-get -y install python3-pip ninja-build build-essential libsndfile1-dev libliquid-dev nlohmann-json3-dev perl
- name: Install meson (pip3)
run: pip3 install --user meson
- name: meson setup
run: export PATH=$PATH:$HOME/.local/bin && meson setup -Dwerror=true build
- name: compile
run: export PATH=$PATH:$HOME/.local/bin && cd build && meson compile
- name: Test command-line interface
run: perl test/cli.pl build/redsea

build-test-macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- name: Install dependencies (brew)
run: brew install meson libsndfile liquid-dsp nlohmann-json catch2
run: brew install meson libsndfile liquid-dsp nlohmann-json catch2 perl
- name: meson setup
run: meson setup -Dwerror=true -Db_sanitize=address,undefined -Db_lundef=false build
- name: compile
run: cd build && meson compile
- name: test
run: cd build && meson test
- name: Test command-line interface
run: perl test/cli.pl build/redsea

build-windows-msys2-mingw:
runs-on: windows-latest
Expand Down Expand Up @@ -110,6 +120,9 @@ jobs:
shell: msys2 {0}
run: |
meson setup -Dwerror=true build && cd build && meson compile
- name: Test command-line interface
shell: msys2 {0}
run: perl test/cli.pl build/redsea.exe

build-windows-cygwin:
runs-on: windows-latest
Expand Down Expand Up @@ -150,3 +163,6 @@ jobs:
- name: Build redsea
shell: C:\cygwin\bin\bash.exe -eo pipefail '{0}'
run: meson setup -Dwerror=true build && cd build && meson compile
- name: Test command-line interface
shell: C:\cygwin\bin\bash.exe -eo pipefail '{0}'
run: perl test/cli.pl build/redsea
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ jobs:
shell: msys2 {0}
run: |
meson setup -Dwerror=true build && cd build && meson compile
- name: Test command-line interface
shell: msys2 {0}
run: perl test/cli.pl build/redsea.exe
- name: Package DLLs
shell: msys2 {0}
run: >-
Expand Down
108 changes: 108 additions & 0 deletions test/cli.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Basic tests to see if the CLI works at all. Correctness is tested elsewhere.
# Usage: perl cli.pl path/to/redsea.exe [--installed]

use warnings;
use strict;
use IPC::Cmd qw(can_run);
use Carp;

my $exec_name = $ARGV[0] // 'build/redsea';
my $is_installed = ( $ARGV[1] // "" ) eq '--installed';
my $print_even_if_successful = 1;
my $has_failures = 0;
my $test_input_file = 'redsea-test-input';
my $test_output_file = 'redsea-test-output';

exit main();

sub main {
testExeRunnable();
testInputBits();

return $has_failures;
}

sub testExeRunnable {
req( $is_installed ? can_run($exec_name) : -f $exec_name && -x $exec_name,
'Executable is found' );

return;
}

sub testInputBits {
createTestInputFile( "001\n"
. "1110110110111010011100010101001000010100001110000010\n"
. "0010001011100001011100110000100101100000111100111110\n"
. "0010000001100101101101001101101001001000000110111110\n"
. "0010001011100001011100110000000101100010010011100000\n"
. "1010011010110011111010010101010011010011000101010101\n"
. "0010001011100001011100110000100101100001001010101000\n"
. "0111001101100001010000011001100001000011010111000111\n"
. "001000" );

for my $arg ( '-b', '--input bits', '--input-bits' ) {
TestName( 'Option: ' . $arg );
unlink($test_output_file);
runWithArgs( $arg . q{<} . $test_input_file . q{>} . $test_output_file );
open( my $test_output, q{<}, $test_output_file ) or croak $!;
my $result =
( ( <$test_output> // "" ) =~
/\{"pi":"0x22E1","group":"2A","tp":true,"prog_type":"Easy listening"\}/ );
close $test_output;
check( $result, 'decodes ASCII binary' );
}

return;
}

# Just print the test name
sub TestName {
my ($name) = @_;
print $name. q{ };

return;
}

# Run the executable
sub runWithArgs {
my ($args) = @_;
my $command = $exec_name . q{ } . $args;
system( 'sh', '-c', $command );

return;
}

# bool is expected to be true, otherwise fail with message
sub check {
my ( $bool, $message ) = @_;
if ( !$bool || $print_even_if_successful ) {
print( ( $bool ? '[ OK ] ' : '[FAIL] ' ) . $message . "\n" );

$has_failures = 1 if ( !$bool );
}

return;
}

# bool is expected to be true, otherwise fail with message + exit
sub req {
my ( $bool, $message ) = @_;
if ( !$bool || $print_even_if_successful ) {
print( ( $bool ? '[ OK ] ' : '[FAIL] ' ) . $message . "\n" );

exit(1) if ( !$bool );
}

return;
}

# Create a file with $contents
sub createTestInputFile {
my ($contents) = @_;
unlink($test_input_file);
open my $file, q{>}, $test_input_file or croak $!;
print $file $contents;
close $file;

return;
}

0 comments on commit 1c1d1fa

Please sign in to comment.