Skip to content
Open
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
@@ -0,0 +1,137 @@
package com.espressif.idf.ui.test;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
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.SWTBotCanvas;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.espressif.idf.ui.test.operations.EnvSetupOperations;

@RunWith(SWTBotJunit4ClassRunner.class)
public class TerminalViewTest
{

private static SWTWorkbenchBot bot;

@BeforeClass
public static void setup() throws Exception
{

bot = new SWTWorkbenchBot();
EnvSetupOperations.setupEspressifEnv(bot);
}

@AfterClass
public static void cleanup() throws Exception
{
try
{
SWTBotView terminalView = bot.viewByTitle("Terminal");
terminalView.close();
}
catch (WidgetNotFoundException ignored)
{
}

}

@Test
public void testOpenTerminalView() throws Exception
{
// Create a temporary file for capturing terminal output
Path tempFile = Files.createTempFile("idf_version_output", ".txt");
File outputFile = tempFile.toFile();
outputFile.deleteOnExit(); // ensure cleanup after JVM exits

Comment on lines +56 to +60
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Quote the temp file path in the shell redirection command

outputFile.getAbsolutePath() can contain spaces (very common on Windows home directories), so idf.py --version > <path> will misparse and likely fail. Wrap the path in quotes when building cmd so redirection works on all platforms.

-		// Command with temporary file
-		String cmd = "idf.py --version > " + outputFile.getAbsolutePath();
+		// Command with temporary file (quote path to handle spaces)
+		String cmd = "idf.py --version > \"" + outputFile.getAbsolutePath() + "\"";

Also applies to: 98-100

🤖 Prompt for AI Agents
In
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java
around lines 56-60 (and also apply the same change at lines 98-100), the
temporary output file path is used raw in a shell redirection which can break if
the path contains spaces; update the code that builds the command so the
outputFile.getAbsolutePath() is wrapped in quotes (e.g., "..." ) when inserted
into the redirection portion of the cmd string, ensuring the path is properly
quoted on all platforms.

String[] tooltips = { "Open a Terminal (Ctrl+Alt+Shift+T)", "Open a Terminal (Shift+Ctrl+Alt+T)",
"Open a Terminal" };

SWTBotToolbarButton openTerminalButton = null;

for (String tooltip : tooltips)
{
try
{
openTerminalButton = bot.toolbarButtonWithTooltip(tooltip);
break; // stop at the first one found
}
catch (WidgetNotFoundException ignored)
{
// try next tooltip
}
}

if (openTerminalButton == null)
{
throw new WidgetNotFoundException("Toolbar button 'Open a Terminal' not found with any known tooltip");
}

openTerminalButton.click();
bot.comboBox().setSelection("ESP-IDF Terminal");
bot.button("OK").click();
SWTBotView terminalView = bot.viewByTitle("Terminal");
terminalView.show();
terminalView.setFocus();

// Wait for terminal to initialize
bot.sleep(3000);

// Type command into the Canvas terminal
SWTBotCanvas canvas = terminalView.bot().canvas();
canvas.setFocus();

// Command with temporary file
String cmd = "idf.py --version > " + outputFile.getAbsolutePath();
canvas.display.syncExec(() -> {
for (char c : cmd.toCharArray())
{
Event e = new Event();
e.type = SWT.KeyDown;
e.character = c;
canvas.widget.notifyListeners(SWT.KeyDown, e);

Event e2 = new Event();
e2.type = SWT.KeyUp;
e2.character = c;
canvas.widget.notifyListeners(SWT.KeyUp, e2);
}

// Press Enter
Event enterDown = new Event();
enterDown.type = SWT.KeyDown;
enterDown.character = '\r';
canvas.widget.notifyListeners(SWT.KeyDown, enterDown);

Event enterUp = new Event();
enterUp.type = SWT.KeyUp;
enterUp.character = '\r';
canvas.widget.notifyListeners(SWT.KeyUp, enterUp);
});

// Wait for the command to execute
bot.sleep(5000);

// Read the output from the temporary file
String output = new String(Files.readAllBytes(tempFile), StandardCharsets.UTF_8);

assertTrue("Output should contain 'IDF v'", output.contains("IDF v"));
Comment on lines +129 to +132
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add verification that the file was written before asserting content.

The test reads the file and asserts it contains "IDF v" without checking if:

  • The file is non-empty
  • The command actually executed
  • The command succeeded vs. failed

If the file is empty or the command failed, the assertion message "Output should contain 'IDF v'" doesn't help diagnose the root cause.

Apply this diff to add pre-assertion checks:

 		// Read the output from the temporary file
 		String output = new String(Files.readAllBytes(tempFile), StandardCharsets.UTF_8);
 
+		assertTrue("Output file should not be empty - command may have failed", 
+			!output.trim().isEmpty());
 		assertTrue("Output should contain 'IDF v'", output.contains("IDF v"));

Alternatively, combine into a more informative message:

-		assertTrue("Output should contain 'IDF v'", output.contains("IDF v"));
+		assertTrue(
+			String.format("Expected output to contain 'IDF v' but got: '%s'", 
+				output.trim().isEmpty() ? "<empty>" : output.substring(0, Math.min(100, output.length()))),
+			output.contains("IDF v"));
📝 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
// Read the output from the temporary file
String output = new String(Files.readAllBytes(tempFile), StandardCharsets.UTF_8);
assertTrue("Output should contain 'IDF v'", output.contains("IDF v"));
// Read the output from the temporary file
String output = new String(Files.readAllBytes(tempFile), StandardCharsets.UTF_8);
assertTrue("Output file should not be empty - command may have failed",
!output.trim().isEmpty());
assertTrue("Output should contain 'IDF v'", output.contains("IDF v"));
🤖 Prompt for AI Agents
In
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java
around lines 89-92, add pre-assertion checks so the temporary file was actually
written and the command likely succeeded before asserting content: verify the
file is non-empty (e.g. Files.size(tempFile) > 0 or output.length() > 0) and
include the actual file contents in the assertion message for easier diagnosis;
if you have access to the process/command result also assert the process exit
code is zero or that stderr is empty, then replace the existing assertTrue with
a more informative assertion that includes the output (e.g. "Expected output to
contain 'IDF v', actual output: " + output).

// Optional: delete the temp file explicitly after test
Files.deleteIfExists(tempFile);
}

}
Loading