From 727430964a6b89fe5fdbc738cc9a2f0bd7fc5ceb Mon Sep 17 00:00:00 2001 From: "Igor V. Kovalenko" Date: Sat, 7 Oct 2023 03:04:08 +0300 Subject: [PATCH] Add test for deduction guide template vs index issue Add new index binding resolution test strategy SinglePDOMReindexedTestStrategy which does reindex project after adding test case sources. Clean up redundand C++17 setup helper classes from test since deduction guides are always enabled. Add test case modelling std::map resolution problem and make sure to run it with new test strategy to reproduce the issue. Bug #438 --- .../tests/IndexBindingResolutionTestBase.java | 49 ++++++++-- .../index/tests/IndexDeductionGuideTest.java | 97 ++++++++++--------- 2 files changed, 92 insertions(+), 54 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index f0b037c9283..4b6c6f84aed 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -631,13 +631,7 @@ public abstract class IndexBindingResolutionTestBase extends SemanticTestBase { setTestSpecificFlags(sourceContents); - IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), headerContents); - CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); - waitForIndexer(cproject); - - IFile cppfile = TestSourceReader.createFile(cproject.getProject(), - new Path("references.c" + (cpp ? "pp" : "")), sourceContents); - waitForIndexer(cproject); + IFile cppfile = createSourceFilesAndIndex(headerContents, sourceContents); if (DEBUG) { System.out.println("Project PDOM: " + getName()); @@ -650,6 +644,18 @@ public abstract class IndexBindingResolutionTestBase extends SemanticTestBase { ast = TestSourceReader.createIndexBasedAST(index, cproject, cppfile); } + IFile createSourceFilesAndIndex(String headerContents, String sourceContents) throws Exception { + IFile file = TestSourceReader.createFile(cproject.getProject(), new Path("header.h"), headerContents); + CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER); + waitForIndexer(cproject); + + IFile cppfile = TestSourceReader.createFile(cproject.getProject(), + new Path("references.c" + (cpp ? "pp" : "")), sourceContents); + waitForIndexer(cproject); + + return cppfile; + } + @Override public void tearDown() throws Exception { if (index != null) { @@ -670,6 +676,35 @@ public abstract class IndexBindingResolutionTestBase extends SemanticTestBase { public boolean isCompositeIndex() { return false; } + + protected boolean getIsCPP() { + return cpp; + } + } + + /** + * This strategy is similar to SinglePDOMTestStrategy but it does reindex project after adding all files. + */ + protected class SinglePDOMReindexedTestStrategy extends SinglePDOMTestStrategy { + + public SinglePDOMReindexedTestStrategy(boolean cpp) { + super(cpp); + } + + @Override + IFile createSourceFilesAndIndex(String headerContents, String sourceContents) throws Exception { + CCorePlugin.getIndexManager().setIndexerId(getCProject(), IPDOMManager.ID_FAST_INDEXER); + waitForIndexer(getCProject()); + + TestSourceReader.createFile(getCProject().getProject(), new Path("header.h"), headerContents); + IFile cppfile = TestSourceReader.createFile(getCProject().getProject(), + new Path("references.c" + (getIsCPP() ? "pp" : "")), sourceContents); + + CCorePlugin.getIndexManager().reindex(getCProject()); + waitForIndexer(getCProject()); + + return cppfile; + } } /** diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexDeductionGuideTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexDeductionGuideTest.java index 3481d87e745..493a9b8a6b0 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexDeductionGuideTest.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexDeductionGuideTest.java @@ -18,7 +18,6 @@ import static org.eclipse.cdt.core.parser.tests.ast2.CommonCPPTypes.double_; import static org.eclipse.cdt.core.parser.tests.ast2.CommonCPPTypes.int_; import org.eclipse.cdt.core.dom.ast.IVariable; -import org.eclipse.cdt.core.testplugin.TestScannerProvider; import junit.framework.TestSuite; @@ -26,53 +25,9 @@ import junit.framework.TestSuite; * AST tests for C++17 deduction guides via PDOM. */ public abstract class IndexDeductionGuideTest extends IndexBindingResolutionTestBase { - private static void cxx17SetUp() { - // Deduction guides are now enabled unconditionally - } - - private static void cxx17TearDown() { - TestScannerProvider.clear(); - } - - public class Cxx17ReferencedProject extends ReferencedProject { - public Cxx17ReferencedProject() { - super(true /* cpp */); - } - - @Override - public void setUp() throws Exception { - cxx17SetUp(); - super.setUp(); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - cxx17TearDown(); - } - } - - public class Cxx17SinglePDOMTestStrategy extends SinglePDOMTestStrategy { - public Cxx17SinglePDOMTestStrategy() { - super(true /* cpp */); - } - - @Override - public void setUp() throws Exception { - cxx17SetUp(); - super.setUp(); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - cxx17TearDown(); - } - } - public static class IndexDeductionGuideTestSingleProject extends IndexDeductionGuideTest { public IndexDeductionGuideTestSingleProject() { - setStrategy(new Cxx17SinglePDOMTestStrategy()); + setStrategy(new SinglePDOMTestStrategy(true /* cpp */)); } public static TestSuite suite() { @@ -80,9 +35,19 @@ public abstract class IndexDeductionGuideTest extends IndexBindingResolutionTest } } + public static class IndexDeductionGuideTestSingleProjectReindexed extends IndexDeductionGuideTest { + public IndexDeductionGuideTestSingleProjectReindexed() { + setStrategy(new SinglePDOMReindexedTestStrategy(true /* cpp */)); + } + + public static TestSuite suite() { + return suite(IndexDeductionGuideTestSingleProjectReindexed.class); + } + } + public static class IndexDeductionGuideTestProjectWithDepProj extends IndexDeductionGuideTest { public IndexDeductionGuideTestProjectWithDepProj() { - setStrategy(new Cxx17ReferencedProject()); + setStrategy(new ReferencedProject(true /* cpp */)); } public static TestSuite suite() { @@ -92,6 +57,7 @@ public abstract class IndexDeductionGuideTest extends IndexBindingResolutionTest public static void addTests(TestSuite suite) { suite.addTest(IndexDeductionGuideTestSingleProject.suite()); + suite.addTest(IndexDeductionGuideTestSingleProjectReindexed.suite()); suite.addTest(IndexDeductionGuideTestProjectWithDepProj.suite()); } @@ -135,4 +101,41 @@ public abstract class IndexDeductionGuideTest extends IndexBindingResolutionTest assertType(getBindingFromASTName("convert(", 7), varDouble.getType()); } + + // #pragma once + // + // namespace test + // { + // typedef double result_t; + // template struct Dependent; + // } + // + // template struct Intermediate + // { + // public: + // typedef test::result_t result_type; + // }; + // + // template> + // class Base { + // typedef Intermediate<_Key, _Dependent> _Intermediate; + // + // public: + // typedef typename _Intermediate::result_type result_type; + // }; + + // using BaseType = Base::result_type; // test marker + // + // namespace test_std_alternative { + // template + // class Unrelated; + // + // using namespace test; + // template + // Unrelated(_KeyInUnrelated) + // -> Unrelated<_KeyInUnrelated, Dependent<_KeyInUnrelated>>; + // } + public void testDeductionGuideTemplateIssue438() throws Exception { + getBindingFromASTName("Base::result_type; // test marker", 22); + } }