Changeset 1210


Ignore:
Timestamp:
Jul 12, 2011, 9:04:05 PM (6 years ago)
Author:
stefan
Message:

improved detection of warning in latex output and added tests

Location:
trunk
Files:
1 added
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/errorhighlighting/LatexCompileError.java

    r1162 r1210  
    3333    return type;
    3434  }
     35
     36  public String getTypeString() {
     37    switch (type) {
     38      case TYPE_ERROR: return "error";
     39      case TYPE_WARNING: return "warning";
     40      case TYPE_OVERFULL_HBOX: return "overfull hbox";
     41    }
     42    return null;
     43  }
    3544
    3645  public void setType(int type) {
  • trunk/src/jlatexeditor/errorhighlighting/LatexCompiler.java

    r1209 r1210  
    207207        error.setFile(SystemUtils.newFile(file.getParentFile(), fileName), fileName);
    208208
    209         int linePos = line.indexOf("on input line ");
     209        String unwrappedLine = line;
     210        while (!unwrappedLine.endsWith(".")) {
     211          line = in.readLine();
     212          errorView.appendLine(line);
     213          unwrappedLine += line;
     214        }
     215
     216        int linePos = unwrappedLine.indexOf("on input line ");
    210217        if (linePos != -1) {
    211218          linePos += "on input line ".length();
    212219          try {
    213             error.setLine(Integer.parseInt(line.substring(linePos, line.indexOf('.', linePos))));
     220            error.setLine(Integer.parseInt(unwrappedLine.substring(linePos, unwrappedLine.indexOf('.', linePos))));
    214221          } catch (Exception ignored) {
    215222          }
    216223        }
    217224
    218         StringBuffer errorMessage = new StringBuffer(line.substring(line.indexOf(':') + 1).trim());
     225        StringBuffer errorMessage = new StringBuffer(unwrappedLine.substring(unwrappedLine.indexOf(':') + 1).trim());
    219226        for (int i = 0; i < 5; i++) {
    220227          line = in.readLine();
  • trunk/test/src/jlatexeditor/errorhighlighting/LatexCompilerTest.java

    r1209 r1210  
    33import jlatexeditor.ErrorView;
    44import junit.framework.TestCase;
     5import util.StreamUtils;
     6import util.SystemUtils;
    57
    68import java.io.*;
     
    1012 */
    1113public class LatexCompilerTest extends TestCase {
    12   public void testCompiler() throws IOException {
     14  public void testCompilerOutput() throws IOException {
     15    File dir = new File("test/resources/latex_output");
     16    File[] latexOuts = dir.listFiles(new FilenameFilter() {
     17      @Override
     18      public boolean accept(File dir, String name) {
     19        return name.endsWith(".latex-out");
     20      }
     21    });
     22
     23    for (File latexOut : latexOuts) {
     24      File parseOut = new File(latexOut.getPath().substring(0, latexOut.getPath().length() - 10) + ".parse-out");
     25
     26      compareParseOutput(latexOut, parseOut);
     27    }
     28  }
     29
     30  private void compareParseOutput(File latexOut, File parseOut) throws IOException {
    1331    ErrorView errorView = new ErrorView(null);
    1432    LatexCompiler compiler = LatexCompiler.createInstance(LatexCompiler.Type.pdf, null, errorView);
    1533
    16     compiler.parseLatexOutput(new File("."), new BufferedReader(new InputStreamReader(new FileInputStream("test/resources/latex_output/output1.txt"))));
     34    compiler.parseLatexOutput(new File("."), new BufferedReader(new InputStreamReader(new FileInputStream(latexOut))));
     35
     36    StringBuilder sb = new StringBuilder();
     37    for (LatexCompileError latexCompileError : errorView.getErrors()) {
     38      sb.append(latexCompileError.getTypeString()).append(":\n");
     39      sb.append(latexCompileError.toString()).append("\n");
     40    }
     41
     42    String parseOutContent = StreamUtils.readFile(parseOut.getPath());
     43
     44    assertEquals(parseOutContent, sb.toString());
    1745  }
    1846}
Note: See TracChangeset for help on using the changeset viewer.