diff --git a/.github/workflows/android-native-build.yml b/.github/workflows/android-native-build.yml index 7fea6e33..289345a4 100644 --- a/.github/workflows/android-native-build.yml +++ b/.github/workflows/android-native-build.yml @@ -1,4 +1,6 @@ name: Android Native build +permissions: + contents: read on: workflow_dispatch: @@ -15,7 +17,7 @@ jobs: ref: ${{ github.head_ref }} - name: Install Android NDK - uses: nttld/setup-ndk@v1.4.2 + uses: nttld/setup-ndk@afb4c9964b521afb97c864b7d40b11e6911bd410 with: ndk-version: r25c diff --git a/.github/workflows/build-all.yml b/.github/workflows/build-all.yml index cea5e45c..effbd60b 100644 --- a/.github/workflows/build-all.yml +++ b/.github/workflows/build-all.yml @@ -2,6 +2,10 @@ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net name: CI (Native + dotnet) +permissions: + contents: read + checks: write + security-events: write on: push: @@ -14,11 +18,13 @@ on: description: 'Enable GPU libraries build and publish' required: true default: 'false' -permissions: - contents: read - checks: write + schedule: + - cron: '40 17 * * 0' jobs: + codeql-github-actions: + uses: ./.github/workflows/codeql-github-actions.yml + android: uses: ./.github/workflows/android-native-build.yml diff --git a/.github/workflows/codeql-github-actions.yml b/.github/workflows/codeql-github-actions.yml new file mode 100644 index 00000000..73a2bdc5 --- /dev/null +++ b/.github/workflows/codeql-github-actions.yml @@ -0,0 +1,28 @@ +name: Dotnet Build and Test + +permissions: + contents: read + checks: write + security-events: write + +on: + workflow_call: + +jobs: + codeql-github: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: actions + build-mode: none + + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:actions" diff --git a/.github/workflows/dotnet-maui.yml b/.github/workflows/dotnet-maui.yml index a84365e4..a1a8a3ff 100644 --- a/.github/workflows/dotnet-maui.yml +++ b/.github/workflows/dotnet-maui.yml @@ -2,6 +2,8 @@ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net name: Dotnet Maui Build and Test +permissions: + contents: read on: workflow_call: @@ -23,7 +25,7 @@ jobs: dotnet-version: | 9.0.x - - uses: maxim-lobanov/setup-xcode@v1 + - uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd with: xcode-version: '16.2' @@ -89,7 +91,7 @@ jobs: run: dotnet tool install Microsoft.DotNet.XHarness.CLI --global --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json --version "10.0.0-*" - name: run android tests - uses: reactivecircus/android-emulator-runner@v2 + uses: reactivecircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d with: api-level: 29 arch: x86_64 @@ -119,7 +121,7 @@ jobs: dotnet-version: | 8.0.x - - uses: maxim-lobanov/setup-xcode@v1 + - uses: maxim-lobanov/setup-xcode@60606e260d2fc5762a71e64e74b2174e8ea3c8bd with: xcode-version: '16.2' diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 449c8983..e53814c5 100755 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -3,12 +3,14 @@ name: Dotnet Build and Test -on: - workflow_call: - permissions: contents: read checks: write + security-events: write + +on: + workflow_call: + env: HF_TOKEN: ${{ secrets.HF_TOKEN }} @@ -36,7 +38,14 @@ jobs: - name: Restore dependencies run: dotnet restore ./Whisper.net.sln - + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: csharp + build-mode: manual + - name: Build run: dotnet build ./Whisper.net.sln --no-restore -warnaserror @@ -45,13 +54,18 @@ jobs: dotnet test ./Whisper.net.sln --no-build --logger "trx" - name: Test Reporter - uses: dorny/test-reporter@v1.9.1 + uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5 if: success() || failure() # run this step even if previous step failed with: name: Whisper.net MacOs Test Results path: ./**/*.trx reporter: dotnet-trx + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:csharp" + - name: Upload trx files uses: actions/upload-artifact@v4 if: success() || failure() # run this step even if previous step failed @@ -59,6 +73,7 @@ jobs: name: test-results-macos path: ./**/*.trx retention-days: 7 + dotnet-windows: runs-on: windows-latest @@ -82,7 +97,14 @@ jobs: - name: Restore dependencies run: dotnet restore ./Whisper.net.sln - + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: csharp + build-mode: manual + - name: Build run: dotnet build ./Whisper.net.sln --no-restore -warnaserror @@ -91,7 +113,7 @@ jobs: dotnet test ./Whisper.net.sln --no-build --logger "trx" - name: Test Reporter - uses: dorny/test-reporter@v1.9.1 + uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5 if: success() || failure() # run this step even if previous step failed with: name: Whisper.net Windows Test Results @@ -105,7 +127,12 @@ jobs: name: test-results-windows path: ./**/*.trx retention-days: 7 - + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:csharp" + dotnet-linux: runs-on: ubuntu-latest @@ -137,7 +164,7 @@ jobs: dotnet test ./Whisper.net.sln --no-build --logger "trx" - name: Test Reporter - uses: dorny/test-reporter@v1.9.1 + uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5 if: success() || failure() # run this step even if previous step failed with: name: Whisper.net Linux Test Results diff --git a/.github/workflows/linux-cuda-native-build.yml b/.github/workflows/linux-cuda-native-build.yml index a9d6475a..b2df14ad 100644 --- a/.github/workflows/linux-cuda-native-build.yml +++ b/.github/workflows/linux-cuda-native-build.yml @@ -1,5 +1,8 @@ name: Linux Cuda Native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: @@ -21,7 +24,7 @@ jobs: run: sudo apt-get update && sudo apt-get install -y gcc-arm-linux-gnueabihf && sudo apt-get install -y g++-arm-linux-gnueabihf - name: Install CUDA Toolkit - uses: Jimver/cuda-toolkit@v0.2.18 + uses: Jimver/cuda-toolkit@8022558310ea543e35132143092835585f60e628 with: cuda: "12.1.0" diff --git a/.github/workflows/linux-native-build.yml b/.github/workflows/linux-native-build.yml index 536ee16a..0516a632 100644 --- a/.github/workflows/linux-native-build.yml +++ b/.github/workflows/linux-native-build.yml @@ -1,5 +1,8 @@ name: Linux Native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: diff --git a/.github/workflows/linux-noavx-native-build.yml b/.github/workflows/linux-noavx-native-build.yml index e4ed5c99..67aeb377 100644 --- a/.github/workflows/linux-noavx-native-build.yml +++ b/.github/workflows/linux-noavx-native-build.yml @@ -1,5 +1,8 @@ name: Linux Native build Without AVX +permissions: + contents: read + on: workflow_dispatch: workflow_call: diff --git a/.github/workflows/linux-openvino-native-build.yml b/.github/workflows/linux-openvino-native-build.yml index a3b5ed59..7546749e 100644 --- a/.github/workflows/linux-openvino-native-build.yml +++ b/.github/workflows/linux-openvino-native-build.yml @@ -1,5 +1,8 @@ name: Linux OpenVino native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: diff --git a/.github/workflows/linux-vulkan-native-build.yml b/.github/workflows/linux-vulkan-native-build.yml index 1cacb005..8da2ebce 100644 --- a/.github/workflows/linux-vulkan-native-build.yml +++ b/.github/workflows/linux-vulkan-native-build.yml @@ -1,5 +1,8 @@ name: Linux Vulkan native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: @@ -21,7 +24,7 @@ jobs: run: sudo apt-get update && sudo apt-get install -y gcc-arm-linux-gnueabihf && sudo apt-get install -y g++-arm-linux-gnueabihf - name: Install Vulkan SDK - uses: jakoch/install-vulkan-sdk-action@v1.0.4 + uses: jakoch/install-vulkan-sdk-action@40216eed6cafc7df0be5eb80620a9f0e7c7104f9 with: vulkan_version: 1.3.290.0 optional_components: com.lunarg.vulkan.vma diff --git a/.github/workflows/macos-coreml-native-build.yml b/.github/workflows/macos-coreml-native-build.yml index 560eb9c8..a33ccd11 100644 --- a/.github/workflows/macos-coreml-native-build.yml +++ b/.github/workflows/macos-coreml-native-build.yml @@ -1,5 +1,8 @@ name: MacOs CoreML Native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: diff --git a/.github/workflows/macos-native-build.yml b/.github/workflows/macos-native-build.yml index 08bc813c..a686c53b 100644 --- a/.github/workflows/macos-native-build.yml +++ b/.github/workflows/macos-native-build.yml @@ -1,5 +1,8 @@ name: MacOs Native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: diff --git a/.github/workflows/pack-all.yml b/.github/workflows/pack-all.yml index 1fecf17f..29c3013a 100644 --- a/.github/workflows/pack-all.yml +++ b/.github/workflows/pack-all.yml @@ -3,6 +3,9 @@ name: Pack All +permissions: + contents: read + on: workflow_call: inputs: diff --git a/.github/workflows/push-all.yml b/.github/workflows/push-all.yml index f25af84b..33a81a3c 100644 --- a/.github/workflows/push-all.yml +++ b/.github/workflows/push-all.yml @@ -3,12 +3,12 @@ name: Push Nuget Packages to nuget.org -on: - workflow_call: - permissions: contents: write +on: + workflow_call: + jobs: push-nupkgs: runs-on: windows-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 73e78019..0f4a3086 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,6 +3,8 @@ name: CD (Native + dotnet) +permissions: + contents: write on: workflow_dispatch: inputs: @@ -23,9 +25,6 @@ on: env: IS_PREVIEW: ${{ inputs.IsPreview }} PREVIEW_SUFFIX: ${{ inputs.PreviewSuffix }} - -permissions: - contents: write jobs: diff --git a/.github/workflows/wasm-native-build.yml b/.github/workflows/wasm-native-build.yml index 0cf6ce0a..148adc4d 100644 --- a/.github/workflows/wasm-native-build.yml +++ b/.github/workflows/wasm-native-build.yml @@ -1,5 +1,8 @@ name: Wasm Native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: @@ -15,7 +18,7 @@ jobs: ref: ${{ github.head_ref }} - name: Install Emscripten - uses: mymindstorm/setup-emsdk@v13 + uses: mymindstorm/setup-emsdk@6ab9eb1bda2574c4ddb79809fc9247783eaf9021 - name: Run wasm build run: make wasm diff --git a/.github/workflows/windows-cuda-native-build.yml b/.github/workflows/windows-cuda-native-build.yml index 9acd8489..cc8f09d6 100644 --- a/.github/workflows/windows-cuda-native-build.yml +++ b/.github/workflows/windows-cuda-native-build.yml @@ -1,5 +1,8 @@ name: Windows Cuda native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: @@ -16,14 +19,14 @@ jobs: ref: ${{ github.head_ref }} - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v2 + uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce - name: Install OpenCl with vcpkg run: | vcpkg --triplet=x64-windows install opencl - name: Install CUDA Toolkit - uses: Jimver/cuda-toolkit@v0.2.18 + uses: Jimver/cuda-toolkit@8022558310ea543e35132143092835585f60e628 with: cuda: "12.1.0" diff --git a/.github/workflows/windows-native-build.yml b/.github/workflows/windows-native-build.yml index c1684f10..d18a9da4 100644 --- a/.github/workflows/windows-native-build.yml +++ b/.github/workflows/windows-native-build.yml @@ -1,5 +1,8 @@ name: Windows native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: diff --git a/.github/workflows/windows-noavx-native-build.yml b/.github/workflows/windows-noavx-native-build.yml index 9013ba12..58e3d507 100644 --- a/.github/workflows/windows-noavx-native-build.yml +++ b/.github/workflows/windows-noavx-native-build.yml @@ -1,5 +1,8 @@ name: Windows native build Without AVX +permissions: + contents: read + on: workflow_dispatch: workflow_call: diff --git a/.github/workflows/windows-openvino-native-build.yml b/.github/workflows/windows-openvino-native-build.yml index 9a86d1e5..8e615d48 100644 --- a/.github/workflows/windows-openvino-native-build.yml +++ b/.github/workflows/windows-openvino-native-build.yml @@ -1,5 +1,8 @@ name: Windows OpenVino native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: @@ -15,7 +18,7 @@ jobs: ref: ${{ github.head_ref }} - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v2 + uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce - name: Run Build run: | diff --git a/.github/workflows/windows-vulkan-native-build.yml b/.github/workflows/windows-vulkan-native-build.yml index a8e2e1cf..b5a348df 100644 --- a/.github/workflows/windows-vulkan-native-build.yml +++ b/.github/workflows/windows-vulkan-native-build.yml @@ -1,5 +1,8 @@ name: Windows Vulkan native build +permissions: + contents: read + on: workflow_dispatch: workflow_call: @@ -15,10 +18,10 @@ jobs: ref: ${{ github.head_ref }} - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v2 + uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce - name: Install Vulkan SDK - uses: jakoch/install-vulkan-sdk-action@v1.0.4 + uses: jakoch/install-vulkan-sdk-action@40216eed6cafc7df0be5eb80620a9f0e7c7104f9 with: vulkan_version: 1.3.290.0 optional_components: com.lunarg.vulkan.vma diff --git a/Directory.Packages.props b/Directory.Packages.props index 169d68f8..00afc240 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -6,7 +6,6 @@ - diff --git a/Whisper.net.sln b/Whisper.net.sln index 5436e63e..5a9d86ad 100644 --- a/Whisper.net.sln +++ b/Whisper.net.sln @@ -19,12 +19,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "github", "github", "{5C8656 ProjectSection(SolutionItems) = preProject .github\workflows\android-native-build.yml = .github\workflows\android-native-build.yml .github\workflows\build-all.yml = .github\workflows\build-all.yml + .github\workflows\codeql-github-actions.yml = .github\workflows\codeql-github-actions.yml .github\workflows\dotnet-maui.yml = .github\workflows\dotnet-maui.yml .github\workflows\dotnet.yml = .github\workflows\dotnet.yml .github\workflows\linux-cuda-native-build.yml = .github\workflows\linux-cuda-native-build.yml .github\workflows\linux-native-build.yml = .github\workflows\linux-native-build.yml .github\workflows\linux-noavx-native-build.yml = .github\workflows\linux-noavx-native-build.yml .github\workflows\linux-openvino-native-build.yml = .github\workflows\linux-openvino-native-build.yml + .github\workflows\linux-vulkan-native-build.yml = .github\workflows\linux-vulkan-native-build.yml .github\workflows\macos-coreml-native-build.yml = .github\workflows\macos-coreml-native-build.yml .github\workflows\macos-native-build.yml = .github\workflows\macos-native-build.yml .github\workflows\pack-all.yml = .github\workflows\pack-all.yml diff --git a/tests/Whisper.net.Tests/FactoryTests.cs b/tests/Whisper.net.Tests/FactoryTests.cs index 854ca6da..c604a192 100644 --- a/tests/Whisper.net.Tests/FactoryTests.cs +++ b/tests/Whisper.net.Tests/FactoryTests.cs @@ -1,5 +1,4 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT -using FluentAssertions; using Whisper.net.Logger; using Xunit; using Xunit.Abstractions; @@ -34,7 +33,7 @@ public void GetSupportedLanguages_ShouldReturnAll() { var languages = WhisperFactory.GetSupportedLanguages().ToList(); - languages.Should().HaveCount(99); + Assert.Equal(99, languages.Count); } [Fact] @@ -46,7 +45,7 @@ public void CreateBuilder_WithNoModel_ShouldThrow() .CreateBuilder(); }; - loadingMethod.Should().Throw(); + Assert.Throws(() => loadingMethod()); } [Fact] @@ -58,7 +57,7 @@ public void CreateBuilder_WithCorruptedModel_ShouldThrow() .CreateBuilder(); }; - loadingMethod.Should().Throw(); + Assert.Throws(loadingMethod); } [Fact] @@ -66,7 +65,7 @@ public void CreateBuilder_WithFileModel_ShouldReturnBuilder() { using var factory = WhisperFactory.FromPath(model.ModelFile); var builder = factory.CreateBuilder(); - builder.Should().NotBeNull(); + Assert.NotNull(builder); } [Fact] @@ -75,7 +74,7 @@ public void CreateBuilder_WithMemoryModel_ShouldReturnBuilder() var memoryBuffer = File.ReadAllBytes(model.ModelFile); using var factory = WhisperFactory.FromBuffer(memoryBuffer); var builder = factory.CreateBuilder(); - builder.Should().NotBeNull(); + Assert.NotNull(builder); } [Fact] @@ -89,7 +88,7 @@ public void CreateBuilder_WithDisposedFactory_ShouldThrow() factory.CreateBuilder(); }; - loadingMethod.Should().Throw(); + Assert.Throws(loadingMethod); } private void OnLog(WhisperLogLevel logLevel, string? message) diff --git a/tests/Whisper.net.Tests/ProcessAsyncFunctionalTests.cs b/tests/Whisper.net.Tests/ProcessAsyncFunctionalTests.cs index e0b38fea..8080d4a0 100644 --- a/tests/Whisper.net.Tests/ProcessAsyncFunctionalTests.cs +++ b/tests/Whisper.net.Tests/ProcessAsyncFunctionalTests.cs @@ -1,10 +1,9 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT -using FluentAssertions; using Xunit; namespace Whisper.net.Tests; -public class ProcessAsyncFunctionalTests(TinyModelFixture model) : IClassFixture +public partial class ProcessAsyncFunctionalTests(TinyModelFixture model) : IClassFixture { [Fact] public async Task TestHappyFlowAsync() @@ -32,13 +31,12 @@ public async Task TestHappyFlowAsync() segmentsEnumerated.Add(data); } - segmentsEnumerated.Should().BeEquivalentTo(segments); - - segments.Should().HaveCountGreaterThan(0); - progress.Should().BeInAscendingOrder().And.HaveCountGreaterThan(1); - encoderBegins.Should().HaveCount(1); - - segments.Should().Contain(segmentData => segmentData.Text.Contains("nation should commit")); + Assert.Equal(segments, segmentsEnumerated); + Assert.True(segments.Count > 0); + Assert.True(progress.SequenceEqual(progress.OrderBy(x => x))); + Assert.True(progress.Count > 1); + Assert.Single(encoderBegins); + Assert.Contains(segments, segmentData => segmentData.Text.Contains("nation should commit")); } [Fact] @@ -80,13 +78,11 @@ public async Task ProcessAsync_Cancelled_WillCancellTheProcessing_AndDispose_Wil await processor.DisposeAsync(); - segmentsEnumerated.Should().BeEmpty(); - - segments.Should().HaveCount(1); - encoderBegins.Should().HaveCount(1); - taskCanceledException.Should().NotBeNull(); - - segments.Should().Contain(segmentData => segmentData.Text.Contains("nation should commit")); + Assert.Empty(segmentsEnumerated); + Assert.Single( segments); + Assert.Single( encoderBegins); + Assert.NotNull(taskCanceledException); + Assert.Contains(segments, segmentData => segmentData.Text.Contains("nation should commit")); } [Fact] @@ -105,7 +101,7 @@ public async Task ProcessAsync_WhenJunkChunkExists_ProcessCorrectly() segments.Add(segment); } - segments.Should().HaveCountGreaterThanOrEqualTo(1); + Assert.True(segments.Count >= 1); } [Fact] @@ -124,13 +120,12 @@ public async Task ProcessAsync_WhenMultichannel_ProcessCorrectly() segments.Add(segment); } - segments.Should().HaveCountGreaterThanOrEqualTo(1); + Assert.True(segments.Count >= 1); } [Fact] public async Task ProcessAsync_CalledMultipleTimes_Serially_WillCompleteEverytime() { - var segments1 = new List(); var segments2 = new List(); var segments3 = new List(); @@ -158,7 +153,9 @@ public async Task ProcessAsync_CalledMultipleTimes_Serially_WillCompleteEverytim segments3.Add(segment); } - segments1.Should().BeEquivalentTo(segments2); - segments2.Should().BeEquivalentTo(segments3); + Assert.True(segments1.SequenceEqual(segments2, new SegmentDataComparer())); + Assert.True(segments2.SequenceEqual(segments3, new SegmentDataComparer())); + } + } diff --git a/tests/Whisper.net.Tests/ProcessFunctionalTests.cs b/tests/Whisper.net.Tests/ProcessFunctionalTests.cs index 60ac813c..87b3b0b9 100644 --- a/tests/Whisper.net.Tests/ProcessFunctionalTests.cs +++ b/tests/Whisper.net.Tests/ProcessFunctionalTests.cs @@ -1,9 +1,8 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT -using System.ComponentModel; using System.Runtime.InteropServices; -using FluentAssertions; using Xunit; +using static Whisper.net.Tests.ProcessAsyncFunctionalTests; namespace Whisper.net.Tests; @@ -31,11 +30,13 @@ public async Task TestHappyFlow() using var fileReader = await TestDataProvider.OpenFileStreamAsync("kennedy.wav"); processor.Process(fileReader); - segments.Should().HaveCountGreaterThan(0); - encoderBegins.Should().HaveCount(1); - progress.Should().BeInAscendingOrder().And.HaveCountGreaterThan(1); + Assert.True(segments.Count >= 1); + Assert.True(encoderBegins.Count >= 1); + Assert.True(progress.SequenceEqual(progress.OrderBy(s => s))); - segments.Should().Contain(segmentData => segmentData.Text.Contains("nation should commit")); + Assert.True(progress.Count >= 1); + + Assert.Contains(segments, s => s.Text.Contains("nation should commit")); } [Fact(Skip = "Skipping for now, for some reason not working on ios, see #308")] @@ -57,8 +58,8 @@ public async Task TestCancelEncoder() using var fileReader = await TestDataProvider.OpenFileStreamAsync("kennedy.wav"); processor.Process(fileReader); - segments.Should().HaveCount(0); - encoderBegins.Should().HaveCount(1); + Assert.True(segments.Count == 0); + Assert.Single(encoderBegins); } [Fact] @@ -80,10 +81,11 @@ public async Task TestAutoDetectLanguageWithRomanian() { segments.Add(segment); } - segments.Should().HaveCountGreaterThan(0); - encoderBegins.Should().HaveCountGreaterThanOrEqualTo(1); - segments.Should().AllSatisfy(s => s.Language.Should().Be("ro")); - segments.Should().Contain(segmentData => segmentData.Text.Contains("efectua")); + + Assert.True(segments.Count >= 1); + Assert.True(encoderBegins.Count >= 1); + Assert.True(segments.All(s => s.Language == "ro")); + Assert.Contains(segments, s => s.Text.Contains("efectua")); } [Fact] @@ -100,7 +102,7 @@ public async Task Process_WhenMultichannel_ProcessCorrectly() using var fileReader = await TestDataProvider.OpenFileStreamAsync("multichannel.wav"); processor.Process(fileReader); - segments.Should().HaveCountGreaterThanOrEqualTo(1); + Assert.True(segments.Count >= 1); } [Fact] @@ -132,8 +134,8 @@ public async Task Process_CalledMultipleTimes_Serially_WillCompleteEverytime() using var fileReader3 = await TestDataProvider.OpenFileStreamAsync("kennedy.wav"); processor.Process(fileReader3); - segments1.Should().BeEquivalentTo(segments2); - segments2.Should().BeEquivalentTo(segments3); + Assert.True(segments1.SequenceEqual(segments2, new SegmentDataComparer())); + Assert.True(segments2.SequenceEqual(segments3, new SegmentDataComparer())); } [Theory] @@ -200,10 +202,11 @@ _ when RuntimeInformation.IsOSPlatform(OSPlatform.OSX) => "macos", using var fileReader = await TestDataProvider.OpenFileStreamAsync("kennedy.wav"); processor.Process(fileReader); - segments.Should().HaveCountGreaterThan(0); - encoderBegins.Should().HaveCount(1); - progress.Should().BeInAscendingOrder().And.HaveCountGreaterThan(1); + Assert.True(segments.Count > 0); + Assert.Single(encoderBegins); - segments.Should().Contain(segmentData => segmentData.Text.Contains("nation should commit")); + Assert.Equal(progress, progress.OrderBy(p => p)); + Assert.True(progress.Count > 1); + Assert.Contains(segments, segmentData => segmentData.Text.Contains("nation should commit")); } } diff --git a/tests/Whisper.net.Tests/ProcessQuantizedTests.cs b/tests/Whisper.net.Tests/ProcessQuantizedTests.cs index 38597fc0..d43aeb50 100644 --- a/tests/Whisper.net.Tests/ProcessQuantizedTests.cs +++ b/tests/Whisper.net.Tests/ProcessQuantizedTests.cs @@ -1,6 +1,5 @@ // Licensed under the MIT license: https://opensource.org/licenses/MIT -using FluentAssertions; using Xunit; namespace Whisper.net.Tests; @@ -28,10 +27,10 @@ public async Task TestHappyFlowQuantized() using var fileReader = await TestDataProvider.OpenFileStreamAsync("bush.wav"); processor.Process(fileReader); - segments.Should().HaveCountGreaterThan(0); - encoderBegins.Should().HaveCountGreaterThanOrEqualTo(1); - progress.Should().BeInAscendingOrder().And.HaveCountGreaterThan(1); - - segments.Should().Contain(segmentData => segmentData.Text.Contains("My fellow Americans")); + Assert.True(segments.Count > 0); + Assert.True(encoderBegins.Count >= 1); + Assert.True(progress.Count >= 1); + Assert.Equal(progress, progress.OrderBy(s => s)); + Assert.Contains(segments, segmentData => segmentData.Text.Contains("My fellow Americans")); } } diff --git a/tests/Whisper.net.Tests/SegmentDataComparer.cs b/tests/Whisper.net.Tests/SegmentDataComparer.cs new file mode 100644 index 00000000..80ec38ff --- /dev/null +++ b/tests/Whisper.net.Tests/SegmentDataComparer.cs @@ -0,0 +1,23 @@ +// Licensed under the MIT license: https://opensource.org/licenses/MIT + +namespace Whisper.net.Tests; +public partial class ProcessAsyncFunctionalTests +{ + public class SegmentDataComparer : IEqualityComparer + { + public bool Equals(SegmentData? x, SegmentData? y) + { + if (x == null || y == null) + { + return false; + } + return x.Text == y.Text && x.MinProbability == y.MinProbability && x.Probability == y.Probability && x.Start == y.Start && x.End == y.End; // Compare by relevant properties + } + + public int GetHashCode(SegmentData obj) + { + return obj.Text.GetHashCode(); + } + } + +} diff --git a/tests/Whisper.net.Tests/Whisper.net.Tests.csproj b/tests/Whisper.net.Tests/Whisper.net.Tests.csproj index 6a58b281..63ab9665 100644 --- a/tests/Whisper.net.Tests/Whisper.net.Tests.csproj +++ b/tests/Whisper.net.Tests/Whisper.net.Tests.csproj @@ -10,7 +10,6 @@ -