mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-14 10:13:05 +02:00
Start work on C handle io object and use it to output help.
This commit is contained in:
parent
9001b9b957
commit
c1ab7b3c98
@ -26,6 +26,10 @@
|
||||
<release-item>
|
||||
<p>Replace <code>THROW_ON_SYS_ERROR()</code> with <code>THROW_SYS_ERROR()</code>. The former macro was hiding missing branch coverage for critical error handling.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Start work on C handle io object and use it to output help.</p>
|
||||
</release-item>
|
||||
</release-development-list>
|
||||
</release-core-list>
|
||||
|
||||
|
@ -58,6 +58,7 @@ SRCS = \
|
||||
command/command.c \
|
||||
common/error.c \
|
||||
common/exit.c \
|
||||
common/io/handle.c \
|
||||
common/ini.c \
|
||||
common/log.c \
|
||||
common/memContext.c \
|
||||
|
@ -4,6 +4,7 @@ Help Command
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common/io/handle.h"
|
||||
#include "common/memContext.h"
|
||||
#include "common/type.h"
|
||||
#include "config/config.h"
|
||||
@ -337,10 +338,7 @@ cmdHelp()
|
||||
{
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
String *help = helpRender();
|
||||
|
||||
if (write(STDOUT_FILENO, strPtr(help), strSize(help)) != (int)strSize(help)) // {uncovered - write does not fail}
|
||||
THROW_SYS_ERROR(FileWriteError, "unable to write help to stdout"); // {uncovered+}
|
||||
ioHandleWriteOneStr(STDOUT_FILENO, helpRender());
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
}
|
||||
|
17
src/common/io/handle.c
Normal file
17
src/common/io/handle.c
Normal file
@ -0,0 +1,17 @@
|
||||
/***********************************************************************************************************************************
|
||||
Handle IO
|
||||
***********************************************************************************************************************************/
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common/error.h"
|
||||
#include "common/io/handle.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Write a string to the specified handle
|
||||
***********************************************************************************************************************************/
|
||||
void
|
||||
ioHandleWriteOneStr(int handle, const String *string)
|
||||
{
|
||||
if (write(handle, strPtr(string), strSize(string)) != (int)strSize(string))
|
||||
THROW_SYS_ERROR(FileWriteError, "unable to write to %u byte(s) to handle", strSize(string));
|
||||
}
|
14
src/common/io/handle.h
Normal file
14
src/common/io/handle.h
Normal file
@ -0,0 +1,14 @@
|
||||
/***********************************************************************************************************************************
|
||||
Handle IO
|
||||
***********************************************************************************************************************************/
|
||||
#ifndef COMMON_IO_HANDLE_H
|
||||
#define COMMON_IO_HANDLE_H
|
||||
|
||||
#include "common/type.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
void ioHandleWriteOneStr(int handle, const String *string);
|
||||
|
||||
#endif
|
@ -176,6 +176,16 @@ my $oTestDef =
|
||||
'common/debug' => TESTDEF_COVERAGE_NOCODE,
|
||||
},
|
||||
},
|
||||
{
|
||||
&TESTDEF_NAME => 'io-handle',
|
||||
&TESTDEF_TOTAL => 1,
|
||||
&TESTDEF_C => true,
|
||||
|
||||
&TESTDEF_COVERAGE =>
|
||||
{
|
||||
'common/io/handle' => TESTDEF_COVERAGE_FULL,
|
||||
},
|
||||
},
|
||||
{
|
||||
&TESTDEF_NAME => 'exit',
|
||||
&TESTDEF_TOTAL => 1,
|
||||
@ -320,7 +330,7 @@ my $oTestDef =
|
||||
},
|
||||
},
|
||||
{
|
||||
&TESTDEF_NAME => 'io-handle',
|
||||
&TESTDEF_NAME => 'io-handle-perl',
|
||||
&TESTDEF_TOTAL => 6,
|
||||
|
||||
&TESTDEF_COVERAGE =>
|
||||
|
@ -1,7 +1,7 @@
|
||||
####################################################################################################################################
|
||||
# CommonIoHandleTest.pm - tests for Common::Io::Handle module
|
||||
# Tests for Common::Io::Handle module
|
||||
####################################################################################################################################
|
||||
package pgBackRestTest::Module::Common::CommonIoHandleTest;
|
||||
package pgBackRestTest::Module::Common::CommonIoHandlePerlTest;
|
||||
use parent 'pgBackRestTest::Common::RunTest';
|
||||
|
||||
####################################################################################################################################
|
25
test/src/module/common/ioHandleTest.c
Normal file
25
test/src/module/common/ioHandleTest.c
Normal file
@ -0,0 +1,25 @@
|
||||
/***********************************************************************************************************************************
|
||||
Test Handle IO
|
||||
***********************************************************************************************************************************/
|
||||
#include <fcntl.h>
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Test Run
|
||||
***********************************************************************************************************************************/
|
||||
void
|
||||
testRun()
|
||||
{
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("ioHandleWriteOneStr()"))
|
||||
{
|
||||
TEST_ERROR(
|
||||
ioHandleWriteOneStr(999999, strNew("test")), FileWriteError,
|
||||
"unable to write to 4 byte(s) to handle: [9] Bad file descriptor");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
String *fileName = strNewFmt("%s/test.txt", testPath());
|
||||
int fileHandle = open(strPtr(fileName), O_CREAT | O_TRUNC | O_WRONLY, 0700);
|
||||
|
||||
TEST_RESULT_VOID(ioHandleWriteOneStr(fileHandle, strNew("test1\ntest2")), "write string to file");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user