aboutsummaryrefslogtreecommitdiff
path: root/gcc/selftest.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2016-08-16 18:02:43 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2016-08-16 18:02:43 +0000
commiteb3a5bcc74b063c05ceb78f8e0bfee3e03b021a6 (patch)
treeb7b9c8817db01180af43f706c9d64db290fb525c /gcc/selftest.c
parent7841800f7a5fec82615b74f8ed9beb48f0e152ef (diff)
downloadgcc-eb3a5bcc74b063c05ceb78f8e0bfee3e03b021a6.zip
gcc-eb3a5bcc74b063c05ceb78f8e0bfee3e03b021a6.tar.gz
gcc-eb3a5bcc74b063c05ceb78f8e0bfee3e03b021a6.tar.bz2
Move class temp_source_file from input.c to selftest.c/h
gcc/ChangeLog: * input.c (class selftest::temp_source_file): Move to selftest.h. (selftest::temp_source_file::temp_source_file): Move to selftest.c. (selftest::temp_source_file::~temp_source_file): Likewise. * selftest.c (selftest::temp_source_file::temp_source_file): Move here from input.c. (selftest::temp_source_file::~temp_source_file): Likewise. * selftest.h (class selftest::temp_source_file): Move here from input.c From-SVN: r239509
Diffstat (limited to 'gcc/selftest.c')
-rw-r--r--gcc/selftest.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/gcc/selftest.c b/gcc/selftest.c
index 2951c3c..0a7192e 100644
--- a/gcc/selftest.c
+++ b/gcc/selftest.c
@@ -87,6 +87,32 @@ selftest::assert_streq (const location &loc,
desc_expected, desc_actual, val_expected, val_actual);
}
+/* Constructor. Create a tempfile using SUFFIX, and write CONTENT to
+ it. Abort if anything goes wrong, using LOC as the effective
+ location in the problem report. */
+
+selftest::temp_source_file::temp_source_file (const location &loc,
+ const char *suffix,
+ const char *content)
+{
+ m_filename = make_temp_file (suffix);
+ ASSERT_NE (m_filename, NULL);
+
+ FILE *out = fopen (m_filename, "w");
+ if (!out)
+ ::selftest::fail_formatted (loc, "unable to open tempfile: %s",
+ m_filename);
+ fprintf (out, "%s", content);
+ fclose (out);
+}
+
+/* Destructor. Delete the tempfile. */
+
+selftest::temp_source_file::~temp_source_file ()
+{
+ unlink (m_filename);
+ free (m_filename);
+}
/* Selftests for the selftest system itself. */