Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
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
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
Libraries
spdlog
Commits
3620b31e
Commit
3620b31e
authored
Feb 23, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added pattern formatter tests
parent
7709fc70
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
5 deletions
+80
-5
tests/test_misc.cpp
tests/test_misc.cpp
+3
-1
tests/test_pattern_formatter.cpp
tests/test_pattern_formatter.cpp
+68
-0
tests/tests.vcxproj
tests/tests.vcxproj
+3
-1
tests/tests.vcxproj.filters
tests/tests.vcxproj.filters
+6
-3
No files found.
tests/
format
.cpp
→
tests/
test_misc
.cpp
View file @
3620b31e
...
...
@@ -39,7 +39,6 @@ TEST_CASE("basic_logging ", "[basic_logging]")
//REQUIRE(log_info(some_logged_class("some_val")) == "some_val");
}
TEST_CASE
(
"log_levels"
,
"[log_levels]"
)
{
REQUIRE
(
log_info
(
"Hello"
,
spdlog
::
level
::
err
)
==
""
);
...
...
@@ -54,3 +53,6 @@ TEST_CASE("log_levels", "[log_levels]")
tests/test_pattern_formatter.cpp
0 → 100644
View file @
3620b31e
#include "includes.h"
// log to str and return it
static
std
::
string
log_to_str
(
const
std
::
string
&
msg
,
std
::
shared_ptr
<
spdlog
::
formatter
>
formatter
=
nullptr
)
{
std
::
ostringstream
oss
;
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
spdlog
::
logger
oss_logger
(
"pattern_tester"
,
oss_sink
);
oss_logger
.
set_level
(
spdlog
::
level
::
info
);
if
(
formatter
)
oss_logger
.
set_formatter
(
formatter
);
oss_logger
.
info
(
msg
);
return
oss
.
str
();
}
TEST_CASE
(
"custom eol"
,
"[pattern_formatter]"
)
{
std
::
string
msg
=
"Hello custom eol test"
;
std
::
string
eol
=
";)"
;
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"%v"
,
spdlog
::
pattern_time_type
::
local
,
";)"
);
REQUIRE
(
log_to_str
(
msg
,
formatter
)
==
msg
+
eol
);
}
TEST_CASE
(
"empty format"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
""
,
spdlog
::
pattern_time_type
::
local
,
""
);
REQUIRE
(
log_to_str
(
"Some message"
,
formatter
)
==
""
);
}
TEST_CASE
(
"empty format2"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
""
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
REQUIRE
(
log_to_str
(
"Some message"
,
formatter
)
==
"
\n
"
);
}
TEST_CASE
(
"level"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"[%l] %v"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
REQUIRE
(
log_to_str
(
"Some message"
,
formatter
)
==
"[info] Some message
\n
"
);
}
TEST_CASE
(
"short level"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"[%L] %v"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
REQUIRE
(
log_to_str
(
"Some message"
,
formatter
)
==
"[I] Some message
\n
"
);
}
TEST_CASE
(
"name"
,
"[pattern_formatter]"
)
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"[%n] %v"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
REQUIRE
(
log_to_str
(
"Some message"
,
formatter
)
==
"[pattern_tester] Some message
\n
"
);
}
TEST_CASE
(
"date MM/DD/YY "
,
"[pattern_formatter]"
)
{
using
namespace
::
std
::
chrono
;
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"%D %v"
,
spdlog
::
pattern_time_type
::
local
,
"
\n
"
);
auto
now_tm
=
spdlog
::
details
::
os
::
localtime
();
std
::
stringstream
oss
;
oss
<<
std
::
put_time
(
&
now_tm
,
"%D"
)
<<
" Some message
\n
"
;
REQUIRE
(
log_to_str
(
"Some message"
,
formatter
)
==
oss
.
str
());
}
tests/tests.vcxproj
View file @
3620b31e
...
...
@@ -21,6 +21,7 @@
<PropertyGroup
Label=
"Globals"
>
<ProjectGuid>
{59A07559-5F38-4DD6-A7FA-DB4153690B42}
</ProjectGuid>
<RootNamespace>
tests
</RootNamespace>
<WindowsTargetPlatformVersion>
10.0.16299.0
</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.Default.props"
/>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
Label=
"Configuration"
>
...
...
@@ -128,10 +129,11 @@
<ClCompile
Include=
"errors.cpp"
/>
<ClCompile
Include=
"file_helper.cpp"
/>
<ClCompile
Include=
"file_log.cpp"
/>
<ClCompile
Include=
"
format
.cpp"
/>
<ClCompile
Include=
"
test_misc
.cpp"
/>
<ClCompile
Include=
"main.cpp"
/>
<ClCompile
Include=
"registry.cpp"
/>
<ClCompile
Include=
"test_macros.cpp"
/>
<ClCompile
Include=
"test_pattern_formatter.cpp"
/>
<ClCompile
Include=
"utils.cpp"
/>
</ItemGroup>
<ItemGroup>
...
...
tests/tests.vcxproj.filters
View file @
3620b31e
...
...
@@ -18,9 +18,6 @@
<ClCompile
Include=
"file_log.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"format.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"main.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
...
...
@@ -39,6 +36,12 @@
<ClCompile
Include=
"test_macros.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"test_pattern_formatter.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"test_misc.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"includes.h"
>
...
...
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