mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-04 09:43:08 +02:00
Use uncrustify for code formatting.
The code is not completely reflowed yet so there are some cases that uncrustify will not catch. The formatting will be improved over time. Some block of code require special formatting so have been surrounded with the {uncrustify-off}/{uncrustify-on} markers. These exceptions should be kept to a minimum. Add --code-format (to reformat code) and --code-format-check (to check formatting) to test.pl. Add a CI test that will check code formatting. Code must be correctly formatted before it can be merge to integration. Add documentation to the coding standards for code formatting.
This commit is contained in:
parent
d4070c9064
commit
ce0ea2cfab
5
.git-blame-ignore-revs
Normal file
5
.git-blame-ignore-revs
Normal file
@ -0,0 +1,5 @@
|
||||
# Reformat code with uncrustify.
|
||||
d4070c90641a61fa3cb1169f3bd53067193bab4e
|
||||
|
||||
# Fix formatting errors.
|
||||
b2202c36d9e7c4557ac37087757df80193d516b5
|
14
.github/workflows/test.yml
vendored
14
.github/workflows/test.yml
vendored
@ -127,6 +127,20 @@ jobs:
|
||||
run: |
|
||||
diff ${GITHUB_WORKSPACE?}/pgbackrest/.github/workflows/symbol.out <(nm -gj --defined-only build/src/pgbackrest)
|
||||
|
||||
# Check that code is correctly formatted
|
||||
code-format:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
path: pgbackrest
|
||||
|
||||
- name: Check
|
||||
run: |
|
||||
cd ${HOME?} && ${GITHUB_WORKSPACE?}/pgbackrest/test/ci.pl test --vm=none --param=code-format-check
|
||||
|
||||
codeql:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
|
@ -1,5 +1,13 @@
|
||||
# pgBackRest <br/> Coding Standards
|
||||
|
||||
## Formatting with uncrustify
|
||||
|
||||
pgBackRest uses uncrustify to check/update the code formatting. If the `code-format` test fails in CI then reformat the code:
|
||||
```
|
||||
pgbackrest/test/test.pl --code-format
|
||||
```
|
||||
Also review the standards in the following sections below. Some standards require further explanation and others are not enforced by uncrustify.
|
||||
|
||||
## Standards
|
||||
|
||||
### Indentation
|
||||
|
@ -3,6 +3,20 @@
|
||||
<doc title="{[project]}" subtitle="Coding Standards" toc="y">
|
||||
<description>{[project]} Coding Standard.</description>
|
||||
|
||||
<!-- ======================================================================================================================= -->
|
||||
<section id="uncrustify">
|
||||
<title>Formatting with <proper>uncrustify</proper></title>
|
||||
|
||||
<p><backrest/> uses <proper>uncrustify</proper> to check/update the code formatting. If the <id>code-format</id> test fails in CI then reformat the code:</p>
|
||||
|
||||
<code-block>
|
||||
pgbackrest/test/test.pl --code-format
|
||||
</code-block>
|
||||
|
||||
<p>Also review the standards in the following sections below. Some standards require further explanation and others are not enforced by <proper>uncrustify</proper>.</p>
|
||||
|
||||
</section>
|
||||
|
||||
<!-- ======================================================================================================================= -->
|
||||
<section id="standards">
|
||||
<title>Standards</title>
|
||||
|
@ -12,6 +12,7 @@ Build Common
|
||||
/***********************************************************************************************************************************
|
||||
Block comments
|
||||
***********************************************************************************************************************************/
|
||||
// {uncrustify_off - comment inside string}
|
||||
#define COMMENT_BLOCK_BEGIN \
|
||||
"/***************************************************************************************************************************" \
|
||||
"********"
|
||||
@ -23,6 +24,7 @@ Block comments
|
||||
#define COMMENT_SEPARATOR \
|
||||
" // ---------------------------------------------------------------------------------------------------------------------" \
|
||||
"--------"
|
||||
// {uncrustify_on}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
|
@ -360,6 +360,7 @@ encodeToStrSizeHex(const size_t sourceSize)
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
// {uncrustify_off - array alignment}
|
||||
static const int8_t decodeHexLookup[256] =
|
||||
{
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
@ -379,6 +380,7 @@ static const int8_t decodeHexLookup[256] =
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
};
|
||||
// {uncrustify_on}
|
||||
|
||||
static void
|
||||
decodeToBinValidateHex(const char *const source)
|
||||
|
@ -83,6 +83,7 @@ https://en.wikipedia.org/wiki/Logjam_(computer_security).
|
||||
// Hardcoded DH parameters, used in ephemeral DH keying. This is the 2048-bit DH parameter from RFC 3526. The generation of the
|
||||
// prime is specified in RFC 2412 Appendix E, which also discusses the design choice of the generator. Note that when loaded with
|
||||
// OpenSSL this causes DH_check() to fail on DH_NOT_SUITABLE_GENERATOR, where leaking a bit is preferred.
|
||||
// {uncrustify_off - comment inside string}
|
||||
#define DH_2048 \
|
||||
"-----BEGIN DH PARAMETERS-----\n" \
|
||||
"MIIBCAKCAQEA///////////JD9qiIWjCNMTGYouA3BzRKQJOCIpnzHQCC76mOxOb\n" \
|
||||
@ -92,6 +93,7 @@ https://en.wikipedia.org/wiki/Logjam_(computer_security).
|
||||
"fDKQXkYuNs474553LBgOhgObJ4Oi7Aeij7XFXfBvTFLJ3ivL9pVYFxg5lUl86pVq\n" \
|
||||
"5RXSJhiY+gUQFXKOWoqsqmj//////////wIBAg==\n" \
|
||||
"-----END DH PARAMETERS-----"
|
||||
// {uncrustify_on}
|
||||
|
||||
static void
|
||||
tlsServerDh(SSL_CTX *const context)
|
||||
|
@ -103,8 +103,9 @@ typedef struct MemContextCallbackOne
|
||||
} MemContextCallbackOne;
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Possible sizes for the manifest based on options. Formatting has been compressed to save space.
|
||||
Possible sizes for the manifest based on options
|
||||
***********************************************************************************************************************************/
|
||||
// {uncrustify_off - formatting compressed to save space}
|
||||
static const uint8_t memContextSizePossible[memQtyMany + 1][memQtyMany + 1][memQtyOne + 1] =
|
||||
{
|
||||
// child none
|
||||
@ -137,6 +138,7 @@ static const uint8_t memContextSizePossible[memQtyMany + 1][memQtyMany + 1][memQ
|
||||
{/* callback none */ sizeof(MemContextChildMany) + sizeof(MemContextAllocMany),
|
||||
/* callback one */ sizeof(MemContextChildMany) + sizeof(MemContextAllocMany) + sizeof(MemContextCallbackOne)}},
|
||||
};
|
||||
// {uncrustify_on}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Get pointers to optional parts of the manifest
|
||||
|
@ -43,6 +43,7 @@ strIdBitFromZN(const StringIdBit bit, const char *const buffer, size_t size)
|
||||
case stringIdBit5:
|
||||
{
|
||||
// Map to convert characters to encoding
|
||||
// {uncrustify_off - array alignment}
|
||||
static const uint8_t map[256] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@ -62,6 +63,7 @@ strIdBitFromZN(const StringIdBit bit, const char *const buffer, size_t size)
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
// {uncrustify_on}
|
||||
|
||||
// Make sure the string is valid for this encoding
|
||||
for (size_t bufferIdx = 0; bufferIdx < size; bufferIdx++)
|
||||
@ -132,6 +134,7 @@ strIdBitFromZN(const StringIdBit bit, const char *const buffer, size_t size)
|
||||
ASSERT(bit == stringIdBit6);
|
||||
|
||||
// Map to convert characters to encoding
|
||||
// {uncrustify_off - array alignment}
|
||||
static const uint8_t map[256] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@ -151,6 +154,7 @@ strIdBitFromZN(const StringIdBit bit, const char *const buffer, size_t size)
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
// {uncrustify_on}
|
||||
|
||||
// Make sure the string is valid for this encoding
|
||||
for (size_t bufferIdx = 0; bufferIdx < size; bufferIdx++)
|
||||
|
@ -27,7 +27,9 @@ Function types for loading and saving
|
||||
// The purpose of this callback is to attempt a load (from file or otherwise). Return true when the load is successful or throw an
|
||||
// error. Return false when there are no more loads to try, but always make at least one load attempt. The try parameter will
|
||||
// start at 0 and be incremented on each call.
|
||||
// {uncrustify_off - uncrustify unable to parse this statement}
|
||||
typedef bool InfoLoadCallback(void *data, unsigned int try);
|
||||
// {uncrustify_on}
|
||||
|
||||
typedef void InfoLoadNewCallback(void *data, const String *section, const String *key, const String *value);
|
||||
typedef void InfoSaveCallback(void *data, const String *sectionNext, InfoSave *infoSaveData);
|
||||
|
@ -1,6 +1,9 @@
|
||||
# export PGB=pgbackrest;export PGB_IMAGE=$PGB/test:u22-main;PGB_REPO=~/Documents/Code/$PGB
|
||||
# docker build --squash -f $PGB_REPO/test/Dockerfile -t $PGB_IMAGE .
|
||||
# docker run --privileged -itd --name $PGB-test -h $PGB-test -v $PGB_REPO:/home/vagrant/$PGB $PGB_IMAGE
|
||||
#
|
||||
# When running test.pl --code-format permissions may get munged. Run this from the pgbackrest/test path to fix them:
|
||||
# find .. | grep "\.[ch]$" | xargs xattr -rc && find .. | grep "\.[ch]$" | xargs chmod -x
|
||||
FROM ubuntu:jammy
|
||||
|
||||
# Install packages
|
||||
@ -10,7 +13,7 @@ RUN DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
|
||||
libdbd-pg-perl libxml-checker-perl libyaml-perl \
|
||||
devscripts build-essential lintian git cloc txt2man debhelper libssl-dev zlib1g-dev libperl-dev libxml2-dev liblz4-dev \
|
||||
liblz4-tool libpq-dev lcov autoconf-archive zstd libzstd-dev bzip2 libbz2-dev pkg-config libyaml-dev libc6-dbg wget meson \
|
||||
ccache valgrind tzdata
|
||||
ccache valgrind tzdata uncrustify
|
||||
|
||||
# Install Docker
|
||||
RUN groupadd -g5000 docker
|
||||
|
2
test/Vagrantfile
vendored
2
test/Vagrantfile
vendored
@ -76,7 +76,7 @@ Vagrant.configure(2) do |config|
|
||||
echo 'Install Build Tools' && date
|
||||
apt-get install -y devscripts build-essential lintian git cloc txt2man debhelper libssl-dev zlib1g-dev libperl-dev \
|
||||
libxml2-dev liblz4-dev liblz4-tool libpq-dev lcov autoconf-archive zstd libzstd-dev bzip2 libbz2-dev pkg-config \
|
||||
libyaml-dev libc6-dbg valgrind meson ccache
|
||||
libyaml-dev libc6-dbg valgrind meson ccache uncrustify
|
||||
|
||||
#-----------------------------------------------------------------------------------------------------------------------
|
||||
echo 'Install Docker' && date
|
||||
|
@ -188,7 +188,8 @@ eval
|
||||
{
|
||||
# Build list of packages that need to be installed
|
||||
my $strPackage =
|
||||
"make gcc ccache meson python3-pip git rsync zlib1g-dev libssl-dev libxml2-dev libpq-dev libyaml-dev pkg-config";
|
||||
"make gcc ccache meson python3-pip git rsync zlib1g-dev libssl-dev libxml2-dev libpq-dev libyaml-dev pkg-config" .
|
||||
" uncrustify";
|
||||
|
||||
# Add lcov when testing coverage
|
||||
if (vmCoverageC($strVm))
|
||||
|
@ -343,6 +343,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
hrnPackReadToStr(pckReadNew(pckWriteResult(bldHlpRenderHelpAutoCPack(bldCfg, bldHlpParse(storageTest, bldCfg))))),
|
||||
// {uncrustify_off - indentation}
|
||||
"1:array:"
|
||||
"["
|
||||
// backup command
|
||||
@ -400,6 +401,7 @@ testRun(void)
|
||||
", 2:str:stanza2"
|
||||
"]"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"parse and render");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -50,6 +50,7 @@ testRun(void)
|
||||
HRN_CFG_LOAD(cfgCmdInfo, argListStanzaOpt);
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":[],"
|
||||
@ -74,6 +75,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - empty repo, stanza option specified");
|
||||
|
||||
StringList *argListTextStanzaOpt = strLstDup(argListText);
|
||||
@ -101,6 +103,7 @@ testRun(void)
|
||||
HRN_CFG_LOAD(cfgCmdInfo, argList);
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":[],"
|
||||
@ -125,6 +128,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - missing stanza data");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -148,6 +152,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":[],"
|
||||
@ -183,6 +188,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - other error, single repo");
|
||||
|
||||
HRN_CFG_LOAD(cfgCmdInfo, argListTextStanzaOpt);
|
||||
@ -252,6 +258,7 @@ testRun(void)
|
||||
HRN_CFG_LOAD(cfgCmdInfo, argList);
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":["
|
||||
@ -299,6 +306,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - single stanza, no valid backups, backup/expire lock detected");
|
||||
|
||||
HRN_CFG_LOAD(cfgCmdInfo, argListText);
|
||||
@ -444,6 +452,7 @@ testRun(void)
|
||||
HRN_CFG_LOAD(cfgCmdInfo, argList);
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":["
|
||||
@ -576,6 +585,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - single stanza, valid backup, no priors, no archives in latest DB, backup/expire lock detected");
|
||||
|
||||
HRN_CFG_LOAD(cfgCmdInfo, argListText);
|
||||
@ -1038,6 +1048,7 @@ testRun(void)
|
||||
HRN_CFG_LOAD(cfgCmdInfo, argListMultiRepoJson);
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":["
|
||||
@ -1441,6 +1452,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - multiple stanzas, some with valid backups, archives in latest DB, backup lock held on one stanza");
|
||||
|
||||
// Notify child to release lock
|
||||
@ -1587,6 +1599,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":[],"
|
||||
@ -1619,6 +1632,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json, multi-repo, backup not found");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -1661,6 +1675,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":["
|
||||
@ -1763,6 +1778,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - backup set requested");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -1846,6 +1862,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":["
|
||||
@ -1970,6 +1987,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - multi-repo, backup set requested, found on repo2, report stanza and db over all repos");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -2043,6 +2061,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":["
|
||||
@ -2141,6 +2160,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - backup set requested, no links");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -2212,6 +2232,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":["
|
||||
@ -2306,6 +2327,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - backup set requested, no db and no checksum error");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -2361,6 +2383,7 @@ testRun(void)
|
||||
HRN_CFG_LOAD(cfgCmdInfo, argList2);
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":["
|
||||
@ -2410,6 +2433,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - multiple stanzas - selected found, repo1");
|
||||
|
||||
argList2 = strLstDup(argListMultiRepo);
|
||||
@ -2735,6 +2759,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":["
|
||||
@ -2905,6 +2930,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - multi-repo, database mismatch, repo2 stanza-upgrade needed");
|
||||
|
||||
// Crypto error
|
||||
@ -3289,6 +3315,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
infoRender(),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"{"
|
||||
"\"archive\":[],"
|
||||
@ -3314,6 +3341,7 @@ testRun(void)
|
||||
"}"
|
||||
"}"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json - invalid stanza");
|
||||
|
||||
argList = strLstNew();
|
||||
|
@ -54,9 +54,11 @@ testRun(void)
|
||||
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "missing directory (json)");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(output),
|
||||
"{"
|
||||
"\".\":{\"type\":\"path\"}"
|
||||
"}\n",
|
||||
// {uncrustify_off - indentation}
|
||||
"{"
|
||||
"\".\":{\"type\":\"path\"}"
|
||||
"}\n",
|
||||
// {uncrustify_on}
|
||||
"check output");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -74,9 +76,11 @@ testRun(void)
|
||||
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "empty directory (json)");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(output),
|
||||
"{"
|
||||
"\".\":{\"type\":\"path\"}"
|
||||
"}\n",
|
||||
// {uncrustify_off - indentation}
|
||||
"{"
|
||||
"\".\":{\"type\":\"path\"}"
|
||||
"}\n",
|
||||
// {uncrustify_on}
|
||||
"check output");
|
||||
|
||||
output = bufNew(0);
|
||||
@ -84,9 +88,11 @@ testRun(void)
|
||||
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "empty directory with filter match (json)");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(output),
|
||||
"{"
|
||||
"\".\":{\"type\":\"path\"}"
|
||||
"}\n",
|
||||
// {uncrustify_off - indentation}
|
||||
"{"
|
||||
"\".\":{\"type\":\"path\"}"
|
||||
"}\n",
|
||||
// {uncrustify_on}
|
||||
"check output");
|
||||
|
||||
output = bufNew(0);
|
||||
@ -130,13 +136,15 @@ testRun(void)
|
||||
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "path and file (json)");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(output),
|
||||
"{"
|
||||
"\".\":{\"type\":\"path\"},"
|
||||
"\"aaa\":{\"type\":\"file\",\"size\":8,\"time\":1578671569},"
|
||||
"\"bbb\":{\"type\":\"path\"},"
|
||||
"\"link\":{\"type\":\"link\",\"destination\":\"../bbb\"},"
|
||||
"\"pipe\":{\"type\":\"special\"}"
|
||||
"}\n",
|
||||
// {uncrustify_off - indentation}
|
||||
"{"
|
||||
"\".\":{\"type\":\"path\"},"
|
||||
"\"aaa\":{\"type\":\"file\",\"size\":8,\"time\":1578671569},"
|
||||
"\"bbb\":{\"type\":\"path\"},"
|
||||
"\"link\":{\"type\":\"link\",\"destination\":\"../bbb\"},"
|
||||
"\"pipe\":{\"type\":\"special\"}"
|
||||
"}\n",
|
||||
// {uncrustify_on}
|
||||
"check output");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
@ -268,9 +276,11 @@ testRun(void)
|
||||
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "file (json)");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(output),
|
||||
"{"
|
||||
"\".\":{\"type\":\"file\",\"size\":8,\"time\":1578671569}"
|
||||
"}\n",
|
||||
// {uncrustify_off - indentation}
|
||||
"{"
|
||||
"\".\":{\"type\":\"file\",\"size\":8,\"time\":1578671569}"
|
||||
"}\n",
|
||||
// {uncrustify_on}
|
||||
"check output");
|
||||
|
||||
output = bufNew(0);
|
||||
@ -278,9 +288,11 @@ testRun(void)
|
||||
TEST_RESULT_VOID(storageListRender(ioBufferWriteNew(output)), "file (json)");
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewBuf(output),
|
||||
"{"
|
||||
"\".\":{\"type\":\"file\",\"size\":8,\"time\":1578671569}"
|
||||
"}\n",
|
||||
// {uncrustify_off - indentation}
|
||||
"{"
|
||||
"\".\":{\"type\":\"file\",\"size\":8,\"time\":1578671569}"
|
||||
"}\n",
|
||||
// {uncrustify_on}
|
||||
"check output");
|
||||
|
||||
output = bufNew(0);
|
||||
|
@ -354,12 +354,14 @@ testRun(void)
|
||||
|
||||
// Check block that errors
|
||||
TEST_ERROR(
|
||||
// {uncrustify_off - indentation}
|
||||
MEM_CONTEXT_BEGIN(memContext)
|
||||
{
|
||||
TEST_RESULT_Z(memContextCurrent()->name, "test-block", "context is now test-block");
|
||||
THROW(AssertError, "error in test block");
|
||||
}
|
||||
MEM_CONTEXT_END(),
|
||||
// {uncrustify_on}
|
||||
AssertError, "error in test block");
|
||||
|
||||
TEST_RESULT_Z(memContextCurrent()->name, "TOP", "context is now top");
|
||||
|
@ -271,6 +271,7 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
jsonWriteResult(write),
|
||||
// {uncrustify_off - indentation}
|
||||
"["
|
||||
"true,"
|
||||
"55,"
|
||||
@ -291,6 +292,7 @@ testRun(void)
|
||||
"null,"
|
||||
"null"
|
||||
"]",
|
||||
// {uncrustify_on}
|
||||
"json result");
|
||||
|
||||
TEST_RESULT_VOID(jsonWriteFree(write), "free");
|
||||
|
@ -126,9 +126,10 @@ testRun(void)
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
hrnPackToStr(pckFromBuf(pack)),
|
||||
"1:u64:488"
|
||||
", 2:u64:1911246845"
|
||||
", 7:u64:18446744073709551615"
|
||||
// {uncrustify_off - indentation}
|
||||
"1:u64:488"
|
||||
", 2:u64:1911246845"
|
||||
", 7:u64:18446744073709551615"
|
||||
", 10:u64:1"
|
||||
", 11:u64:77"
|
||||
", 12:u32:127"
|
||||
@ -174,10 +175,12 @@ testRun(void)
|
||||
", 51:bin:"
|
||||
", 52:pack:<1:u64:345, 3:str:sub>"
|
||||
", 54:array:[1:str:a, 2:str:bcd]",
|
||||
// {uncrustify_on}
|
||||
"check pack string");
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
strNewEncode(encodingHex, pack),
|
||||
// {uncrustify_off - indentation}
|
||||
"98e803" // 1, u64, 750
|
||||
"98fd9fad8f07" // 2, u64, 1911246845
|
||||
"9c01ffffffffffffffffff01" // 7, u64, 0xFFFFFFFFFFFFFFFF
|
||||
@ -223,6 +226,7 @@ testRun(void)
|
||||
"f0020998d902790373756200" // 52, pack, 1:u64:345, 3:str:sub
|
||||
"11780161780362636400" // 54, strlst, 1:str:a, 2:str:bcd
|
||||
"00", // end
|
||||
// {uncrustify_on}
|
||||
"check pack hex");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
|
@ -25,6 +25,7 @@ STRING_STATIC(TEST_KEY_FILE_STR, TEST_KEY_FIL
|
||||
#define TEST_TOKEN "X X"
|
||||
STRING_STATIC(TEST_TOKEN_STR, TEST_TOKEN);
|
||||
|
||||
// {uncrustify_off - comment inside string}
|
||||
#define TEST_KEY \
|
||||
"{\n" \
|
||||
"\"type\": \"service_account\",\n" \
|
||||
@ -60,6 +61,7 @@ STRING_STATIC(TEST_TOKEN_STR, TEST_TOKEN);
|
||||
"\"client_email\": \"service@project.iam.gserviceaccount.com\",\n" \
|
||||
"\"token_uri\": \"https://%s:%u/token\"\n" \
|
||||
"}\n"
|
||||
// {uncrustify_on}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Helper to build test requests
|
||||
|
@ -892,6 +892,7 @@ testRun(void)
|
||||
#define TEST_SERVICE_URI \
|
||||
"/?Action=AssumeRoleWithWebIdentity&RoleArn=arn%3Aaws%3Aiam%3A%3A123456789012%3Arole%2FTestRole" \
|
||||
"&RoleSessionName=pgBackRest&Version=2011-06-15&WebIdentityToken=" TEST_SERVICE_TOKEN
|
||||
// {uncrustify_off - comment inside string}
|
||||
#define TEST_SERVICE_RESPONSE \
|
||||
"<AssumeRoleWithWebIdentityResponse xmlns=\"https://sts.amazonaws.com/doc/2011-06-15/\">\n" \
|
||||
" <AssumeRoleWithWebIdentityResult>\n" \
|
||||
@ -903,6 +904,7 @@ testRun(void)
|
||||
" </Credentials>\n" \
|
||||
" </AssumeRoleWithWebIdentityResult>\n" \
|
||||
"</AssumeRoleWithWebIdentityResponse>"
|
||||
// {uncrustify_on}
|
||||
|
||||
HRN_STORAGE_PUT_Z(storagePosixNewP(TEST_PATH_STR, .write = true), "web-id-token", TEST_SERVICE_TOKEN);
|
||||
|
||||
|
46
test/test.pl
46
test/test.pl
@ -91,6 +91,10 @@ test.pl [options]
|
||||
--tz test with the specified timezone
|
||||
--debug-test-trace test stack trace for low-level functions (slow, esp w/valgrind, may cause timeouts)
|
||||
|
||||
Code Format Options:
|
||||
--code-format format code to project standards -- this may overwrite files!
|
||||
--code-format-check check that code is formatted to project standards
|
||||
|
||||
Report Options:
|
||||
--coverage-summary generate a coverage summary report for the documentation
|
||||
--coverage-only only run coverage tests (as a subset of selected tests) for the documentation
|
||||
@ -133,6 +137,8 @@ my @iyModuleTestRun;
|
||||
my $iVmMax = 1;
|
||||
my $iVmId = undef;
|
||||
my $bDryRun = false;
|
||||
my $bCodeFormat = false;
|
||||
my $bCodeFormatCheck = false;
|
||||
my $bNoCleanup = false;
|
||||
my $strPgSqlBin;
|
||||
my $strTestPath;
|
||||
@ -208,6 +214,8 @@ GetOptions ('q|quiet' => \$bQuiet,
|
||||
'gen-check' => \$bGenCheck,
|
||||
'min-gen' => \$bMinGen,
|
||||
'code-count' => \$bCodeCount,
|
||||
'code-format' => \$bCodeFormat,
|
||||
'code-format-check' => \$bCodeFormatCheck,
|
||||
'profile' => \$bProfile,
|
||||
'no-back-trace' => \$bNoBackTrace,
|
||||
'no-valgrind' => \$bNoValgrind,
|
||||
@ -609,6 +617,44 @@ eval
|
||||
(trim(`uname`) ne 'Darwin' ? ' --ignore-missing-args' : '') .
|
||||
" ${strBackRestBase}/ ${strRepoCachePath}");
|
||||
|
||||
# Format code with uncrustify
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
if ($bCodeFormat || $bCodeFormatCheck)
|
||||
{
|
||||
&log(INFO, 'code format' . ($bCodeFormatCheck ? ' check' : ''));
|
||||
|
||||
my $hManifest = $oStorageTest->manifest($strRepoCachePath);
|
||||
my $strCommand =
|
||||
"uncrustify -c ${strBackRestBase}/test/uncrustify.cfg" .
|
||||
($bCodeFormatCheck ? ' --check' : ' --replace --no-backup');
|
||||
|
||||
foreach my $strFile (sort(keys(%{$hManifest})))
|
||||
{
|
||||
# Skip non-C files
|
||||
next if $hManifest->{$strFile}{type} ne 'f' || ($strFile !~ /\.c$/ && $strFile !~ /\.h$/);
|
||||
|
||||
# Check mode
|
||||
if ($hManifest->{$strFile}{mode} ne '0644')
|
||||
{
|
||||
confess &log(ERROR, "expected mode '0644' for '$strFile' but found '" . $hManifest->{$strFile}{mode} . "'");
|
||||
}
|
||||
|
||||
# Skip specific file
|
||||
next if
|
||||
# Does not format correctly because it is a template
|
||||
$strFile eq 'test/src/test.c' ||
|
||||
# Contains code copied directly from PostgreSQL
|
||||
$strFile eq 'src/postgres/interface/static.vendor.h' ||
|
||||
$strFile eq 'src/postgres/interface/version.vendor.h';
|
||||
|
||||
$strCommand .= " ${strBackRestBase}/${strFile}";
|
||||
}
|
||||
|
||||
executeTest($strCommand . " 2>&1");
|
||||
|
||||
exit 0;
|
||||
}
|
||||
|
||||
# Generate code counts
|
||||
#---------------------------------------------------------------------------------------------------------------------------
|
||||
if ($bCodeCount)
|
||||
|
3137
test/uncrustify.cfg
Executable file
3137
test/uncrustify.cfg
Executable file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user