Add a LINT option to CMake (#372)
* ci: make style-checking available locally * cmake: add a linting target * tests: check test suite syntax with checksrc.pl
Этот коммит содержится в:
родитель
cde13f6201
Коммит
1adb24fd07
12
.travis.yml
12
.travis.yml
@ -46,10 +46,12 @@ compiler:
|
||||
|
||||
addons:
|
||||
chrome: stable
|
||||
matrix:
|
||||
include:
|
||||
- name: "Check style"
|
||||
script: ./ci/checksrc.sh
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- B=style
|
||||
- ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF B=configure
|
||||
- ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=OFF ENABLE_ZLIB_COMPRESSION=OFF B=cmake
|
||||
- ADDRESS_SIZE=64 CRYPTO_BACKEND=OpenSSL BUILD_SHARED_LIBS=ON ENABLE_ZLIB_COMPRESSION=OFF B=cmake
|
||||
@ -100,12 +102,6 @@ before_install:
|
||||
install:
|
||||
|
||||
script:
|
||||
- |
|
||||
if [ "$B" = "style" ]; then
|
||||
./buildconf
|
||||
./configure
|
||||
make checksrc
|
||||
fi
|
||||
- |
|
||||
if [ "$B" = "configure" ]; then
|
||||
autoreconf -fi
|
||||
|
@ -98,6 +98,14 @@ if(BUILD_TESTING)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
option(LINT "Check style while building" OFF)
|
||||
if(LINT)
|
||||
add_custom_target(lint ALL
|
||||
./ci/checksrc.sh
|
||||
WORKING_DIRECTORY ${libssh2_SOURCE_DIR})
|
||||
add_dependencies(libssh2 lint)
|
||||
endif()
|
||||
|
||||
add_subdirectory(docs)
|
||||
|
||||
feature_summary(WHAT ALL)
|
||||
|
8
ci/checksrc.sh
Исполняемый файл
8
ci/checksrc.sh
Исполняемый файл
@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
FILES="src/*.[ch] include/*.h example/*.c tests/*.[ch]"
|
||||
WHITELIST="-Wsrc/libssh2_config.h"
|
||||
|
||||
perl ./ci/checksrc.pl -i4 -m79 -ASIZEOFNOPAREN -ASNPRINTF -ACOPYRIGHT -AFOPENMODE $WHITELIST $FILES
|
@ -42,6 +42,11 @@ pass the options to CMake on the command line:
|
||||
|
||||
The following options are available:
|
||||
|
||||
* `LINT=ON`
|
||||
|
||||
Enables running the source code linter when building. Can be `ON` or `OFF`.
|
||||
|
||||
|
||||
* `BUILD_SHARED_LIBS=OFF`
|
||||
|
||||
Determines whether libssh2 is built as a static library or as a
|
||||
|
@ -118,9 +118,9 @@ static int run_command_varg(char **output, const char *command, va_list args)
|
||||
if(output) {
|
||||
/* command output may contain a trailing newline, so we trim
|
||||
* whitespace here */
|
||||
size_t end = strlen(buf) - 1;
|
||||
while(end > 0 && isspace(buf[end])) {
|
||||
buf[end] = '\0';
|
||||
size_t end = strlen(buf);
|
||||
while(end > 0 && isspace(buf[end - 1])) {
|
||||
buf[end - 1] = '\0';
|
||||
}
|
||||
|
||||
*output = strdup(buf);
|
||||
@ -140,7 +140,7 @@ static int run_command(char **output, const char *command, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int build_openssh_server_docker_image()
|
||||
static int build_openssh_server_docker_image(void)
|
||||
{
|
||||
return run_command(NULL, "docker build -t libssh2/openssh_server "
|
||||
"openssh_server");
|
||||
@ -157,7 +157,7 @@ static int stop_openssh_server(char *container_id)
|
||||
return run_command(NULL, "docker stop %s", container_id);
|
||||
}
|
||||
|
||||
static const char *docker_machine_name()
|
||||
static const char *docker_machine_name(void)
|
||||
{
|
||||
return getenv("DOCKER_MACHINE_NAME");
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ int test(LIBSSH2_SESSION *session)
|
||||
rc = libssh2_channel_request_auth_agent(channel);
|
||||
if(rc != 0) {
|
||||
fprintf(stderr, "Auth agent request for agent forwarding failed, "
|
||||
"error code %d\n", rc);
|
||||
"error code %d\n", rc);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -84,8 +84,9 @@ int test(LIBSSH2_SESSION *session)
|
||||
calculate_digest(md5_hash, MD5_HASH_SIZE, buf, BUFSIZ);
|
||||
|
||||
if(strcmp(buf, EXPECTED_ECDSA_MD5_HASH_DIGEST) != 0) {
|
||||
fprintf(stderr, "ECDSA MD5 hash not as expected, digest "
|
||||
"%s != %s\n", buf, EXPECTED_ECDSA_MD5_HASH_DIGEST);
|
||||
fprintf(stderr,
|
||||
"ECDSA MD5 hash not as expected - digest %s != %s\n",
|
||||
buf, EXPECTED_ECDSA_MD5_HASH_DIGEST);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -99,8 +100,9 @@ int test(LIBSSH2_SESSION *session)
|
||||
calculate_digest(sha1_hash, SHA1_HASH_SIZE, buf, BUFSIZ);
|
||||
|
||||
if(strcmp(buf, EXPECTED_ECDSA_SHA1_HASH_DIGEST) != 0) {
|
||||
fprintf(stderr, "ECDSA SHA1 hash not as expected, digest "
|
||||
"%s != %s\n", buf, EXPECTED_ECDSA_SHA1_HASH_DIGEST);
|
||||
fprintf(stderr,
|
||||
"ECDSA SHA1 hash not as expected - digest %s != %s\n",
|
||||
buf, EXPECTED_ECDSA_SHA1_HASH_DIGEST);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -115,8 +117,9 @@ int test(LIBSSH2_SESSION *session)
|
||||
calculate_digest(sha256_hash, SHA256_HASH_SIZE, buf, BUFSIZ);
|
||||
|
||||
if(strcmp(buf, EXPECTED_ECDSA_SHA256_HASH_DIGEST) != 0) {
|
||||
fprintf(stderr, "ECDSA SHA256 hash not as expected, digest "
|
||||
"%s != %s\n", buf, EXPECTED_ECDSA_SHA256_HASH_DIGEST);
|
||||
fprintf(stderr,
|
||||
"ECDSA SHA256 hash not as expected - digest %s != %s\n",
|
||||
buf, EXPECTED_ECDSA_SHA256_HASH_DIGEST);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -133,8 +136,9 @@ int test(LIBSSH2_SESSION *session)
|
||||
calculate_digest(md5_hash, MD5_HASH_SIZE, buf, BUFSIZ);
|
||||
|
||||
if(strcmp(buf, EXPECTED_RSA_MD5_HASH_DIGEST) != 0) {
|
||||
fprintf(stderr, "MD5 hash not as expected, digest "
|
||||
"%s != %s\n", buf, EXPECTED_RSA_MD5_HASH_DIGEST);
|
||||
fprintf(stderr,
|
||||
"MD5 hash not as expected - digest %s != %s\n",
|
||||
buf, EXPECTED_RSA_MD5_HASH_DIGEST);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -148,8 +152,9 @@ int test(LIBSSH2_SESSION *session)
|
||||
calculate_digest(sha1_hash, SHA1_HASH_SIZE, buf, BUFSIZ);
|
||||
|
||||
if(strcmp(buf, EXPECTED_RSA_SHA1_HASH_DIGEST) != 0) {
|
||||
fprintf(stderr, "SHA1 hash not as expected, digest "
|
||||
"%s != %s\n", buf, EXPECTED_RSA_SHA1_HASH_DIGEST);
|
||||
fprintf(stderr,
|
||||
"SHA1 hash not as expected - digest %s != %s\n",
|
||||
buf, EXPECTED_RSA_SHA1_HASH_DIGEST);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -164,8 +169,9 @@ int test(LIBSSH2_SESSION *session)
|
||||
calculate_digest(sha256_hash, SHA256_HASH_SIZE, buf, BUFSIZ);
|
||||
|
||||
if(strcmp(buf, EXPECTED_RSA_SHA256_HASH_DIGEST) != 0) {
|
||||
fprintf(stderr, "SHA256 hash not as expected, digest "
|
||||
"%s != %s\n", buf, EXPECTED_RSA_SHA256_HASH_DIGEST);
|
||||
fprintf(stderr,
|
||||
"SHA256 hash not as expected - digest %s != %s\n",
|
||||
buf, EXPECTED_RSA_SHA256_HASH_DIGEST);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,9 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *USERNAME = "libssh2"; /* set in Dockerfile */
|
||||
static const char *PASSWORD = "my test password"; /* set in Dockerfile */
|
||||
/* configured in Dockerfile */
|
||||
static const char *USERNAME = "libssh2";
|
||||
static const char *PASSWORD = "my test password";
|
||||
|
||||
static void kbd_callback(const char *name, int name_len,
|
||||
const char *instruct, int instruct_len,
|
||||
|
@ -4,7 +4,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *PASSWORD = "my test password"; /* set in Dockerfile */
|
||||
/* configured in Dockerfile */
|
||||
static const char *PASSWORD = "my test password";
|
||||
static const char *WRONG_USERNAME = "i dont exist";
|
||||
|
||||
int test(LIBSSH2_SESSION *session)
|
||||
|
@ -4,8 +4,9 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *USERNAME = "libssh2"; /* set in Dockerfile */
|
||||
static const char *PASSWORD = "my test password"; /* set in Dockerfile */
|
||||
/* configured in Dockerfile */
|
||||
static const char *USERNAME = "libssh2";
|
||||
static const char *PASSWORD = "my test password";
|
||||
|
||||
int test(LIBSSH2_SESSION *session)
|
||||
{
|
||||
|
@ -4,9 +4,10 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *USERNAME = "libssh2"; /* set in Dockerfile */
|
||||
/* configured in Dockerfile */
|
||||
static const char *USERNAME = "libssh2";
|
||||
static const char *KEY_FILE_PRIVATE = "key_dsa";
|
||||
static const char *KEY_FILE_PUBLIC = "key_dsa.pub"; /* set in Dockerfile */
|
||||
static const char *KEY_FILE_PUBLIC = "key_dsa.pub";
|
||||
|
||||
int test(LIBSSH2_SESSION *session)
|
||||
{
|
||||
|
@ -4,9 +4,10 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *USERNAME = "libssh2"; /* set in Dockerfile */
|
||||
/* configured in Dockerfile */
|
||||
static const char *USERNAME = "libssh2";
|
||||
static const char *KEY_FILE_PRIVATE = "key_ed25519";
|
||||
static const char *KEY_FILE_PUBLIC = "key_ed25519.pub"; /* set in Dockerfile */
|
||||
static const char *KEY_FILE_PUBLIC = "key_ed25519.pub";
|
||||
|
||||
int test(LIBSSH2_SESSION *session)
|
||||
{
|
||||
|
@ -35,9 +35,11 @@ int test(LIBSSH2_SESSION *session)
|
||||
return 1;
|
||||
}
|
||||
|
||||
rc = libssh2_userauth_publickey_frommemory(session, USERNAME,
|
||||
strlen(USERNAME),
|
||||
NULL, 0, buffer, len, NULL);
|
||||
rc = libssh2_userauth_publickey_frommemory(session,
|
||||
USERNAME, strlen(USERNAME),
|
||||
NULL, 0,
|
||||
buffer, len,
|
||||
NULL);
|
||||
|
||||
free(buffer);
|
||||
|
||||
|
@ -4,11 +4,11 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *USERNAME = "libssh2"; /* set in Dockerfile */
|
||||
/* configured in Dockerfile */
|
||||
static const char *USERNAME = "libssh2";
|
||||
static const char *PASSWORD = "libssh2";
|
||||
static const char *KEY_FILE_PRIVATE = "key_ed25519_encrypted";
|
||||
static const char *KEY_FILE_PUBLIC = "key_ed25519_encrypted.pub";
|
||||
/* set in Dockerfile */
|
||||
|
||||
int test(LIBSSH2_SESSION *session)
|
||||
{
|
||||
|
@ -4,11 +4,11 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *USERNAME = "libssh2"; /* set in Dockerfile */
|
||||
/* configured in Dockerfile */
|
||||
static const char *USERNAME = "libssh2";
|
||||
static const char *PASSWORD = "libssh2";
|
||||
static const char *KEY_FILE_PRIVATE = "key_rsa_encrypted";
|
||||
static const char *KEY_FILE_PUBLIC = "key_rsa_encrypted.pub";
|
||||
/* set in Dockerfile */
|
||||
|
||||
int test(LIBSSH2_SESSION *session)
|
||||
{
|
||||
|
@ -4,9 +4,10 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *USERNAME = "libssh2"; /* set in Dockerfile */
|
||||
/* configured in Dockerfile */
|
||||
static const char *USERNAME = "libssh2";
|
||||
static const char *KEY_FILE_PRIVATE = "key_rsa";
|
||||
static const char *KEY_FILE_PUBLIC = "key_rsa.pub"; /* set in Dockerfile */
|
||||
static const char *KEY_FILE_PUBLIC = "key_rsa.pub";
|
||||
|
||||
int test(LIBSSH2_SESSION *session)
|
||||
{
|
||||
|
@ -4,10 +4,10 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static const char *USERNAME = "libssh2"; /* set in Dockerfile */
|
||||
/* configured in Dockerfile */
|
||||
static const char *USERNAME = "libssh2";
|
||||
static const char *KEY_FILE_PRIVATE = "key_rsa_openssh";
|
||||
static const char *KEY_FILE_PUBLIC = "key_rsa_openssh.pub";
|
||||
/* set in Dockerfile */
|
||||
|
||||
int test(LIBSSH2_SESSION *session)
|
||||
{
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user