diff options
author | Shevek <[email protected]> | 2015-01-01 13:42:25 -0800 |
---|---|---|
committer | Shevek <[email protected]> | 2015-01-01 13:43:26 -0800 |
commit | a6cf018b30b197ed84f0a0d9ca81fbb9320782c2 (patch) | |
tree | 51bd6a4cd0eca1f7306ae6650632acb4b7e2218b /src | |
parent | e46675ff16bda1f62059fcec83c8f09509fa8c4d (diff) |
Write IncludeAbsoluteTest properly.vanilla
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 |