Skip to content

Commit

Permalink
Add test for deduction guide template vs index issue
Browse files Browse the repository at this point in the history
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
  • Loading branch information
i-garrison authored and jonahgraham committed Dec 28, 2023
1 parent a7bfdd2 commit 215daef
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,7 @@ public void setUp() throws Exception {

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());
Expand All @@ -650,6 +644,18 @@ public void setUp() throws Exception {
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) {
Expand All @@ -670,6 +676,35 @@ public IIndex getIndex() {
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;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,71 +18,36 @@
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;

/**
* 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();
public static class IndexDeductionGuideTestSingleProject extends IndexDeductionGuideTest {
public IndexDeductionGuideTestSingleProject() {
setStrategy(new SinglePDOMTestStrategy(true /* cpp */));
}

@Override
public void tearDown() throws Exception {
super.tearDown();
cxx17TearDown();
public static TestSuite suite() {
return suite(IndexDeductionGuideTestSingleProject.class);
}
}

public static class IndexDeductionGuideTestSingleProject extends IndexDeductionGuideTest {
public IndexDeductionGuideTestSingleProject() {
setStrategy(new Cxx17SinglePDOMTestStrategy());
public static class IndexDeductionGuideTestSingleProjectReindexed extends IndexDeductionGuideTest {
public IndexDeductionGuideTestSingleProjectReindexed() {
setStrategy(new SinglePDOMReindexedTestStrategy(true /* cpp */));
}

public static TestSuite suite() {
return suite(IndexDeductionGuideTestSingleProject.class);
return suite(IndexDeductionGuideTestSingleProjectReindexed.class);
}
}

public static class IndexDeductionGuideTestProjectWithDepProj extends IndexDeductionGuideTest {
public IndexDeductionGuideTestProjectWithDepProj() {
setStrategy(new Cxx17ReferencedProject());
setStrategy(new ReferencedProject(true /* cpp */));
}

public static TestSuite suite() {
Expand All @@ -92,6 +57,7 @@ public static TestSuite suite() {

public static void addTests(TestSuite suite) {
suite.addTest(IndexDeductionGuideTestSingleProject.suite());
suite.addTest(IndexDeductionGuideTestSingleProjectReindexed.suite());
suite.addTest(IndexDeductionGuideTestProjectWithDepProj.suite());
}

Expand Down Expand Up @@ -135,4 +101,41 @@ public void testDeductionGuideBasicHeader() throws Exception {

assertType(getBindingFromASTName("convert(", 7), varDouble.getType());
}

// #pragma once
//
// namespace test
// {
// typedef double result_t;
// template<typename _Tp = void> struct Dependent;
// }
//
// template<typename _Key, typename _Equal> struct Intermediate
// {
// public:
// typedef test::result_t result_type;
// };
//
// template<typename _Key, typename _Dependent = test::Dependent<_Key>>
// class Base {
// typedef Intermediate<_Key, _Dependent> _Intermediate;
//
// public:
// typedef typename _Intermediate::result_type result_type;
// };

// using BaseType = Base<int>::result_type; // test marker
//
// namespace test_std_alternative {
// template<typename A, typename B>
// class Unrelated;
//
// using namespace test;
// template<typename _KeyInUnrelated>
// Unrelated(_KeyInUnrelated)
// -> Unrelated<_KeyInUnrelated, Dependent<_KeyInUnrelated>>;
// }
public void testDeductionGuideTemplateIssue438() throws Exception {
getBindingFromASTName("Base<int>::result_type; // test marker", 22);
}
}

0 comments on commit 215daef

Please sign in to comment.