From aa1a3aa73ff88d9fd463b0ce0074891cb03b06dc Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Mon, 25 Nov 2024 17:56:56 +0100 Subject: [PATCH] chore: add simple tests for checking plugin version --- src/Fable.Transforms/Global/Compiler.fs | 2 +- .../Compiler/CompilerHelpersTests.fs | 24 +++++++++++++++++++ .../Compiler/Fable.Tests.Compiler.fsproj | 3 ++- tests/Integration/Compiler/Main.fs | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tests/Integration/Compiler/CompilerHelpersTests.fs diff --git a/src/Fable.Transforms/Global/Compiler.fs b/src/Fable.Transforms/Global/Compiler.fs index a850b4ecc9..ce425ec84f 100644 --- a/src/Fable.Transforms/Global/Compiler.fs +++ b/src/Fable.Transforms/Global/Compiler.fs @@ -99,7 +99,7 @@ type InlineExprLazy(f: Compiler -> InlineExpr) = [] module CompilerExt = - let private expectedVersionMatchesActual (expected: string) (actual: string) = + let expectedVersionMatchesActual (expected: string) (actual: string) = try let r = System.Text.RegularExpressions.Regex(@"^(\d+)\.(\d+)(?:\.(\d+))?") diff --git a/tests/Integration/Compiler/CompilerHelpersTests.fs b/tests/Integration/Compiler/CompilerHelpersTests.fs new file mode 100644 index 0000000000..edda34abc0 --- /dev/null +++ b/tests/Integration/Compiler/CompilerHelpersTests.fs @@ -0,0 +1,24 @@ +module Fable.Tests.Compiler.CompilerHelpers + +open Fable.Core +open Util.Testing +open Fable.Tests.Compiler.Util +open Fable.Tests.Compiler.Util.Compiler + +let tests = + testList "Compiler Helpers" [ + testCase "expectedVersionMatchesActual works for same major version" <| fun _ -> + Fable.CompilerExt.expectedVersionMatchesActual "5.0.0" "5.0.0" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "5.0.1" "5.0.0" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "5.1.0" "5.0.0" |> equal true + + testCase "expectedVersionMatchesActual works if actual version is highter than expected version" <| fun _ -> + Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "5.0.0" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "4.0.1" "5.0.0" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "4.1.0" "5.0.0" |> equal true + + testCase "expectedVersionMatchesActual reject if actual version is highter than expected version" <| fun _ -> + Fable.CompilerExt.expectedVersionMatchesActual "4.0.0" "3.0.0" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "4.0.1" "3.0.0" |> equal true + Fable.CompilerExt.expectedVersionMatchesActual "4.1.0" "3.0.0" |> equal true + ] diff --git a/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj b/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj index 096a4285c5..573d040109 100644 --- a/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj +++ b/tests/Integration/Compiler/Fable.Tests.Compiler.fsproj @@ -22,6 +22,7 @@ + - \ No newline at end of file + diff --git a/tests/Integration/Compiler/Main.fs b/tests/Integration/Compiler/Main.fs index 4011447b32..fbed235b93 100644 --- a/tests/Integration/Compiler/Main.fs +++ b/tests/Integration/Compiler/Main.fs @@ -7,6 +7,7 @@ let allTests = [ CompilerMessages.tests AnonRecordInInterface.tests + CompilerHelpers.tests ]