From 5207738007e283912518d850c1a33a99a016b39a Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 17 Jul 2021 23:47:30 +0200 Subject: [PATCH] Add and fix macOS builds --- .github/workflows/dotnet.yml | 7 ++++++- build/Program.fs | 28 +++++++++++++++----------- src/common/tests_xunit.cs | 38 +++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 8f50d17e..83c2f01d 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -9,7 +9,11 @@ on: jobs: build: - runs-on: windows-latest + strategy: + matrix: + os: [windows-latest, macos-latest] + + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v2 @@ -33,6 +37,7 @@ jobs: with: dotnet-version: 2.1.x - name: Add msbuild to PATH + if: startsWith(matrix.os, 'windows') uses: microsoft/setup-msbuild@v1.0.2 - name: Install T4 run: dotnet tool install --global dotnet-t4 diff --git a/build/Program.fs b/build/Program.fs index 1686ba94..78869d49 100644 --- a/build/Program.fs +++ b/build/Program.fs @@ -2,6 +2,7 @@ open System open System.Diagnostics open System.IO +open System.Runtime.InteropServices open System.Xml.Linq open System.Linq @@ -165,25 +166,30 @@ let main argv = //exec "dotnet" (sprintf "run --framework=%s" "net5.0") (Path.Combine(top, "test_nupkgs", "cil", "fake_xunit")) - exec "dotnet" "test" (Path.Combine(top, "test_nupkgs", "e_sqlite3", "real_xunit")) - exec "dotnet" "test" (Path.Combine(top, "test_nupkgs", "winsqlite3", "real_xunit")) - exec "dotnet" "test" (Path.Combine(top, "test_nupkgs", "e_sqlcipher", "real_xunit")) - // TODO do bundle_sqlite3 real_xunit here? + let real_xunit_dirs = [ + yield "e_sqlite3" + yield "e_sqlcipher" + // TODO do bundle_sqlite3 real_xunit here? + if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then yield "winsqlite3" + ] let fake_xunit_tfms = [ - "netcoreapp2.1" - "netcoreapp3.1" - //"net461" + yield "netcoreapp2.1" + yield "netcoreapp3.1" + if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then yield "net461" ] let fake_xunit_dirs = [ - "e_sqlite3" - "e_sqlcipher" - "winsqlite3" - "sqlite3" + yield "e_sqlite3" + yield "e_sqlcipher" + if RuntimeInformation.IsOSPlatform(OSPlatform.Windows) then yield "winsqlite3" + yield "sqlite3" ] for tfm in fake_xunit_tfms do + for dir in real_xunit_dirs do + let args = sprintf "test --framework=%s" tfm + exec "dotnet" args (Path.Combine(top, "test_nupkgs", dir, "real_xunit")) for dir in fake_xunit_dirs do let args = sprintf "run --framework=%s" tfm exec "dotnet" args (Path.Combine(top, "test_nupkgs", dir, "fake_xunit")) diff --git a/src/common/tests_xunit.cs b/src/common/tests_xunit.cs index 95ab296c..f1caa1cc 100644 --- a/src/common/tests_xunit.cs +++ b/src/common/tests_xunit.cs @@ -18,6 +18,7 @@ limitations under the License. using System.Collections.Generic; using System.Linq; using System.IO; +using System.Runtime.InteropServices; using System.Text; using SQLitePCL; using SQLitePCL.Ugly; @@ -67,10 +68,13 @@ public void test_GetZeroTerminatedUTF8Bytes() [Fact] public void test_call_sqlite3_enable_load_extension() { - using (sqlite3 db = ugly.open(":memory:")) + if (0 == raw.sqlite3_compileoption_used("SQLITE_OMIT_LOAD_EXTENSION")) { - var rc = raw.sqlite3_enable_load_extension(db, 0); - Assert.Equal(raw.SQLITE_OK, rc); + using (sqlite3 db = ugly.open(":memory:")) + { + var rc = raw.sqlite3_enable_load_extension(db, 0); + Assert.Equal(raw.SQLITE_OK, rc); + } } } @@ -781,10 +785,17 @@ public void test_threadsafe() public void test_enable_shared_cache() { int result = raw.sqlite3_enable_shared_cache(1); - Assert.Equal(raw.SQLITE_OK, result); + // https://www.sqlite.org/c3ref/enable_shared_cache.html + // Note: This method is disabled on MacOS X 10.7 and iOS version 5.0 and will always + // return SQLITE_MISUSE. On those systems, shared cache mode should be enabled + // per-database connection via sqlite3_open_v2() with SQLITE_OPEN_SHAREDCACHE. + if (result != raw.SQLITE_MISUSE) + { + Assert.Equal(raw.SQLITE_OK, result); - result = raw.sqlite3_enable_shared_cache(0); - Assert.Equal(raw.SQLITE_OK, result); + result = raw.sqlite3_enable_shared_cache(0); + Assert.Equal(raw.SQLITE_OK, result); + } } [Fact] @@ -815,12 +826,15 @@ public void test_sqlite3_soft_heap_limit64() } [Fact] - public void sqlite3_hard_heap_limit64() + public void test_sqlite3_hard_heap_limit64() { var version = raw.sqlite3_libversion_number(); - if (version < 3031001) return; // Added in 3.31.1: https://sqlite.org/releaselog/3_31_1.html + // Skip failing test on macOS system provided libsqlite3.dylib + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && raw.GetNativeLibraryName() == "sqlite3") + return; + var query = raw.sqlite3_hard_heap_limit64(-1); Assert.True(query >= 0); @@ -835,11 +849,17 @@ public void sqlite3_hard_heap_limit64() [Fact] public void test_sqlite3_status() { + // Skip failing test on macOS system provided libsqlite3.dylib + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && raw.GetNativeLibraryName() == "sqlite3") + return; + using (sqlite3 db = ugly.open(":memory:")) { int current; int highwater; - ugly.sqlite3_status(raw.SQLITE_STATUS_MEMORY_USED, out current, out highwater, 0); + + var rc = raw.sqlite3_status(raw.SQLITE_STATUS_MEMORY_USED, out current, out highwater, 0); + Assert.Equal(raw.SQLITE_OK, rc); Assert.True(current > 0); Assert.True(highwater > 0);