From 129082d05fb648f0f0e2c1c1cf2ad4ad401ebaf1 Mon Sep 17 00:00:00 2001 From: mmews Date: Fri, 16 Feb 2024 12:39:46 +0100 Subject: [PATCH] added/renamed/enabled tests --- .../n4js/utils/ProjectDescriptionLoader.java | 2 +- ...orkspaceNoDefaultSourceFolderPnpmTest.java | 64 +++++++++++++++ ...orkspaceNoDefaultSourceFolderYarnTest.java | 77 +++++++++++++++++++ ...ava => YarnDifferentPackageNamesTest.java} | 2 +- ...ava => YarnProjectDuplicateNamesTest.java} | 2 +- 5 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/WorkspaceNoDefaultSourceFolderPnpmTest.java create mode 100644 tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/WorkspaceNoDefaultSourceFolderYarnTest.java rename tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/{YarnDifferentPackageNames.java => YarnDifferentPackageNamesTest.java} (97%) rename tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/{YarnProjectDuplicateNames.java => YarnProjectDuplicateNamesTest.java} (97%) diff --git a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/ProjectDescriptionLoader.java b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/ProjectDescriptionLoader.java index b549ef2889..df4de4f949 100644 --- a/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/ProjectDescriptionLoader.java +++ b/plugins/org.eclipse.n4js/src/org/eclipse/n4js/utils/ProjectDescriptionLoader.java @@ -112,7 +112,7 @@ public ProjectDescription loadProjectDescriptionAtLocation(FileURI location, URI ? packageJsonHelper.convertToProjectDescription(packageJSON) : null; if (pdbFromPackageJSON != null) { - // note the order is important here: + // the order is important here: setInformationFromFileSystem(location, pdbFromPackageJSON); setInformationFromPnpmWorkspace(location, pdbFromPackageJSON); diff --git a/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/WorkspaceNoDefaultSourceFolderPnpmTest.java b/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/WorkspaceNoDefaultSourceFolderPnpmTest.java new file mode 100644 index 0000000000..7c90934c04 --- /dev/null +++ b/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/WorkspaceNoDefaultSourceFolderPnpmTest.java @@ -0,0 +1,64 @@ +/** + * Copyright (c) 2020 NumberFour AG. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * NumberFour AG - Initial API and implementation + */ +package org.eclipse.n4js.ide.tests.builder; + +import java.util.Map; + +import org.eclipse.n4js.ide.tests.helper.server.AbstractIdeTest; +import org.eclipse.n4js.ide.tests.helper.server.TestWorkspaceManager; +import org.eclipse.n4js.workspace.N4JSSourceFolderSnapshotForPackageJson; +import org.eclipse.n4js.workspace.WorkspaceAccess; +import org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot; +import org.eclipse.n4js.xtext.workspace.SourceFolderSnapshot; +import org.junit.Assert; +import org.junit.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Inject; + +/** + * Test if the workspace project does not have the default source folder '.'. + */ + +public class WorkspaceNoDefaultSourceFolderPnpmTest extends AbstractIdeTest { + + @Inject + WorkspaceAccess workspaceAccess; + + private static Map> testData = Map.of( + "main-project", Map.of( + "MainModule", """ + // empty + """, + CFG_DEPENDENCIES, """ + library-project-other-name + """), + "library-project", Map.of( + "LibraryModule", """ + // empty + """)); + + @Test + public void test() throws Exception { + testWorkspaceManager.createTestOnDisk(testData); + + startAndWaitForLspServer(); + + ProjectConfigSnapshot pc = concurrentIndex.getProjectConfig(TestWorkspaceManager.YARN_TEST_PROJECT); + Assert.assertNotNull(pc); + + ImmutableSet sfs = pc.getSourceFolders(); + + Assert.assertEquals(1, sfs.size()); + Assert.assertTrue(sfs.iterator().next() instanceof N4JSSourceFolderSnapshotForPackageJson); + } + +} diff --git a/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/WorkspaceNoDefaultSourceFolderYarnTest.java b/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/WorkspaceNoDefaultSourceFolderYarnTest.java new file mode 100644 index 0000000000..9711cc5f91 --- /dev/null +++ b/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/WorkspaceNoDefaultSourceFolderYarnTest.java @@ -0,0 +1,77 @@ +/** + * Copyright (c) 2020 NumberFour AG. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * NumberFour AG - Initial API and implementation + */ +package org.eclipse.n4js.ide.tests.builder; + +import java.nio.file.Path; +import java.util.Map; + +import org.eclipse.n4js.ide.tests.helper.server.AbstractIdeTest; +import org.eclipse.n4js.ide.tests.helper.server.TestWorkspaceManager; +import org.eclipse.n4js.utils.URIUtils; +import org.eclipse.n4js.workspace.N4JSSourceFolderSnapshotForPackageJson; +import org.eclipse.n4js.workspace.WorkspaceAccess; +import org.eclipse.n4js.workspace.locations.FileURI; +import org.eclipse.n4js.xtext.workspace.ProjectConfigSnapshot; +import org.eclipse.n4js.xtext.workspace.SourceFolderSnapshot; +import org.eclipse.xtext.xbase.lib.Pair; +import org.junit.Assert; +import org.junit.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Inject; + +/** + * Test if the workspace project does not have the default source folder '.'. + */ + +public class WorkspaceNoDefaultSourceFolderYarnTest extends AbstractIdeTest { + + @Inject + WorkspaceAccess workspaceAccess; + + private static Map> testData = Map.of( + "main-project", Map.of( + "MainModule", """ + // empty + """, + CFG_DEPENDENCIES, """ + library-project-other-name + """), + "library-project", Map.of( + "LibraryModule", """ + // empty + """)); + + @Test + public void test() throws Exception { + testWorkspaceManager.createTestOnDisk(testData); + + Path pnpmws = Path.of(getRoot().toString(), TestWorkspaceManager.YARN_TEST_PROJECT, "pnpm-workspace.yaml"); + FileURI pnpmwsUri = new FileURI(URIUtils.toFileUri(pnpmws)); + createFileOnDiskWithoutNotification(pnpmwsUri, "packages:\n" + + " - 'packages/*'"); + + Path pckjws = Path.of(getRoot().toString(), TestWorkspaceManager.YARN_TEST_PROJECT, "package.json"); + FileURI pckjUri = new FileURI(URIUtils.toFileUri(pckjws)); + changeFileOnDiskWithoutNotification(pckjUri, Pair.of("\"workspaces\"", "\"ignore_me\"")); + + startAndWaitForLspServer(); + + ProjectConfigSnapshot pc = concurrentIndex.getProjectConfig(TestWorkspaceManager.YARN_TEST_PROJECT); + Assert.assertNotNull(pc); + + ImmutableSet sfs = pc.getSourceFolders(); + + Assert.assertEquals(1, sfs.size()); + Assert.assertTrue(sfs.iterator().next() instanceof N4JSSourceFolderSnapshotForPackageJson); + } + +} diff --git a/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnDifferentPackageNames.java b/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnDifferentPackageNamesTest.java similarity index 97% rename from tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnDifferentPackageNames.java rename to tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnDifferentPackageNamesTest.java index 03b341b558..d679c0ae5c 100644 --- a/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnDifferentPackageNames.java +++ b/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnDifferentPackageNamesTest.java @@ -21,7 +21,7 @@ * Test two cases of projects with the same project name within a yarn setup */ -public class YarnDifferentPackageNames extends AbstractIncrementalBuilderTest { +public class YarnDifferentPackageNamesTest extends AbstractIncrementalBuilderTest { private static Map> testData = Map.of( "main-project", Map.of( diff --git a/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnProjectDuplicateNames.java b/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnProjectDuplicateNamesTest.java similarity index 97% rename from tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnProjectDuplicateNames.java rename to tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnProjectDuplicateNamesTest.java index 71d345d25e..77e5f237da 100644 --- a/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnProjectDuplicateNames.java +++ b/tests/org.eclipse.n4js.ide.tests/src/org/eclipse/n4js/ide/tests/builder/YarnProjectDuplicateNamesTest.java @@ -29,7 +29,7 @@ * Test two cases of projects with the same project name within a yarn setup */ @SuppressWarnings("unchecked") -public class YarnProjectDuplicateNames extends AbstractIncrementalBuilderTest { +public class YarnProjectDuplicateNamesTest extends AbstractIncrementalBuilderTest { private static Map> testData1 = Map.of( TestWorkspaceManager.YARN_TEST_PROJECT, Map.of(