Skip to content

Commit

Permalink
added test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sigmaaa committed Aug 14, 2023
1 parent 4c3a13a commit 8d77bf1
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*******************************************************************************/
package com.espressif.idf.core.build;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
Expand All @@ -13,7 +12,6 @@

import com.espressif.idf.core.resources.OpenDialogListenerSupport;
import com.espressif.idf.core.resources.PopupDialog;
import com.espressif.idf.core.util.HintsUtil;
import com.espressif.idf.core.util.StringUtil;

/**
Expand All @@ -40,9 +38,14 @@
public class EspIdfErrorParser implements IConsoleParser
{

private List<ReHintPair> reHintsList = HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()));
private List<ReHintPair> allMatchesList = new ArrayList<>();
private List<ReHintPair> reHintsList;
private List<ReHintPair> allMatchesList;

public EspIdfErrorParser(List<ReHintPair> reHintPairs)
{
this.reHintsList = reHintPairs;
this.allMatchesList = new ArrayList<>();
}
public boolean processLine(String paramString)
{
for (ReHintPair reHintEntry : reHintsList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import com.espressif.idf.core.internal.CMakeErrorParser;
import com.espressif.idf.core.logging.Logger;
import com.espressif.idf.core.util.DfuCommandsUtil;
import com.espressif.idf.core.util.HintsUtil;
import com.espressif.idf.core.util.IDFUtil;
import com.espressif.idf.core.util.ParitionSizeHandler;
import com.espressif.idf.core.util.StringUtil;
Expand Down Expand Up @@ -423,7 +424,8 @@ private void runCmakeBuildCommand(IConsole console, IProgressMonitor monitor, IP
IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_STATUS,
IDFCorePreferenceConstants.AUTOMATE_BUILD_HINTS_DEFAULT_STATUS, null);
IConsoleParser[] consoleParsers = buildHintsStatus
? new IConsoleParser[] { epm, new StatusParser(), new EspIdfErrorParser() }
? new IConsoleParser[] { epm, new StatusParser(),
new EspIdfErrorParser(HintsUtil.getReHintsList(new File(HintsUtil.getHintsYmlPath()))) }
: new IConsoleParser[] { epm, new StatusParser() };
watchProcess(p, consoleParsers);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright 2022-2023 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.core.build.test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator;
import org.junit.jupiter.api.Test;

import com.espressif.idf.core.build.EspIdfErrorParser;
import com.espressif.idf.core.build.ReHintPair;
import com.espressif.idf.core.resources.OpenDialogListenerSupport;
import com.espressif.idf.core.resources.PopupDialog;
import com.espressif.idf.core.util.StringUtil;

@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
class EspIdfErrorParserTest
{

private static final String NON_EXISTING_ERROR_REGEX = "non existing error regex";
private static final String ERROR_LINE = "/hello_world/main/hello_world_main.c:14:10: fatal error: spiram.h: No such file or directory";
private static final String EXPECTED_HINT = "EXPECTED_HINT";
private static final String ERROR_REGEX = "fatal error: (spiram.h|esp_spiram.h): No such file or directory";

@Test
void process_line_returns_true_if_hint_available_for_error_line()
{
List<ReHintPair> reHintPairs = new ArrayList<>();
reHintPairs.add(
new ReHintPair(ERROR_REGEX, StringUtil.EMPTY));
String errorLine = ERROR_LINE;
EspIdfErrorParser ep = new EspIdfErrorParser(reHintPairs);

boolean actualResult = ep.processLine(errorLine);

assertTrue(actualResult);
}

@Test
void process_line_returns_false_if_no_hint_found_for_error_line()
{
List<ReHintPair> reHintPairs = new ArrayList<>();
reHintPairs.add(
new ReHintPair(NON_EXISTING_ERROR_REGEX, StringUtil.EMPTY));
String errorLine = ERROR_LINE;
EspIdfErrorParser ep = new EspIdfErrorParser(reHintPairs);

boolean actualResult = ep.processLine(errorLine);

assertFalse(actualResult);
}

@SuppressWarnings("unchecked")
@Test
void shutdown_should_trigger_property_change_listener_with_error_hints_pairs_as_new_value()
{
List<ReHintPair> actualReHintPair = new ArrayList<>();
OpenDialogListenerSupport.getSupport().addPropertyChangeListener(evt -> {
PopupDialog popupDialog = PopupDialog.valueOf(evt.getPropertyName());
if (popupDialog.equals(PopupDialog.AVAILABLE_HINTS))
actualReHintPair.addAll((List<ReHintPair>) evt.getNewValue());
});
List<ReHintPair> reHintPairs = new ArrayList<>();
String expectedHint = EXPECTED_HINT;
reHintPairs.add(
new ReHintPair(ERROR_REGEX, expectedHint));
String errorLine = ERROR_LINE;

EspIdfErrorParser ep = new EspIdfErrorParser(reHintPairs);
boolean actualResult = ep.processLine(errorLine);
ep.shutdown();

assertTrue(actualResult);
assertEquals(expectedHint, actualReHintPair.get(0).getHint());
assertEquals(errorLine, actualReHintPair.get(0).getRe());
}

}

0 comments on commit 8d77bf1

Please sign in to comment.