diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java | 26 | ||||
-rw-r--r-- | src/test/resources/absolute.h | 1 |
2 files changed, 14 insertions, 13 deletions
diff --git a/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java b/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java index 99ebf8f..df7ffb7 100644 --- a/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java +++ b/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java @@ -1,10 +1,13 @@ package org.anarres.cpp; +import com.google.common.io.CharStreams; import java.io.BufferedReader; +import java.io.File; import java.io.Reader; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.Assert.*; /** * @@ -14,22 +17,19 @@ public class IncludeAbsoluteTest { private static final Logger LOG = LoggerFactory.getLogger(IncludeAbsoluteTest.class); - // TODO: Rewrite this test to get the CWD and read a file with known content in the test suite. - // Guava (available in test suite) can map a URL to a File resource. @Test public void testAbsoluteInclude() throws Exception { + File file = new File("build/resources/test/absolute.h"); + assertTrue(file.exists()); + + String input = "#include <" + file.getAbsolutePath() + ">\n"; + LOG.info("Input: " + input); Preprocessor pp = new Preprocessor(); - pp.getSystemIncludePath().add("/usr/include"); - pp.getSystemIncludePath().add("/usr/include/x86_64-linux-gnu"); - pp.addInput(new StringLexerSource( - "#include </usr/include/features.h>\n" - + "", true)); + pp.addInput(new StringLexerSource(input, true)); Reader r = new CppReader(pp); - // This will error if the file isn't found. - BufferedReader br = new BufferedReader(r); - for (int i = 0; i < 10; i++) { - LOG.info(br.readLine()); - } - br.close(); + String output = CharStreams.toString(r); + r.close(); + LOG.info("Output: " + output); + assertTrue(output.contains("absolute-result")); } } diff --git a/src/test/resources/absolute.h b/src/test/resources/absolute.h new file mode 100644 index 0000000..82c5a66 --- /dev/null +++ b/src/test/resources/absolute.h @@ -0,0 +1 @@ +absolute-result |