diff --git a/src/testsuite/testsuite-script.c b/src/testsuite/testsuite-script.c index 7548f81283857ceb31c9a7ff8ca16c45bfe20c28..102909cbb58f04b46ee2e8ce9ab0f06011398077 100644 --- a/src/testsuite/testsuite-script.c +++ b/src/testsuite/testsuite-script.c @@ -31,6 +31,34 @@ void testsuite_script_deinit(void) { } +static const char *path_get_filename(const char *path) +{ + const char *filename; + + filename = strrchr(path, '/'); + if (filename == NULL) + filename = path; + else + filename++; + return filename; +} + +const char *testsuite_script_get_name(const char *path) +{ + const char *file, *ext; + + file = path_get_filename(path); + + /* Extract the script name */ + ext = strrchr(file, '.'); + if (ext == NULL || ext == file || + (strcmp(ext, ".svtest") != 0 && + strcmp(ext, "."SIEVE_SCRIPT_FILEEXT) != 0)) + return NULL; + + return t_strdup_until(file, ext); +} + static struct sieve_binary * _testsuite_script_compile(const struct sieve_runtime_env *renv, const char *script) diff --git a/src/testsuite/testsuite-script.h b/src/testsuite/testsuite-script.h index 547fdfc74baa32593456c3f117a9af0680255d42..1bbab0aecb598559a2f6aed519ffdc847e201085 100644 --- a/src/testsuite/testsuite-script.h +++ b/src/testsuite/testsuite-script.h @@ -6,6 +6,8 @@ void testsuite_script_init(void); void testsuite_script_deinit(void); +const char *testsuite_script_get_name(const char *path); + bool testsuite_script_is_subtest(const struct sieve_runtime_env *renv); bool testsuite_script_compile(const struct sieve_runtime_env *renv,