From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17148 invoked by alias); 1 Jun 2016 21:10:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 17096 invoked by uid 89); 1 Jun 2016 21:10:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 spammy=Hx-languages-length:5820, dolor, elit, HX-HELO:eggs.gnu.org X-HELO: eggs.gnu.org Received: from eggs.gnu.org (HELO eggs.gnu.org) (208.118.235.92) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 01 Jun 2016 21:10:51 +0000 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8D9W-0007tn-9F for gcc-patches@gcc.gnu.org; Wed, 01 Jun 2016 16:54:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41439) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8D9W-0007tj-0W for gcc-patches@gcc.gnu.org; Wed, 01 Jun 2016 16:54:10 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A2F162649 for ; Wed, 1 Jun 2016 20:54:09 +0000 (UTC) Received: from c64.redhat.com (vpn-239-103.phx2.redhat.com [10.3.239.103]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u51Ks4WP027176; Wed, 1 Jun 2016 16:54:08 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: Bernd Schmidt , Jeff Law , David Malcolm Subject: [PATCH 06/21] Convert Levenshtein test from a plugin to a selftest Date: Wed, 01 Jun 2016 21:10:00 -0000 Message-Id: <1464816003-35862-7-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1464816003-35862-1-git-send-email-dmalcolm@redhat.com> References: <1447952699-40820-1-git-send-email-dmalcolm@redhat.com> <1464816003-35862-1-git-send-email-dmalcolm@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 X-IsSubscribed: yes X-SW-Source: 2016-06/txt/msg00098.txt.bz2 This is an example of converting one of our existing plugin-based tests to run within -fself-test instead. gcc/ChangeLog: * spellcheck.c: Include "selftest.h". (spellcheck_test): New class (TEST_F (spellcheck_test, levenshtein_distance)): New selftest, based on testsuite/gcc.dg/plugin/levenshtein_plugin.c. gcc/testsuite/ChangeLog: * gcc.dg/plugin/levenshtein-test-1.c: Delete. * gcc.dg/plugin/levenshtein_plugin.c: Delete. * gcc.dg/plugin/plugin.exp (plugin_test_list): Remove the above. --- gcc/spellcheck.c | 48 ++++++++++++++++++ gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c | 9 ---- gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c | 64 ------------------------ gcc/testsuite/gcc.dg/plugin/plugin.exp | 1 - 4 files changed, 48 insertions(+), 74 deletions(-) delete mode 100644 gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c delete mode 100644 gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c diff --git a/gcc/spellcheck.c b/gcc/spellcheck.c index e4e83a5..12ff13b 100644 --- a/gcc/spellcheck.c +++ b/gcc/spellcheck.c @@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see #include "tm.h" #include "tree.h" #include "spellcheck.h" +#include "selftest.h" /* The Levenshtein distance is an "edit-distance": the minimal number of one-character insertions, removals or substitutions @@ -165,3 +166,50 @@ find_closest_string (const char *target, return best_candidate; } + +#if CHECKING_P + +namespace { + +class spellcheck_test : public ::selftest::test +{ + protected: + void + levenshtein_distance_unit_test_oneway (const char *a, const char *b, + edit_distance_t expected) + { + edit_distance_t actual = levenshtein_distance (a, b); + EXPECT_EQ (actual, expected); + } + + void + levenshtein_distance_unit_test (const char *a, const char *b, + edit_distance_t expected) + { + /* Run every test both ways to ensure it's symmetric. */ + levenshtein_distance_unit_test_oneway (a, b, expected); + levenshtein_distance_unit_test_oneway (b, a, expected); + } +}; + +TEST_F (spellcheck_test, levenshtein_distance) +{ + levenshtein_distance_unit_test ("", "nonempty", strlen ("nonempty")); + levenshtein_distance_unit_test ("saturday", "sunday", 3); + levenshtein_distance_unit_test ("foo", "m_foo", 2); + levenshtein_distance_unit_test ("hello_world", "HelloWorld", 3); + levenshtein_distance_unit_test + ("the quick brown fox jumps over the lazy dog", "dog", 40); + levenshtein_distance_unit_test + ("the quick brown fox jumps over the lazy dog", + "the quick brown dog jumps over the lazy fox", + 4); + levenshtein_distance_unit_test + ("Lorem ipsum dolor sit amet, consectetur adipiscing elit,", + "All your base are belong to us", + 44); +} + +} /* anon namespace. */ + +#endif /* #if CHECKING_P */ diff --git a/gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c b/gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c deleted file mode 100644 index ac49992..0000000 --- a/gcc/testsuite/gcc.dg/plugin/levenshtein-test-1.c +++ /dev/null @@ -1,9 +0,0 @@ -/* Placeholder C source file for unit-testing gcc/spellcheck.c. */ -/* { dg-do compile } */ -/* { dg-options "-O" } */ - -int -main (int argc, char **argv) -{ - return 0; -} diff --git a/gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c b/gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c deleted file mode 100644 index 3e7dc78..0000000 --- a/gcc/testsuite/gcc.dg/plugin/levenshtein_plugin.c +++ /dev/null @@ -1,64 +0,0 @@ -/* Plugin for unittesting gcc/spellcheck.h. */ - -#include "config.h" -#include "gcc-plugin.h" -#include "system.h" -#include "coretypes.h" -#include "spellcheck.h" -#include "diagnostic.h" - -int plugin_is_GPL_compatible; - -static void -levenshtein_distance_unit_test_oneway (const char *a, const char *b, - edit_distance_t expected) -{ - edit_distance_t actual = levenshtein_distance (a, b); - if (actual != expected) - error ("levenshtein_distance (\"%s\", \"%s\") : expected: %i got %i", - a, b, expected, actual); -} - - -static void -levenshtein_distance_unit_test (const char *a, const char *b, - edit_distance_t expected) -{ - /* Run every test both ways to ensure it's symmetric. */ - levenshtein_distance_unit_test_oneway (a, b, expected); - levenshtein_distance_unit_test_oneway (b, a, expected); -} - -/* Callback handler for the PLUGIN_FINISH event; run - levenshtein_distance unit tests here. */ - -static void -on_finish (void */*gcc_data*/, void */*user_data*/) -{ - levenshtein_distance_unit_test ("", "nonempty", strlen ("nonempty")); - levenshtein_distance_unit_test ("saturday", "sunday", 3); - levenshtein_distance_unit_test ("foo", "m_foo", 2); - levenshtein_distance_unit_test ("hello_world", "HelloWorld", 3); - levenshtein_distance_unit_test - ("the quick brown fox jumps over the lazy dog", "dog", 40); - levenshtein_distance_unit_test - ("the quick brown fox jumps over the lazy dog", - "the quick brown dog jumps over the lazy fox", - 4); - levenshtein_distance_unit_test - ("Lorem ipsum dolor sit amet, consectetur adipiscing elit,", - "All your base are belong to us", - 44); -} - -int -plugin_init (struct plugin_name_args *plugin_info, - struct plugin_gcc_version */*version*/) -{ - register_callback (plugin_info->base_name, - PLUGIN_FINISH, - on_finish, - NULL); /* void *user_data */ - - return 0; -} diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index fd1e98e..dfcdea2 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -70,7 +70,6 @@ set plugin_test_list [list \ diagnostic-test-expressions-1.c } \ { diagnostic_plugin_show_trees.c \ diagnostic-test-show-trees-1.c } \ - { levenshtein_plugin.c levenshtein-test-1.c } \ { location_overflow_plugin.c \ location-overflow-test-1.c \ location-overflow-test-2.c } \ -- 1.8.5.3