Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
61f3fc1c
Unverified
Commit
61f3fc1c
authored
Jul 18, 2023
by
Shariar Azad Riday
Committed by
GitHub
Jul 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement regex filtering for test suites
parent
f42cf82d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
7 deletions
+39
-7
libcaf_test/caf/test/runner.cpp
libcaf_test/caf/test/runner.cpp
+37
-7
libcaf_test/caf/test/runner.hpp
libcaf_test/caf/test/runner.hpp
+2
-0
No files found.
libcaf_test/caf/test/runner.cpp
View file @
61f3fc1c
...
...
@@ -8,7 +8,6 @@
#include "caf/config_option_adder.hpp"
#include "caf/config_option_set.hpp"
#include "caf/detail/log_level.hpp"
#include "caf/settings.hpp"
#include "caf/test/context.hpp"
#include "caf/test/nesting_error.hpp"
#include "caf/test/reporter.hpp"
...
...
@@ -16,6 +15,7 @@
#include <iostream>
#include <optional>
#include <regex>
#include <string>
namespace
caf
::
test
{
...
...
@@ -53,6 +53,26 @@ std::optional<unsigned> parse_log_level(std::string_view x) {
return
{};
}
std
::
optional
<
std
::
regex
>
to_regex
(
std
::
string_view
regex_string
)
{
#ifdef CAF_ENABLE_EXCEPTIONS
using
detail
::
format_to
;
auto
err_out
=
[]
{
return
std
::
ostream_iterator
<
char
>
{
std
::
cerr
};
};
try
{
return
std
::
regex
{
regex_string
.
begin
(),
regex_string
.
end
()};
}
catch
(
const
std
::
exception
&
err
)
{
format_to
(
err_out
(),
"error while parsing argument '{}': {}
\n
"
,
regex_string
,
err
.
what
());
return
std
::
nullopt
;
}
catch
(...)
{
format_to
(
err_out
(),
"error while parsing argument '{}': unknown error
\n
"
,
regex_string
);
return
std
::
nullopt
;
}
#else
return
std
::
regex
{
regex_string
.
begin
(),
regex_string
.
end
()};
#endif
}
}
// namespace
runner
::
runner
()
:
suites_
(
caf
::
test
::
registry
::
suites
())
{
...
...
@@ -67,8 +87,19 @@ int runner::run(int argc, char** argv) {
}
else
if
(
help_printed
)
{
return
EXIT_SUCCESS
;
}
auto
suite_regex
=
to_regex
(
get_or
(
cfg_
,
"suites"
,
".*"
));
if
(
!
suite_regex
)
{
return
EXIT_FAILURE
;
}
default_reporter
->
start
();
auto
enabled
=
[](
const
std
::
regex
&
selected
,
std
::
string_view
search_string
)
{
return
std
::
regex_search
(
search_string
.
begin
(),
search_string
.
end
(),
selected
);
};
for
(
auto
&
[
suite_name
,
suite
]
:
suites_
)
{
if
(
!
enabled
(
*
suite_regex
,
suite_name
))
continue
;
default_reporter
->
begin_suite
(
suite_name
);
for
(
auto
[
test_name
,
factory_instance
]
:
suite
)
{
auto
state
=
std
::
make_shared
<
context
>
();
...
...
@@ -109,27 +140,26 @@ int runner::run(int argc, char** argv) {
runner
::
parse_cli_result
runner
::
parse_cli
(
int
argc
,
char
**
argv
)
{
using
detail
::
format_to
;
caf
::
settings
cfg
;
std
::
vector
<
std
::
string
>
args_cpy
{
argv
+
1
,
argv
+
argc
};
auto
options
=
make_option_set
();
auto
res
=
options
.
parse
(
cfg
,
args_cpy
);
auto
res
=
options
.
parse
(
cfg
_
,
args_cpy
);
auto
err
=
std
::
ostream_iterator
<
char
>
{
std
::
cerr
};
if
(
res
.
first
!=
caf
::
pec
::
success
)
{
format_to
(
err
,
"error while parsing argument '{}': {}
\n\n
{}
\n
"
,
*
res
.
second
,
to_string
(
res
.
first
),
options
.
help_text
());
return
{
false
,
true
};
}
if
(
get_or
(
cfg
,
"help"
,
false
))
{
if
(
get_or
(
cfg
_
,
"help"
,
false
))
{
format_to
(
err
,
"{}
\n
"
,
options
.
help_text
());
return
{
true
,
true
};
}
if
(
get_or
(
cfg
,
"available-suites"
,
false
))
{
if
(
get_or
(
cfg
_
,
"available-suites"
,
false
))
{
format_to
(
err
,
"available suites:
\n
"
);
for
(
auto
&
[
suite_name
,
suite
]
:
suites_
)
format_to
(
err
,
"- {}
\n
"
,
suite_name
);
return
{
true
,
true
};
}
if
(
auto
suite_name
=
get_as
<
std
::
string
>
(
cfg
,
"available-tests"
))
{
if
(
auto
suite_name
=
get_as
<
std
::
string
>
(
cfg
_
,
"available-tests"
))
{
auto
i
=
suites_
.
find
(
*
suite_name
);
if
(
i
==
suites_
.
end
())
{
format_to
(
err
,
"no such suite: {}
\n
"
,
*
suite_name
);
...
...
@@ -140,7 +170,7 @@ runner::parse_cli_result runner::parse_cli(int argc, char** argv) {
format_to
(
err
,
"- {}
\n
"
,
test_name
);
return
{
true
,
true
};
}
if
(
auto
verbosity
=
get_as
<
std
::
string
>
(
cfg
,
"verbosity"
))
{
if
(
auto
verbosity
=
get_as
<
std
::
string
>
(
cfg
_
,
"verbosity"
))
{
auto
level
=
parse_log_level
(
*
verbosity
);
if
(
!
level
)
{
format_to
(
err
,
...
...
libcaf_test/caf/test/runner.hpp
View file @
61f3fc1c
...
...
@@ -5,6 +5,7 @@
#pragma once
#include "caf/detail/test_export.hpp"
#include "caf/settings.hpp"
#include "caf/test/registry.hpp"
namespace
caf
::
test
{
...
...
@@ -28,6 +29,7 @@ private:
parse_cli_result
parse_cli
(
int
argc
,
char
**
argv
);
registry
::
suites_map
suites_
;
caf
::
settings
cfg_
;
};
}
// namespace caf::test
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment