Commit 85ecd05c by David Malcolm Committed by David Malcolm

PR bootstrap/71481: fix input.c selftest

gcc/ChangeLog:
	PR bootstrap/71481
	* input.c (selftest::test_reading_source_line): Avoid reading from
	__FILE__ by creating a tempfile with known content and reading
	from that instead.

From-SVN: r237414
parent 2fe00b1f
2016-06-13 David Malcolm <dmalcolm@redhat.com> 2016-06-13 David Malcolm <dmalcolm@redhat.com>
PR bootstrap/71481
* input.c (selftest::test_reading_source_line): Avoid reading from
__FILE__ by creating a tempfile with known content and reading
from that instead.
2016-06-13 David Malcolm <dmalcolm@redhat.com>
* pretty-print.c (assert_pp_format_colored): Skip the test if * pretty-print.c (assert_pp_format_colored): Skip the test if
GCC_COLORS is set. GCC_COLORS is set.
(test_pp_format): Remove comment about GCC_COLORS. (test_pp_format): Remove comment about GCC_COLORS.
......
...@@ -1219,23 +1219,34 @@ test_builtins () ...@@ -1219,23 +1219,34 @@ test_builtins ()
static void static void
test_reading_source_line () test_reading_source_line ()
{ {
/* We will read *this* source file, using __FILE__. /* Create a tempfile and write some text to it. */
Here is some specific text to read and test for: char *filename = make_temp_file (".txt");
The quick brown fox jumps over the lazy dog. */ ASSERT_NE (filename, NULL);
const int linenum_after_test_message = __LINE__; FILE *out = fopen (filename, "w");
const int linenum = linenum_after_test_message - 1; if (!out)
::selftest::fail_formatted (SELFTEST_LOCATION,
"unable to open tempfile: %s", filename);
fprintf (out,
"01234567890123456789\n"
"This is the test text\n"
"This is the 3rd line\n");
fclose (out);
/* Read back a specific line from the tempfile. */
int line_size; int line_size;
const char *source_line = location_get_source_line (__FILE__, linenum, &line_size); const char *source_line = location_get_source_line (filename, 2, &line_size);
ASSERT_TRUE (source_line != NULL); ASSERT_TRUE (source_line != NULL);
ASSERT_EQ (53, line_size); ASSERT_EQ (21, line_size);
if (!strncmp (" The quick brown fox jumps over the lazy dog. */", if (!strncmp ("This is the test text",
source_line, line_size)) source_line, line_size))
::selftest::pass (SELFTEST_LOCATION, ::selftest::pass (SELFTEST_LOCATION,
"source_line matched expected value"); "source_line matched expected value");
else else
::selftest::fail (SELFTEST_LOCATION, ::selftest::fail (SELFTEST_LOCATION,
"source_line did not match expected value"); "source_line did not match expected value");
unlink (filename);
free (filename);
} }
/* Run all of the selftests within this file. */ /* Run all of the selftests within this file. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment