diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 058a388..c952a88 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,13 +14,15 @@ 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 @@ -28,13 +30,15 @@ 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-deb-package: runs-on: ubuntu-latest @@ -42,13 +46,15 @@ jobs: 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 @@ -57,13 +63,15 @@ 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 @@ -71,13 +79,15 @@ jobs: 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 @@ -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 @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5eb7ae0..5f4cd13 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: >- diff --git a/test/cli.pl b/test/cli.pl new file mode 100644 index 0000000..9da3a7b --- /dev/null +++ b/test/cli.pl @@ -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; +}