From 400d29de8379deb513d58e57488776570d566908 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Thu, 25 Jul 2024 13:30:03 +0700 Subject: [PATCH 1/5] roll back nunit3testadapter to 4.3.2 which was the last version to support .net 461 --- tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj | 2 +- .../SIL.LCModel.FixData.Tests.csproj | 2 +- tests/SIL.LCModel.Tests/SIL.LCModel.Tests.csproj | 2 +- tests/SIL.LCModel.Utils.Tests/SIL.LCModel.Utils.Tests.csproj | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj b/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj index 5fb8aa68..e177d2b2 100644 --- a/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj +++ b/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj @@ -14,7 +14,7 @@ This package provides unit tests for SIL.LCModel.Core. - + diff --git a/tests/SIL.LCModel.FixData.Tests/SIL.LCModel.FixData.Tests.csproj b/tests/SIL.LCModel.FixData.Tests/SIL.LCModel.FixData.Tests.csproj index 1e54d007..b1cdf48c 100644 --- a/tests/SIL.LCModel.FixData.Tests/SIL.LCModel.FixData.Tests.csproj +++ b/tests/SIL.LCModel.FixData.Tests/SIL.LCModel.FixData.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/tests/SIL.LCModel.Tests/SIL.LCModel.Tests.csproj b/tests/SIL.LCModel.Tests/SIL.LCModel.Tests.csproj index 86b14f0a..0ef7b2bb 100644 --- a/tests/SIL.LCModel.Tests/SIL.LCModel.Tests.csproj +++ b/tests/SIL.LCModel.Tests/SIL.LCModel.Tests.csproj @@ -13,7 +13,7 @@ This package provides unit tests for SIL.LCModel. - + diff --git a/tests/SIL.LCModel.Utils.Tests/SIL.LCModel.Utils.Tests.csproj b/tests/SIL.LCModel.Utils.Tests/SIL.LCModel.Utils.Tests.csproj index bb8772d6..a675da34 100644 --- a/tests/SIL.LCModel.Utils.Tests/SIL.LCModel.Utils.Tests.csproj +++ b/tests/SIL.LCModel.Utils.Tests/SIL.LCModel.Utils.Tests.csproj @@ -1,7 +1,7 @@ - net461 + net461 SIL.LCModel.Utils The liblcm library is the core FieldWorks model for linguistic analyses of languages. Tools in this library provide the ability to store and interact with language and culture data, including anthropological, text corpus, and linguistics data. This package provides unit tests for SIL.LCModel.Utils and test utility classes @@ -14,7 +14,7 @@ This package provides unit tests for SIL.LCModel.Utils and test utility classes< - + From e01079df3da4a101e83e998e5b2ef467b6f9b5bf Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Thu, 25 Jul 2024 13:31:08 +0700 Subject: [PATCH 2/5] change CI to publish test results and fail if no tests are found --- .github/workflows/ci-cd.yml | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index 64a89cbc..ae5a9120 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -46,7 +46,7 @@ jobs: - name: Solve problems run: Remove-Item c:\tools\php\icuuc*.dll -Force if: matrix.os == 'windows-latest' - + - name: Download 461 targeting pack uses: suisei-cn/actions-download-file@818d6b7dc8fe73f2f924b6241f2b1134ca1377d9 # 1.6.0 id: downloadfile # Remember to give an ID if you need the output filename @@ -54,7 +54,7 @@ jobs: url: "https://download.microsoft.com/download/F/1/D/F1DEB8DB-D277-4EF9-9F48-3A65D4D8F965/NDP461-DevPack-KB3105179-ENU.exe" target: public/ if: matrix.os == 'windows-latest' - + - name: Install targeting pack shell: cmd working-directory: public @@ -67,12 +67,18 @@ jobs: - name: Test on Linux run: | . environ - dotnet test --no-restore --no-build -p:ParallelizeAssembly=false --configuration Release -- RunConfiguration.FailWhenNoTestsFound=true + dotnet test --no-restore --no-build -p:ParallelizeAssembly=false --configuration Release --logger:"trx" --results-directory ./test-results if: matrix.os == 'ubuntu-latest' - name: Test on Windows - run: dotnet test -a "%UserProfile%\.nuget\packages\nunit3testadapter\4.5.0\build\net462" --no-restore --no-build -p:ParallelizeAssembly=false --configuration Release -- RunConfiguration.FailWhenNoTestsFound=true + run: dotnet test --no-restore --no-build -p:ParallelizeAssembly=false --configuration Release --logger:"trx" --results-directory ./test-results if: matrix.os != 'ubuntu-latest' + - name: Upload test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: Test results (${{ matrix.os }}) + path: ./test-results - name: Package run: dotnet pack --include-symbols --no-restore --no-build -p:SymbolPackageFormat=snupkg --configuration Release @@ -87,3 +93,19 @@ jobs: name: NugetPackages path: artifacts/*.nupkg if: github.event_name == 'pull_request' + publish-test-results: + runs-on: ubuntu-latest + needs: build + if: always() + steps: + - name: Download test results + uses: actions/download-artifact@v3 + with: + path: artifacts + - name: Publish test results + uses: EnricoMi/publish-unit-test-result-action@8885e273a4343cd7b48eaa72428dea0c3067ea98 # v2.14.0 + with: + check_name: LCM Tests + files: artifacts/**/*.trx + action_fail: true + action_fail_on_inconclusive: true From 6919afc1889ea04a7f0766c5511c4080c85cc3db Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Thu, 25 Jul 2024 13:47:22 +0700 Subject: [PATCH 3/5] update artifacts actions as they must all be in sync. Use pattern to download Test results artifacts --- .github/workflows/ci-cd.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index ae5a9120..caac217e 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -88,7 +88,7 @@ jobs: if: github.event_name == 'push' && matrix.os == 'ubuntu-latest' - name: Publish Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: NugetPackages path: artifacts/*.nupkg @@ -99,9 +99,10 @@ jobs: if: always() steps: - name: Download test results - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: path: artifacts + pattern: Test results * - name: Publish test results uses: EnricoMi/publish-unit-test-result-action@8885e273a4343cd7b48eaa72428dea0c3067ea98 # v2.14.0 with: From 55a0583b6ff6fa59c67df54e2aba38fed52dcec6 Mon Sep 17 00:00:00 2001 From: Jason Naylor Date: Thu, 25 Jul 2024 10:37:49 -0700 Subject: [PATCH 4/5] Match SIL.TestUtilities reference to other palaso libs * The mismatch brought in a newer version of assemblies after the non-test assemblies were built causing test failures --- tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj b/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj index e177d2b2..c980c133 100644 --- a/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj +++ b/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj @@ -16,7 +16,7 @@ This package provides unit tests for SIL.LCModel.Core. - + From 513fdda93c58f1740d34032e48409ccf1c06b245 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Fri, 26 Jul 2024 15:01:50 +0700 Subject: [PATCH 5/5] fix bug in LcmSet.CopyTo where it would only work if the arrayIndex was 0. Added a test for this case. --- src/SIL.LCModel/DomainImpl/Vectors.cs | 18 ++--- .../DomainImpl/VectorTests.cs | 66 +++++++++++++++++-- 2 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/SIL.LCModel/DomainImpl/Vectors.cs b/src/SIL.LCModel/DomainImpl/Vectors.cs index 7e3cfecd..25b67be8 100644 --- a/src/SIL.LCModel/DomainImpl/Vectors.cs +++ b/src/SIL.LCModel/DomainImpl/Vectors.cs @@ -421,19 +421,13 @@ public void CopyTo(T[] array, int arrayIndex) // TODO: Check for multidimensional 'array' and throw ArgumentException, if it is. lock (SyncRoot) { - //if (arrayIndex >= array.Length || m_items.Count - arrayIndex >= array.Length) - // equals sign causes spurious ArgumentException when copying entire array - if (array.Length == 0) - return; - if (arrayIndex >= array.Length || m_items.Count - arrayIndex > array.Length) - throw new ArgumentException(); - - int currentIndex = 0; - int currentcopiedIndex = 0; - foreach (var objOrId in m_items.ToArray()) + if (m_items.Count + arrayIndex > array.Length) + throw new ArgumentOutOfRangeException("arrayIndex"); + + int currentcopiedIndex = arrayIndex; + foreach (var cmObjectOrId in m_items) { - if (currentIndex++ < arrayIndex) continue; - array.SetValue(FluffUpObjectIfNeeded(objOrId), currentcopiedIndex++); + array[currentcopiedIndex++] = FluffUpObjectIfNeeded(cmObjectOrId); } } } diff --git a/tests/SIL.LCModel.Tests/DomainImpl/VectorTests.cs b/tests/SIL.LCModel.Tests/DomainImpl/VectorTests.cs index 4ec18fb4..2d7983af 100644 --- a/tests/SIL.LCModel.Tests/DomainImpl/VectorTests.cs +++ b/tests/SIL.LCModel.Tests/DomainImpl/VectorTests.cs @@ -396,11 +396,11 @@ private ILexEntry MakeEntry() /// ------------------------------------------------------------------------------------ /// - /// Tests the CopyTo method. + /// Tests the CopyTo LcmList method. /// /// ------------------------------------------------------------------------------------ [Test] - public void CopyTo_OneItemInLongListTest() + public void CopyTo_LcmList_OneItemInLongListTest() { ILcmServiceLocator servLoc = Cache.ServiceLocator; IScrBookFactory bookFact = servLoc.GetInstance(); @@ -418,13 +418,37 @@ public void CopyTo_OneItemInLongListTest() Assert.IsNull(bookArray[4]); } + /// ------------------------------------------------------------------------------------ + /// + /// Tests the CopyTo LcmSet method. + /// + /// ------------------------------------------------------------------------------------ + [Test] + public void CopyTo_LcmSet_OneItemInLongListTest() + { + ILcmServiceLocator servLoc = Cache.ServiceLocator; + IScrDraftFactory draftFactory = servLoc.GetInstance(); + + // Setup the source sequence using the drafts collection. + IScrDraft draft0 = draftFactory.Create("draft"); + + IScrDraft[] draftArray = new IScrDraft[5]; + m_scr.ArchivedDraftsOC.CopyTo(draftArray, 3); + + Assert.IsNull(draftArray[0]); + Assert.IsNull(draftArray[1]); + Assert.IsNull(draftArray[2]); + Assert.AreEqual(draft0, draftArray[3]); + Assert.IsNull(draftArray[4]); + } + /// ------------------------------------------------------------------------------------ /// /// Tests the CopyTo method when we are copying into a one-item list. /// /// ------------------------------------------------------------------------------------ [Test] - public void CopyTo_OneItemInOneItemListTest() + public void CopyTo_LcmList_OneItemInOneItemListTest() { ILcmServiceLocator servLoc = Cache.ServiceLocator; IScrBookFactory bookFact = servLoc.GetInstance(); @@ -438,13 +462,33 @@ public void CopyTo_OneItemInOneItemListTest() Assert.AreEqual(book0, bookArray[0]); } + /// ------------------------------------------------------------------------------------ + /// + /// Tests the CopyTo method when we are copying into a one-item set. + /// + /// ------------------------------------------------------------------------------------ + [Test] + public void CopyTo_LcmSet_OneItemInOneItemListTest() + { + ILcmServiceLocator servLoc = Cache.ServiceLocator; + IScrDraftFactory draftFactory = servLoc.GetInstance(); + + // Setup the source sequence using the drafts collection. + IScrDraft draft0 = draftFactory.Create("draft"); + + IScrDraft[] draftArray = new IScrDraft[1]; + m_scr.ArchivedDraftsOC.CopyTo(draftArray, 0); + + Assert.AreEqual(draft0, draftArray[0]); + } + /// ------------------------------------------------------------------------------------ /// /// Tests the CopyTo method when we are copying no items into an empty list. /// /// ------------------------------------------------------------------------------------ [Test] - public void CopyTo_NoItemsInEmptyItemListTest() + public void CopyTo_LcmList_NoItemsInEmptyItemListTest() { ILcmServiceLocator servLoc = Cache.ServiceLocator; @@ -454,6 +498,20 @@ public void CopyTo_NoItemsInEmptyItemListTest() // This fixes creating a new List<> when giving a LcmVector as the parameter. } + /// ------------------------------------------------------------------------------------ + /// + /// Tests the CopyTo method when we are copying no items into an empty set. + /// + /// ------------------------------------------------------------------------------------ + [Test] + public void CopyTo_LcmSet_NoItemsInEmptyItemListTest() + { + IScrDraft[] draftArray = new IScrDraft[0]; + m_scr.ArchivedDraftsOC.CopyTo(draftArray, 0); + // This test makes sure that an exception is not thrown when the array is empty. + // This fixes creating a new List<> when giving a LcmVector as the parameter. + } + /// ------------------------------------------------------------------------------------ /// /// Tests the CopyTo method when we are copying from one reference sequence to another.