aboutsummaryrefslogtreecommitdiff
path: root/gcc/selftest.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2018-06-28 09:11:16 +0200
committerMartin Liska <marxin@gcc.gnu.org>2018-06-28 07:11:16 +0000
commitd86c7648fb9643640d8c82be19d49927aa488768 (patch)
treeb45fc0d4134e27d198b87360705d0182c44f8f25 /gcc/selftest.c
parent98086b2ba2bd021e887788cea410410e61eaee42 (diff)
downloadgcc-d86c7648fb9643640d8c82be19d49927aa488768.zip
gcc-d86c7648fb9643640d8c82be19d49927aa488768.tar.gz
gcc-d86c7648fb9643640d8c82be19d49927aa488768.tar.bz2
Come up with new --completion option.
2018-06-28 Martin Liska <mliska@suse.cz> * common.opt: Introduce -completion option. * gcc.c (driver_handle_option): Handle it. (driver::main): Print completions if completion is set. * opt-suggestions.c (option_proposer::get_completions): New function. (option_proposer::suggest_completion): Likewise. (option_proposer::find_param_completions): Likewise. (verify_autocompletions): Likewise. (test_completion_valid_options): Likewise. (test_completion_valid_params): Likewise. (in_completion_p): Likewise. (empty_completion_p): Likewise. (test_completion_partial_match): Likewise. (test_completion_garbage): Likewise. (opt_proposer_c_tests): Likewise. * opt-suggestions.h: Declare new functions. * opts.c (common_handle_option): Handle OPT__completion_. * selftest-run-tests.c (selftest::run_tests): Add opt_proposer_c_tests. * selftest.c (assert_str_startswith): New. * selftest.h (assert_str_startswith): Likewise. (opt_proposer_c_tests): New. (ASSERT_STR_STARTSWITH): Likewise. From-SVN: r262210
Diffstat (limited to 'gcc/selftest.c')
-rw-r--r--gcc/selftest.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/selftest.c b/gcc/selftest.c
index 74adc63..27de9a4 100644
--- a/gcc/selftest.c
+++ b/gcc/selftest.c
@@ -125,6 +125,40 @@ assert_str_contains (const location &loc,
desc_haystack, desc_needle, val_haystack, val_needle);
}
+/* Implementation detail of ASSERT_STR_STARTSWITH.
+ Determine if VAL_STR starts with VAL_PREFIX.
+ ::selftest::pass if VAL_STR does start with VAL_PREFIX.
+ ::selftest::fail if it does not, or either is NULL (using
+ DESC_STR and DESC_PREFIX in the error message). */
+
+void
+assert_str_startswith (const location &loc,
+ const char *desc_str,
+ const char *desc_prefix,
+ const char *val_str,
+ const char *val_prefix)
+{
+ /* If val_str is NULL, fail with a custom error message. */
+ if (val_str == NULL)
+ fail_formatted (loc, "ASSERT_STR_STARTSWITH (%s, %s) str=NULL",
+ desc_str, desc_prefix);
+
+ /* If val_prefix is NULL, fail with a custom error message. */
+ if (val_prefix == NULL)
+ fail_formatted (loc,
+ "ASSERT_STR_STARTSWITH (%s, %s) str=\"%s\" prefix=NULL",
+ desc_str, desc_prefix, val_str);
+
+ const char *test = strstr (val_str, val_prefix);
+ if (test == val_str)
+ pass (loc, "ASSERT_STR_STARTSWITH");
+ else
+ fail_formatted
+ (loc, "ASSERT_STR_STARTSWITH (%s, %s) str=\"%s\" prefix=\"%s\"",
+ desc_str, desc_prefix, val_str, val_prefix);
+}
+
+
/* Constructor. Generate a name for the file. */
named_temp_file::named_temp_file (const char *suffix)