Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
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
fmt
Commits
cb7caa54
Commit
cb7caa54
authored
Sep 12, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move FMT_STATIC_ASSERT to header and test.
parent
ea9989b2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
28 deletions
+28
-28
posix.cc
posix.cc
+0
-14
posix.h
posix.h
+14
-0
test/compile-test/CMakeLists.txt
test/compile-test/CMakeLists.txt
+3
-0
test/posix-test.cc
test/posix-test.cc
+11
-14
No files found.
posix.cc
View file @
cb7caa54
...
...
@@ -54,20 +54,6 @@
#endif // _WIN32
#if FMT_GCC_VERSION >= 407
# define FMT_UNUSED __attribute__((unused))
#else
# define FMT_UNUSED
#endif
#if FMT_USE_STATIC_ASSERT
# define FMT_STATIC_ASSERT(cond, message) static_assert(cond, message)
#else
# define FMT_CONCAT_(a, b) FMT_CONCAT(a, b)
# define FMT_STATIC_ASSERT(cond, message) \
typedef int FMT_CONCAT_(Assert, __LINE__)[(cond) ? 1 : -1] FMT_UNUSED
#endif
namespace
{
#ifdef _WIN32
// Return type of read and write functions.
...
...
posix.h
View file @
cb7caa54
...
...
@@ -62,6 +62,20 @@
# endif
#endif
#if FMT_GCC_VERSION >= 407
# define FMT_UNUSED __attribute__((unused))
#else
# define FMT_UNUSED
#endif
#if FMT_USE_STATIC_ASSERT
# define FMT_STATIC_ASSERT(cond, message) static_assert(cond, message)
#else
# define FMT_CONCAT_(a, b) FMT_CONCAT(a, b)
# define FMT_STATIC_ASSERT(cond, message) \
typedef int FMT_CONCAT_(Assert, __LINE__)[(cond) ? 1 : -1] FMT_UNUSED
#endif
// Retries the expression while it evaluates to error_result and errno
// equals to EINTR.
#ifndef _WIN32
...
...
test/compile-test/CMakeLists.txt
View file @
cb7caa54
...
...
@@ -8,6 +8,7 @@ set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../..)
function
(
expect_compile_error code
)
check_cxx_source_compiles
(
"
#include
\"
format.cc
\"
#include
\"
posix.h
\"
int main() {
${
code
}
}
...
...
@@ -44,3 +45,5 @@ expect_compile_error("fmt::Writer() << fmt::pad(42, 5, L' ');")
# Formatting a wide character with a narrow format string is forbidden.
expect_compile_error
(
"fmt::format(
\"
{}
\"
, L'a';"
)
expect_compile_error
(
"FMT_STATIC_ASSERT(0 > 1,
\"
oops
\"
);"
)
test/posix-test.cc
View file @
cb7caa54
...
...
@@ -56,14 +56,6 @@ int fileno_count;
std
::
size_t
read_nbyte
;
std
::
size_t
write_nbyte
;
bool
increase_file_size
;
std
::
string
TEST_FILE_CONTENT
=
"top secret, destroy before reading"
;
void
WriteTestFile
()
{
BufferedFile
bf
(
"test"
,
"w"
);
bf
.
print
(
TEST_FILE_CONTENT
);
bf
.
close
();
}
}
#define EMULATE_EINTR(func, error_result) \
...
...
@@ -183,7 +175,13 @@ int test::fileno(FILE *stream) {
void
write_file
(
fmt
::
StringRef
filename
,
fmt
::
StringRef
content
)
{
fmt
::
BufferedFile
f
(
filename
,
"w"
);
fmt
::
print
(
f
.
get
(),
"{}"
,
content
);
f
.
print
(
"{}"
,
content
);
}
TEST
(
UtilTest
,
StaticAssert
)
{
FMT_STATIC_ASSERT
(
true
,
"success"
);
// Static assertion failure is tested in compile-test because it causes
// a compile-time error.
}
TEST
(
FileTest
,
OpenRetry
)
{
...
...
@@ -222,15 +220,16 @@ TEST(FileTest, CloseNoRetry) {
}
TEST
(
FileTest
,
Size
)
{
WriteTestFile
();
std
::
string
content
=
"top secret, destroy before reading"
;
write_file
(
"test"
,
content
);
File
f
(
"test"
,
File
::
RDONLY
);
EXPECT_EQ
(
TEST_FILE_CONTENT
.
size
(),
f
.
size
());
EXPECT_EQ
(
content
.
size
(),
f
.
size
());
f
.
close
();
EXPECT_SYSTEM_ERROR
(
f
.
size
(),
EBADF
,
"cannot get file attributes"
);
}
TEST
(
FileTest
,
MaxSize
)
{
WriteTestFile
(
);
write_file
(
"test"
,
""
);
File
f
(
"test"
,
File
::
RDONLY
);
increase_file_size
=
true
;
EXPECT_GE
(
f
.
size
(),
0
);
...
...
@@ -238,8 +237,6 @@ TEST(FileTest, MaxSize) {
increase_file_size
=
false
;
}
// TODO: test FMT_STATIC_ASSERT
TEST
(
FileTest
,
ReadRetry
)
{
File
read_end
,
write_end
;
File
::
pipe
(
read_end
,
write_end
);
...
...
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