Skip to content

Commit 2772840

Browse files
Windows runner: fix LSP editor tests (#1312)
* ci: substitute SetupProject method to avoid using idf.py reconfigure * fix: applied correct formatting and add small fix to test * fix: provided updated correct drivers path * fix: improve waitCTab method logic --------- Co-authored-by: Denys Almazov <[email protected]>
1 parent 47ca2ad commit 2772840

File tree

4 files changed

+97
-81
lines changed

4 files changed

+97
-81
lines changed

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/common/utility/TestWidgetWaitUtility.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,14 @@ public static void waitForCTabToAppear(SWTWorkbenchBot workbenchBot, String tabN
277277
@Override
278278
public boolean test() throws Exception
279279
{
280-
return workbenchBot.cTabItem(tabName).isActive();
280+
try
281+
{
282+
return workbenchBot.cTabItem(tabName) != null;
283+
}
284+
catch (WidgetNotFoundException e)
285+
{
286+
return false;
287+
}
281288
}
282289

283290
@Override

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectLspCdtFunctionalityTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ public static void setupEnv() throws Exception
4848
bot = WorkBenchSWTBot.getBot();
4949
EnvSetupOperations.setupEspressifEnv(bot);
5050
ProjectTestOperations.deleteAllProjects(bot);
51-
ProjectTestOperations.setupProjectWithReconfigureCommand(PROJECT_NAME, "EspressIf", "Espressif IDF Project", //$NON-NLS-1$ //$NON-NLS-2$
52-
bot);
53-
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
51+
ProjectTestOperations.setupProject(PROJECT_NAME, "EspressIf", "Espressif IDF Project", bot);
52+
ProjectTestOperations.buildProjectUsingContextMenu(PROJECT_NAME, bot);
53+
ProjectTestOperations.waitForProjectBuild(bot);
54+
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
5455
}
5556

5657
@AfterClass

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectClangFilesTest.java

Lines changed: 71 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@
44
*******************************************************************************/
55
package com.espressif.idf.ui.test.executable.cases.project;
66

7+
import static org.junit.Assert.assertEquals;
78
import static org.junit.Assert.assertTrue;
89

9-
import java.io.File;
1010
import java.io.IOException;
1111
import java.nio.file.Path;
1212
import java.nio.file.Paths;
1313

1414
import org.eclipse.core.resources.IProject;
1515
import org.eclipse.core.resources.ResourcesPlugin;
1616
import org.eclipse.core.runtime.CoreException;
17-
import org.eclipse.core.runtime.IPath;
1817
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
1918
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
2019
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
@@ -28,13 +27,11 @@
2827
import org.junit.runner.RunWith;
2928
import org.junit.runners.MethodSorters;
3029

31-
import com.espressif.idf.core.IDFConstants;
3230
import com.espressif.idf.core.util.IDFUtil;
3331
import com.espressif.idf.ui.test.common.WorkBenchSWTBot;
3432
import com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility;
3533
import com.espressif.idf.ui.test.operations.EnvSetupOperations;
3634
import com.espressif.idf.ui.test.operations.ProjectTestOperations;
37-
import com.espressif.idf.ui.test.operations.selectors.LaunchBarConfigSelector;
3835
import com.espressif.idf.ui.test.operations.selectors.LaunchBarTargetSelector;
3936

4037
/**
@@ -116,7 +113,8 @@ public void givenNewProjectIsCreatedThenTestClangFormatFileSettingsAreBeingAppli
116113
}
117114

118115
@Test
119-
public void givenNewProjectsAreCreatedAndBuiltWhenPreferencesOpenedThenClangdArgumentMatchesExpected() throws Exception
116+
public void givenNewProjectsAreCreatedAndBuiltWhenPreferencesOpenedThenClangdArgumentMatchesExpected()
117+
throws Exception
120118
{
121119
Fixture.givenNewProjectIsCreated("NewProjectClangFilesTest4");
122120
Fixture.whenProjectIsBuiltUsingContextMenu("NewProjectClangFilesTest4");
@@ -127,7 +125,8 @@ public void givenNewProjectsAreCreatedAndBuiltWhenPreferencesOpenedThenClangdArg
127125
}
128126

129127
@Test
130-
public void givenNewProjectIsCreatedWhenBuiltThenClangdDriversUpdateOnTargetWhenChangeTargetAndBuiltThenClangdDriversUpdateOnTargetChange() throws Exception
128+
public void givenNewProjectIsCreatedWhenBuiltThenClangdDriversUpdateOnTargetWhenChangeTargetAndBuiltThenClangdDriversUpdateOnTargetChange()
129+
throws Exception
131130
{
132131
Fixture.givenNewProjectIsCreated("NewProjectClangFilesTest6");
133132
Fixture.whenProjectIsBuiltUsingContextMenu("NewProjectClangFilesTest6");
@@ -186,7 +185,7 @@ private static void thenCheckClangdArgumentAfterProjectBuilt(String projectName)
186185
Fixture.closePreferencesDialog();
187186
}
188187

189-
private static void whenNewProjectIsSelected( String projectName) throws Exception
188+
private static void whenNewProjectIsSelected(String projectName) throws Exception
190189
{
191190
ProjectTestOperations.setupProject(projectName, category, subCategory, bot);
192191
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
@@ -255,14 +254,17 @@ private static void whenClangFormatFileOpenedUsingDoubleClick() throws IOExcepti
255254

256255
private static String getExpectedBuildFolderPATH(String projectName) throws IOException
257256
{
258-
try {
259-
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
260-
String buildFolder = IDFUtil.getBuildDir(project);
261-
Path buildFolderPath = Paths.get(buildFolder);
262-
return buildFolderPath.toAbsolutePath().toString();
263-
} catch (CoreException e) {
264-
throw new IOException("Failed to get build directory for project: " + projectName, e);
265-
}
257+
try
258+
{
259+
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
260+
String buildFolder = IDFUtil.getBuildDir(project);
261+
Path buildFolderPath = Paths.get(buildFolder);
262+
return buildFolderPath.toAbsolutePath().toString();
263+
}
264+
catch (CoreException e)
265+
{
266+
throw new IOException("Failed to get build directory for project: " + projectName, e);
267+
}
266268
}
267269

268270
private static void thenClangdFileContentChecked() throws Exception
@@ -290,31 +292,32 @@ private static void thenClangFormatContentChecked() throws Exception
290292
bot.cTabItem(".clang-format").activate();
291293
assertTrue(ProjectTestOperations.checkExactMatchInTextEditor(
292294
"""
293-
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
294-
BasedOnStyle: LLVM
295-
UseTab: Always
296-
IndentWidth: 4
297-
TabWidth: 4
298-
BreakConstructorInitializers: AfterColon
299-
IndentAccessModifiers: false
300-
AccessModifierOffset: -4
301-
""",
295+
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
296+
BasedOnStyle: LLVM
297+
UseTab: Always
298+
IndentWidth: 4
299+
TabWidth: 4
300+
BreakConstructorInitializers: AfterColon
301+
IndentAccessModifiers: false
302+
AccessModifierOffset: -4
303+
""",
302304
bot));
303305
}
304306

305307
private static void thenClangFormatContentEdited() throws Exception
306308
{
307309
SWTBotEditor textEditor = bot.activeEditor();
308-
textEditor.toTextEditor().setText("""
309-
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
310-
BasedOnStyle: LLVM
311-
UseTab: Always
312-
IndentWidth: 0
313-
TabWidth: 0
314-
BreakConstructorInitializers: AfterColon
315-
IndentAccessModifiers: false
316-
AccessModifierOffset: -4
317-
""");
310+
textEditor.toTextEditor().setText(
311+
"""
312+
# We'll use defaults from the LLVM style, but with some modifications so that it's close to the CDT K&R style.
313+
BasedOnStyle: LLVM
314+
UseTab: Always
315+
IndentWidth: 0
316+
TabWidth: 0
317+
BreakConstructorInitializers: AfterColon
318+
IndentAccessModifiers: false
319+
AccessModifierOffset: -4
320+
""");
318321
}
319322

320323
private static void addSpaceToMainFile() throws Exception
@@ -391,39 +394,43 @@ private static void thenMainFileShellClosed() throws IOException
391394
bot.shell("Save Resource").bot().button("Save").click();
392395
}
393396

394-
private static String getExpectedBuildFolderPATHforClangdAdditionalArgument(String projectName) throws IOException
397+
private static String getExpectedBuildFolderPATHforClangdAdditionalArgument(String projectName)
398+
throws IOException
395399
{
396-
try {
397-
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
398-
String buildFolder = IDFUtil.getBuildDir(project);
399-
Path buildFolderPath = Paths.get(buildFolder);
400-
return "--compile-commands-dir=" + buildFolderPath.toAbsolutePath().toString();
401-
} catch (CoreException e) {
402-
throw new IOException("Failed to get build directory for project: " + projectName, e);
403-
}
400+
try
401+
{
402+
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
403+
String buildFolder = IDFUtil.getBuildDir(project);
404+
Path buildFolderPath = Paths.get(buildFolder);
405+
return "--compile-commands-dir=" + buildFolderPath.toAbsolutePath().toString();
406+
}
407+
catch (CoreException e)
408+
{
409+
throw new IOException("Failed to get build directory for project: " + projectName, e);
410+
}
404411
}
405412

406413
private static String getXtensaToolchainPathBasedOnTheTargetConfigured() throws IOException
407414
{
408-
String toolchain = IDFUtil.getToolchainExePathForActiveTarget();
415+
String toolchain = IDFUtil.getToolchainExePathForActiveTarget();
409416
Path toolchainPath = Paths.get(toolchain);
410417
return toolchainPath.toAbsolutePath().toString();
411418
}
412419

413420
private static void thenCompareActualClangdArgumentWithExpected(String projectName) throws IOException
414-
{
415-
SWTBotShell prefrencesShell = bot.shell("Preferences");
416-
String actualClangdPath = prefrencesShell.bot().textWithLabel("Additional").getText();
417-
String expectedClangdPath = getExpectedBuildFolderPATHforClangdAdditionalArgument(projectName);
418-
assertTrue(expectedClangdPath.equals(actualClangdPath));
421+
{
422+
SWTBotShell prefrencesShell = bot.shell("Preferences");
423+
String actualClangdPath = prefrencesShell.bot().textWithLabel("Additional").getText();
424+
String expectedClangdPath = getExpectedBuildFolderPATHforClangdAdditionalArgument(projectName);
425+
assertTrue(expectedClangdPath.equals(actualClangdPath));
419426
}
420427

421428
private static void thenCompareActualClangdDriversWithExpected(String projectName) throws IOException
422-
{
423-
SWTBotShell prefrencesShell = bot.shell("Preferences");
424-
String actualClangdPath = prefrencesShell.bot().textWithLabel("Drivers").getText();
425-
String expectedClangdPath = getXtensaToolchainPathBasedOnTheTargetConfigured();
426-
assertTrue(expectedClangdPath.equals(actualClangdPath));
429+
{
430+
SWTBotShell prefrencesShell = bot.shell("Preferences");
431+
String actualDriversPath = prefrencesShell.bot().textWithLabel("Drivers").getText();
432+
String expectedDriversPath = "**";
433+
assertEquals(expectedDriversPath, actualDriversPath);
427434
}
428435

429436
private static void whenProjectIsBuiltUsingContextMenu(String projectName) throws IOException
@@ -444,17 +451,19 @@ private static void whenOpenClangdPreferences() throws Exception
444451
prefrencesShell.bot().tree().getTreeItem("C/C++").getNode("Editor (LSP)").getNode("clangd").select();
445452
}
446453

447-
private static void closePreferencesDialog() {
448-
SWTBotShell preferencesShell = bot.shell("Preferences");
449-
preferencesShell.bot().button("Cancel").click(); // Or "Apply and Close"
450-
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "Preferences", 10000);
454+
private static void closePreferencesDialog()
455+
{
456+
SWTBotShell preferencesShell = bot.shell("Preferences");
457+
preferencesShell.bot().button("Cancel").click(); // Or "Apply and Close"
458+
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "Preferences", 10000);
451459
}
452460

453-
private static void closeTargetDialog() {
461+
private static void closeTargetDialog()
462+
{
454463
TestWidgetWaitUtility.waitForDialogToAppear(bot, "IDF Launch Target Changed", 10000);
455-
SWTBotShell preferencesShell = bot.shell("IDF Launch Target Changed");
456-
preferencesShell.bot().button("Yes").click(); // Or "Apply and Close"
457-
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "IDF Launch Target Changed", 10000);
464+
SWTBotShell preferencesShell = bot.shell("IDF Launch Target Changed");
465+
preferencesShell.bot().button("Yes").click(); // Or "Apply and Close"
466+
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "IDF Launch Target Changed", 10000);
458467
}
459468

460469
private static void cleanTestEnv()

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectSDKconfigTest.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,26 +172,26 @@ private static void whenProjectIsBuiltUsingContextMenu() throws IOException
172172

173173
private static void thenSDKconfigFileIsPresent() throws IOException
174174
{
175-
assertTrue(bot.tree().getTreeItem(projectName).getNode("sdkconfig") != null);
175+
assertTrue("SDKconfig file was not found", bot.tree().getTreeItem(projectName).getNode("sdkconfig") != null);
176176
}
177177

178178
private static void thenSDKconfigFileIsAbsent() throws IOException
179179
{
180-
assertTrue(!bot.tree().getTreeItem(projectName).getNodes().contains("sdkconfig"));
180+
assertTrue("SDKconfig file is still present",!bot.tree().getTreeItem(projectName).getNodes().contains("sdkconfig"));
181181
}
182182

183183
private static void whenSDKconfigFileOpenedUsingDoubleClick() throws IOException
184184
{
185185
bot.tree().getTreeItem(projectName).getNode("sdkconfig").doubleClick();
186186
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "Progress Information", 40000);
187-
TestWidgetWaitUtility.waitForCTabToAppear(bot, "SDK Configuration (sdkconfig)", 5000);
187+
TestWidgetWaitUtility.waitForCTabToAppear(bot, "SDK Configuration (sdkconfig)", 10000);
188188
}
189189

190190
private static void whenSDKconfigFileOpenedUsingContextMenu() throws IOException
191191
{
192192
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Menu Config");
193193
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "Progress Information", 40000);
194-
TestWidgetWaitUtility.waitForCTabToAppear(bot, "SDK Configuration (sdkconfig)", 5000);
194+
TestWidgetWaitUtility.waitForCTabToAppear(bot, "SDK Configuration (sdkconfig)", 10000);
195195
}
196196

197197
private static void thenSDKconfigFileContentChecked() throws Exception
@@ -200,7 +200,7 @@ private static void thenSDKconfigFileContentChecked() throws Exception
200200
TestWidgetWaitUtility.waitForTreeItem("Partition Table", bot.tree(1), bot);
201201
bot.tree(1).getTreeItem("Partition Table").click();
202202
bot.sleep(1000);
203-
assertTrue(bot.textWithLabel("Offset of partition table (hex)").getText().matches("0x8000"));
203+
assertTrue("'Offset of partition table (hex)' does not match '0x8000'", bot.textWithLabel("Offset of partition table (hex)").getText().matches("0x8000"));
204204
}
205205

206206
private static void thenSDKconfigFileContentEdited() throws Exception
@@ -210,9 +210,9 @@ private static void thenSDKconfigFileContentEdited() throws Exception
210210
bot.tree(1).getTreeItem("Partition Table").click();
211211
bot.sleep(1000);
212212
bot.textWithLabel("Offset of partition table (hex)").setText("0x4000");
213-
bot.sleep(2000);
213+
bot.sleep(1000);
214214
bot.comboBoxWithLabel("Partition Table").setSelection("Custom partition table CSV");
215-
bot.sleep(2000);
215+
bot.sleep(1000);
216216
bot.checkBox("Generate an MD5 checksum for the partition table").click();
217217
}
218218

@@ -225,8 +225,7 @@ private static void whenSDKconfigFileIsSaved() throws IOException
225225
{
226226
bot.cTabItem("*SDK Configuration (sdkconfig)").activate();
227227
bot.cTabItem("*SDK Configuration (sdkconfig)").close();
228-
bot.sleep(5000);
229-
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Save Resource", 5000);
228+
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Save Resource", 10000);
230229
bot.shell("Save Resource").bot().button("Save").click();
231230
}
232231

@@ -235,12 +234,12 @@ private static void thenCheckChangesAreSaved() throws Exception
235234
bot.cTabItem("SDK Configuration (sdkconfig)").activate();
236235
TestWidgetWaitUtility.waitForTreeItem("Partition Table", bot.tree(1), bot);
237236
bot.tree(1).getTreeItem("Partition Table").click();
238-
bot.sleep(2000);
239-
assertTrue(bot.textWithLabel("Offset of partition table (hex)").getText().matches("0x4000"));
240-
bot.sleep(2000);
241-
assertTrue(bot.comboBoxWithLabel("Partition Table").selection().equals("Custom partition table CSV"));
242-
bot.sleep(2000);
243-
assertTrue(!bot.checkBox("Generate an MD5 checksum for the partition table").isChecked());
237+
bot.sleep(1000);
238+
assertTrue("'Offset of partition table (hex)' does not match '0x4000'", bot.textWithLabel("Offset of partition table (hex)").getText().matches("0x4000"));
239+
bot.sleep(1000);
240+
assertTrue("'Partition Table' does not match 'Custom partition table CSV'", bot.comboBoxWithLabel("Partition Table").selection().equals("Custom partition table CSV"));
241+
bot.sleep(1000);
242+
assertTrue("'Generate an MD5 checksum for the partition table' checkbox is still checked!", !bot.checkBox("Generate an MD5 checksum for the partition table").isChecked());
244243
}
245244

246245
private static void cleanTestEnv()

0 commit comments

Comments
 (0)