From 73e1f66c4dde6b9dba0b2bca9a243c8d28e52fee Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Fri, 26 Jul 2024 20:50:50 +0700 Subject: [PATCH] Ensure tests run on ci (#305) * Roll back nunit3testadapter to 4.3.2 which was the last version to support .net 461 * Change CI to publish test results and fail if no tests are found * Update artifacts actions as they must all be in sync. Use pattern to download Test results artifacts * Match SIL.TestUtilities reference to other palaso libs to avoid pulling in newer versions of SIL.Core * Fix bug in LcmSet.CopyTo where it would only work if the arrayIndex was 0 and add a test for this case --------- Co-authored-by: Jason Naylor --- .github/workflows/ci-cd.yml | 29 +++++++- src/SIL.LCModel/DomainImpl/Vectors.cs | 18 ++--- .../SIL.LCModel.Core.Tests.csproj | 4 +- .../SIL.LCModel.FixData.Tests.csproj | 2 +- .../DomainImpl/VectorTests.cs | 66 +++++++++++++++++-- .../SIL.LCModel.Tests.csproj | 2 +- .../SIL.LCModel.Utils.Tests.csproj | 4 +- 7 files changed, 100 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index af017e1c..a850e741 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -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 --test-adapter-path "%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 @@ -86,8 +92,25 @@ jobs: run: dotnet nuget push artifacts/*.nupkg -s https://nuget.pkg.github.com/sillsdev/index.json -k ${{secrets.GITHUB_TOKEN}} --skip-duplicate - name: Publish Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: 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@v4 + with: + path: artifacts + pattern: Test results * + - 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 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.Core.Tests/SIL.LCModel.Core.Tests.csproj b/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj index 5fb8aa68..c980c133 100644 --- a/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj +++ b/tests/SIL.LCModel.Core.Tests/SIL.LCModel.Core.Tests.csproj @@ -14,9 +14,9 @@ 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/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. 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< - +