blob: 3ce35680c403c8919671a5428a26bff08d1a7696 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.anarres.cpp;
import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.google.common.io.PatternFilenameFilter;
import java.io.File;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
/**
*
* @author shevek
*/
@RunWith(Parameterized.class)
public class RegressionTest {
private static final Logger LOG = LoggerFactory.getLogger(RegressionTest.class);
@Parameterized.Parameters(name = "{0}")
public static List<Object[]> data() throws Exception {
List<Object[]> out = new ArrayList<Object[]>();
File dir = new File("build/resources/test/regression");
for (File inFile : dir.listFiles(new PatternFilenameFilter(".*\\.in"))) {
String name = Files.getNameWithoutExtension(inFile.getName());
File outFile = new File(dir, name + ".out");
out.add(new Object[]{name, inFile, outFile});
}
return out;
}
private final String name;
private final File inFile;
private final File outFile;
public RegressionTest(String name, File inFile, File outFile) {
this.name = name;
this.inFile = inFile;
this.outFile = outFile;
}
@Test
public void testRegression() throws Exception {
String inText = Files.toString(inFile, Charsets.UTF_8);
LOG.info("Read " + name + ":\n" + inText);
CppReader cppReader = new CppReader(new StringReader(inText));
String cppText = CharStreams.toString(cppReader);
LOG.info("Generated " + name + ":\n" + cppText);
if (outFile.exists()) {
String outText = Files.toString(outFile, Charsets.UTF_8);
LOG.info("Expected " + name + ":\n" + outText);
assertEquals(outText, inText);
}
}
}
|