1 | import java.io.BufferedReader;
|
---|
2 | import java.io.File;
|
---|
3 | import java.io.FileOutputStream;
|
---|
4 | import java.io.FileReader;
|
---|
5 | import java.io.IOException;
|
---|
6 | import java.io.PrintStream;
|
---|
7 |
|
---|
8 | import junit.framework.TestCase;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * This is an integration test.
|
---|
12 | *
|
---|
13 | * The class Yylex is generated by JFLex from
|
---|
14 | * <code>src/main/jflex/simple.flex</code>.
|
---|
15 | *
|
---|
16 | * @author regis
|
---|
17 | *
|
---|
18 | */
|
---|
19 | public class YylexTest extends TestCase {
|
---|
20 |
|
---|
21 | private static final String OUTPUT_FILE = "target/output.actual";
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Test that Yylex parser behaves like expected.
|
---|
25 | *
|
---|
26 | * @throws IOException
|
---|
27 | */
|
---|
28 | public void testOutput() throws IOException {
|
---|
29 | String[] argv = new String[1];
|
---|
30 | argv[0] = "src/test/resources/test.txt";
|
---|
31 |
|
---|
32 | // the Yylex prints status on stdout
|
---|
33 | File actual = new File("target/output.actual");
|
---|
34 | actual.delete();
|
---|
35 | FileOutputStream fos = new FileOutputStream(OUTPUT_FILE, true);
|
---|
36 | System.setOut(new PrintStream(fos));
|
---|
37 |
|
---|
38 | Yylex.main(argv);
|
---|
39 |
|
---|
40 | fos.close();
|
---|
41 |
|
---|
42 | // test actual is expected
|
---|
43 | File expected = new File("src/test/resources/output.good");
|
---|
44 | assertTrue(expected.isFile());
|
---|
45 | assertTrue(actual.isFile());
|
---|
46 |
|
---|
47 | BufferedReader actualContent = new BufferedReader(
|
---|
48 | new FileReader(actual));
|
---|
49 | BufferedReader expectedContent = new BufferedReader(new FileReader(
|
---|
50 | expected));
|
---|
51 |
|
---|
52 | for (int lineNumber = 1;lineNumber!=-1; lineNumber++) {
|
---|
53 | String expectedLine = expectedContent.readLine();
|
---|
54 | String actualLine = actualContent.readLine();
|
---|
55 | assertEquals("Line "+lineNumber, expectedLine, actualLine);
|
---|
56 | if (expectedLine==null) lineNumber=-2; //EOF
|
---|
57 | }
|
---|
58 | }
|
---|
59 | }
|
---|