This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] selftest.c: avoid explicit "selftest::" qualifiers


On Mon, 2016-08-29 at 23:53 +0200, Bernd Schmidt wrote:
> On 08/25/2016 03:13 AM, David Malcolm wrote:
> > Split out a new base class for temp_source_file, named_temp_file,
> > moving the deletion to the base class dtor, so that we can write
> > out temporary files in other ways in selftests.
> > 
> > gcc/ChangeLog:
> > 	* selftest.c (selftest::named_temp_file::named_temp_file): New
> > 	ctor.
> > 	(selftest::temp_source_file::~temp_source_file): Move to...
> > 	(selftest::named_temp_file::~named_temp_file): ...here.
> > 	(selftest::test_named_temp_file): New function.
> > 	(selftest::selftest_c_tests): Call test_named_temp_file.
> > 	* selftest.h (class named_temp_file): New class.
> > 	(class temp_source_file): Convert to a subclass of
> > named_temp_file.
> 
> Ok.
> 
> > +selftest::named_temp_file::named_temp_file (const char *suffix)
> 
> Any reason these aren't inside namespace selftest to shorten these
> declarations?

I was being consistent with the rest of the file,  but I no longer
remember why I used explicit namespace selftest:: prefixes there.

The following follow-up patch removes them, moving the
"namespace selftest {" to the top of the file so it covers
everything.

Successfully bootstrapped&regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/ChangeLog:
	* selftest.c: Move "namespace selftest {" to top of file,
	removing explicit "selftest::" qualifiers throughout.
---
 gcc/selftest.c | 78 +++++++++++++++++++++++++++-------------------------------
 1 file changed, 36 insertions(+), 42 deletions(-)

diff --git a/gcc/selftest.c b/gcc/selftest.c
index e6c9510..69d9931 100644
--- a/gcc/selftest.c
+++ b/gcc/selftest.c
@@ -24,12 +24,14 @@ along with GCC; see the file COPYING3.  If not see
 
 #if CHECKING_P
 
-int selftest::num_passes;
+namespace selftest {
+
+int num_passes;
 
 /* Record the successful outcome of some aspect of a test.  */
 
 void
-selftest::pass (const location &/*loc*/, const char */*msg*/)
+pass (const location &/*loc*/, const char */*msg*/)
 {
   num_passes++;
 }
@@ -37,7 +39,7 @@ selftest::pass (const location &/*loc*/, const char */*msg*/)
 /* Report the failed outcome of some aspect of a test and abort.  */
 
 void
-selftest::fail (const location &loc, const char *msg)
+fail (const location &loc, const char *msg)
 {
   fprintf (stderr,"%s:%i: %s: FAIL: %s\n", loc.m_file, loc.m_line,
 	   loc.m_function, msg);
@@ -47,7 +49,7 @@ selftest::fail (const location &loc, const char *msg)
 /* As "fail", but using printf-style formatted output.  */
 
 void
-selftest::fail_formatted (const location &loc, const char *fmt, ...)
+fail_formatted (const location &loc, const char *fmt, ...)
 {
   va_list ap;
 
@@ -65,26 +67,23 @@ selftest::fail_formatted (const location &loc, const char *fmt, ...)
    to be non-NULL; fail gracefully if either are NULL.  */
 
 void
-selftest::assert_streq (const location &loc,
-			const char *desc_expected, const char *desc_actual,
-			const char *val_expected, const char *val_actual)
+assert_streq (const location &loc,
+	      const char *desc_expected, const char *desc_actual,
+	      const char *val_expected, const char *val_actual)
 {
   /* If val_expected is NULL, the test is buggy.  Fail gracefully.  */
   if (val_expected == NULL)
-    ::selftest::fail_formatted
-	(loc, "ASSERT_STREQ (%s, %s) expected=NULL",
-	 desc_expected, desc_actual);
+    fail_formatted (loc, "ASSERT_STREQ (%s, %s) expected=NULL",
+		    desc_expected, desc_actual);
   /* If val_actual is NULL, fail with a custom error message.  */
   if (val_actual == NULL)
-    ::selftest::fail_formatted
-	(loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=NULL",
-	 desc_expected, desc_actual, val_expected);
+    fail_formatted (loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=NULL",
+		    desc_expected, desc_actual, val_expected);
   if (0 == strcmp (val_expected, val_actual))
-    ::selftest::pass (loc, "ASSERT_STREQ");
+    pass (loc, "ASSERT_STREQ");
   else
-    ::selftest::fail_formatted
-	(loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=\"%s\"",
-	 desc_expected, desc_actual, val_expected, val_actual);
+    fail_formatted (loc, "ASSERT_STREQ (%s, %s) expected=\"%s\" actual=\"%s\"",
+		    desc_expected, desc_actual, val_expected, val_actual);
 }
 
 /* Implementation detail of ASSERT_STR_CONTAINS.
@@ -93,36 +92,35 @@ selftest::assert_streq (const location &loc,
    ::selftest::fail if it is not found.  */
 
 void
-selftest::assert_str_contains (const location &loc,
-			       const char *desc_haystack,
-			       const char *desc_needle,
-			       const char *val_haystack,
-			       const char *val_needle)
+assert_str_contains (const location &loc,
+		     const char *desc_haystack,
+		     const char *desc_needle,
+		     const char *val_haystack,
+		     const char *val_needle)
 {
   /* If val_haystack is NULL, fail with a custom error message.  */
   if (val_haystack == NULL)
-    ::selftest::fail_formatted
-	(loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=NULL",
-	 desc_haystack, desc_needle);
+    fail_formatted (loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=NULL",
+		    desc_haystack, desc_needle);
 
   /* If val_needle is NULL, fail with a custom error message.  */
   if (val_needle == NULL)
-    ::selftest::fail_formatted
-	(loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=\"%s\" needle=NULL",
-	 desc_haystack, desc_needle, val_haystack);
+    fail_formatted (loc,
+		    "ASSERT_STR_CONTAINS (%s, %s) haystack=\"%s\" needle=NULL",
+		    desc_haystack, desc_needle, val_haystack);
 
   const char *test = strstr (val_haystack, val_needle);
   if (test)
-    ::selftest::pass (loc, "ASSERT_STR_CONTAINS");
+    pass (loc, "ASSERT_STR_CONTAINS");
   else
-    ::selftest::fail_formatted
+    fail_formatted
 	(loc, "ASSERT_STR_CONTAINS (%s, %s) haystack=\"%s\" needle=\"%s\"",
 	 desc_haystack, desc_needle, val_haystack, val_needle);
 }
 
 /* Constructor.  Generate a name for the file.  */
 
-selftest::named_temp_file::named_temp_file (const char *suffix)
+named_temp_file::named_temp_file (const char *suffix)
 {
   m_filename = make_temp_file (suffix);
   ASSERT_NE (m_filename, NULL);
@@ -130,7 +128,7 @@ selftest::named_temp_file::named_temp_file (const char *suffix)
 
 /* Destructor.  Delete the tempfile.  */
 
-selftest::named_temp_file::~named_temp_file ()
+named_temp_file::~named_temp_file ()
 {
   unlink (m_filename);
   diagnostics_file_cache_forcibly_evict_file (m_filename);
@@ -141,23 +139,20 @@ selftest::named_temp_file::~named_temp_file ()
    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)
+temp_source_file::temp_source_file (const location &loc,
+				    const char *suffix,
+				    const char *content)
 : named_temp_file (suffix)
 {
   FILE *out = fopen (get_filename (), "w");
   if (!out)
-    ::selftest::fail_formatted (loc, "unable to open tempfile: %s",
-				get_filename ());
+    fail_formatted (loc, "unable to open tempfile: %s", get_filename ());
   fprintf (out, "%s", content);
   fclose (out);
 }
 
 /* Selftests for the selftest system itself.  */
 
-namespace selftest {
-
 /* Sanity-check the ASSERT_ macros with various passing cases.  */
 
 static void
@@ -181,9 +176,8 @@ test_named_temp_file ()
   named_temp_file t (".txt");
   FILE *f = fopen (t.get_filename (), "w");
   if (!f)
-    selftest::fail_formatted (SELFTEST_LOCATION,
-			      "unable to open %s for writing",
-			      t.get_filename ());
+    fail_formatted (SELFTEST_LOCATION,
+		    "unable to open %s for writing", t.get_filename ());
   fclose (f);
 }
 
-- 
1.8.5.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]