Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.junit.After;
Expand All @@ -32,7 +31,6 @@
import com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility;
import com.espressif.idf.ui.test.operations.EnvSetupOperations;
import com.espressif.idf.ui.test.operations.ProjectTestOperations;
import com.espressif.idf.ui.test.operations.selectors.LaunchBarTargetSelector;

/**
* Test class to test Clangd / Clang-Format files functionality
Expand Down Expand Up @@ -125,15 +123,11 @@ public void givenNewProjectsAreCreatedAndBuiltWhenPreferencesOpenedThenClangdArg
}

@Test
public void givenNewProjectIsCreatedWhenBuiltThenClangdDriversUpdateOnTargetWhenChangeTargetAndBuiltThenClangdDriversUpdateOnTargetChange()
throws Exception
public void givenNewProjectIsCreatedThenClangdAndQueryDriversPathsAreUpdated() throws Exception
{
Fixture.givenNewProjectIsCreated("NewProjectClangFilesTest6");
Fixture.whenProjectIsBuiltUsingContextMenu("NewProjectClangFilesTest6");
Fixture.thenClangdDriversUpdateOnSelectedTarget();
Fixture.whenChangeTarget();
Fixture.whenProjectIsBuiltUsingContextMenu("NewProjectClangFilesTest6");
Fixture.thenClangdDriversUpdateOnSelectedTarget();
Fixture.thenClangdPathUpdateOnSelectedTarget();
Fixture.thenQueryDriversUpdateOnSelectedTarget();
}

private static class Fixture
Expand All @@ -142,22 +136,13 @@ private static class Fixture
private static String category;
private static String subCategory;
private static String projectName;
private static LaunchBarTargetSelector launchBarTargetSelector;

private static void loadEnv() throws Exception
{
bot = WorkBenchSWTBot.getBot();
EnvSetupOperations.setupEspressifEnv(bot);
bot.sleep(1000);
ProjectTestOperations.deleteAllProjects(bot);
try
{
launchBarTargetSelector = new LaunchBarTargetSelector(bot);
}
catch (WidgetNotFoundException e)
{
launchBarTargetSelector = new LaunchBarTargetSelector(bot, false);
}
}

private static void givenNewEspressifIDFProjectIsSelected(String category, String subCategory)
Expand Down Expand Up @@ -197,17 +182,16 @@ private static void whenNewProjectIsSelected(String projectName) throws Exceptio
bot.sleep(1000);
}

private static void thenClangdDriversUpdateOnSelectedTarget() throws Exception
private static void thenClangdPathUpdateOnSelectedTarget() throws Exception
{
whenOpenClangdPreferences();
thenCompareActualClangdDriversWithExpected("NewProjectClangFilesTest6");
closePreferencesDialog();
thenCompareActualClangdPathWithExpected("NewProjectClangFilesTest6");
}
Comment on lines +185 to 189
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Use the projectName field instead of hardcoding the project name.

Line 188 hardcodes "NewProjectClangFilesTest6" instead of using the projectName field available in the Fixture class. This makes the code brittle and violates the DRY principle.

Apply this diff to use the field:

-		thenCompareActualClangdPathWithExpected("NewProjectClangFilesTest6");
+		thenCompareActualClangdPathWithExpected(projectName);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private static void thenClangdPathUpdateOnSelectedTarget() throws Exception
{
whenOpenClangdPreferences();
thenCompareActualClangdDriversWithExpected("NewProjectClangFilesTest6");
closePreferencesDialog();
thenCompareActualClangdPathWithExpected("NewProjectClangFilesTest6");
}
private static void thenClangdPathUpdateOnSelectedTarget() throws Exception
{
whenOpenClangdPreferences();
thenCompareActualClangdPathWithExpected(projectName);
}
🤖 Prompt for AI Agents
In
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectClangFilesTest.java
around lines 185–189, the call
thenCompareActualClangdPathWithExpected("NewProjectClangFilesTest6") uses a
hardcoded project name; replace the string literal with the projectName field
from the Fixture class (e.g.
thenCompareActualClangdPathWithExpected(Fixture.projectName)) so the test uses
the shared fixture value instead of a brittle hardcoded name.


private static void whenChangeTarget() throws Exception
private static void thenQueryDriversUpdateOnSelectedTarget() throws Exception
{
Fixture.thenLaunchTargetIsSelectedFromLaunchTargets("esp32s2");
Fixture.closeTargetDialog();
thenCompareActualQueryDriversWithExpected("NewProjectClangFilesTest6");
closePreferencesDialog();
}
Comment on lines +191 to 195
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Use the projectName field instead of hardcoding the project name.

Line 193 hardcodes "NewProjectClangFilesTest6" instead of using the projectName field. This creates unnecessary coupling and makes the method less reusable.

Apply this diff to use the field:

-		thenCompareActualQueryDriversWithExpected("NewProjectClangFilesTest6");
+		thenCompareActualQueryDriversWithExpected(projectName);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private static void thenQueryDriversUpdateOnSelectedTarget() throws Exception
{
Fixture.thenLaunchTargetIsSelectedFromLaunchTargets("esp32s2");
Fixture.closeTargetDialog();
thenCompareActualQueryDriversWithExpected("NewProjectClangFilesTest6");
closePreferencesDialog();
}
private static void thenQueryDriversUpdateOnSelectedTarget() throws Exception
{
thenCompareActualQueryDriversWithExpected(projectName);
closePreferencesDialog();
}


private static void thenClangdFileIsPresent() throws IOException
Expand Down Expand Up @@ -282,11 +266,6 @@ private static void thenClangdFileContentCheckedAgain(String projectName) throws
"CompileFlags:\n" + " CompilationDatabase: " + buildPath + "\n" + " Remove: [-m*, -f*]", bot));
}

public static void thenLaunchTargetIsSelectedFromLaunchTargets(String launchTargetName)
{
launchBarTargetSelector.select(launchTargetName);
}

private static void thenClangFormatContentChecked() throws Exception
{
bot.cTabItem(".clang-format").activate();
Expand Down Expand Up @@ -410,13 +389,6 @@ private static String getExpectedBuildFolderPATHforClangdAdditionalArgument(Stri
}
}

private static String getXtensaToolchainPathBasedOnTheTargetConfigured() throws IOException
{
String toolchain = IDFUtil.getToolchainExePathForActiveTarget();
Path toolchainPath = Paths.get(toolchain);
return toolchainPath.toAbsolutePath().toString();
}

private static void thenCompareActualClangdArgumentWithExpected(String projectName) throws IOException
{
SWTBotShell prefrencesShell = bot.shell("Preferences");
Expand All @@ -425,12 +397,20 @@ private static void thenCompareActualClangdArgumentWithExpected(String projectNa
assertTrue(expectedClangdPath.equals(actualClangdPath));
}

private static void thenCompareActualClangdDriversWithExpected(String projectName) throws IOException
private static void thenCompareActualQueryDriversWithExpected(String projectName) throws IOException
{
SWTBotShell prefrencesShell = bot.shell("Preferences");
String actualQueryDriversPath = prefrencesShell.bot().textWithLabel("Drivers").getText();
String expectedQueryDriversPath = "**";
assertEquals(expectedQueryDriversPath, actualQueryDriversPath);
}
Comment on lines +400 to +406
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Remove unused parameter and clarify the expected value.

The method has two issues:

  1. The projectName parameter is declared but never used in the method body.
  2. The expected value "**" is a magic string without explanation. Add a comment or constant to clarify what this represents in the context of query drivers.

Apply this diff to remove the unused parameter:

-	private static void thenCompareActualQueryDriversWithExpected(String projectName) throws IOException
+	private static void thenCompareActualQueryDriversWithExpected() throws IOException
 	{
 		SWTBotShell prefrencesShell = bot.shell("Preferences");
 		String actualQueryDriversPath = prefrencesShell.bot().textWithLabel("Drivers").getText();
-		String expectedQueryDriversPath = "**";
+		// "**" matches all drivers in the query driver path
+		String expectedQueryDriversPath = "**";
 		assertEquals(expectedQueryDriversPath, actualQueryDriversPath);
 	}

And update the call site at line 193:

-	thenCompareActualQueryDriversWithExpected(projectName);
+	thenCompareActualQueryDriversWithExpected();

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectClangFilesTest.java
around lines 400-406, remove the unused projectName parameter from
thenCompareActualQueryDriversWithExpected, update its signature to take no
parameters, and update the caller at line 193 to call the method with no
argument; replace the magic string "**" with a named constant (e.g.,
EXPECTED_QUERY_DRIVERS) declared at class scope with a short comment explaining
what "**" signifies in the query drivers context, and use that constant in the
assertion.


private static void thenCompareActualClangdPathWithExpected(String projectName) throws IOException
{
SWTBotShell prefrencesShell = bot.shell("Preferences");
String actualDriversPath = prefrencesShell.bot().textWithLabel("Drivers").getText();
String expectedDriversPath = "**";
assertEquals(expectedDriversPath, actualDriversPath);
String actualClangdPath = prefrencesShell.bot().textWithLabel("Path").getText();
String expectedClangdPath = "bin";
assertTrue(actualClangdPath.contains(expectedClangdPath));
}

private static void whenProjectIsBuiltUsingContextMenu(String projectName) throws IOException
Expand All @@ -454,18 +434,10 @@ private static void whenOpenClangdPreferences() throws Exception
private static void closePreferencesDialog()
{
SWTBotShell preferencesShell = bot.shell("Preferences");
preferencesShell.bot().button("Cancel").click(); // Or "Apply and Close"
preferencesShell.bot().button("Cancel").click();
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "Preferences", 10000);
}

private static void closeTargetDialog()
{
TestWidgetWaitUtility.waitForDialogToAppear(bot, "IDF Launch Target Changed", 10000);
SWTBotShell preferencesShell = bot.shell("IDF Launch Target Changed");
preferencesShell.bot().button("Yes").click(); // Or "Apply and Close"
TestWidgetWaitUtility.waitWhileDialogIsVisible(bot, "IDF Launch Target Changed", 10000);
}

private static void cleanTestEnv()
{
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
Expand Down
Loading