add test with iwyu and fix all headers accordingly

This commit is contained in:
josch
2014-09-20 09:40:59 +02:00
parent 4b2563d800
commit d8e00119b4
39 changed files with 152 additions and 159 deletions

View File

@@ -2,6 +2,9 @@ cmake_minimum_required(VERSION 2.8)
project(mediafire-tools)
# creates file compile_commands.json in build directory which is used
# to feed iwyu during tests
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
add_library(mfapi SHARED mfapi/mfconn.c mfapi/file.c mfapi/folder.c mfapi/apicalls/file_get_info.c mfapi/apicalls/user_get_info.c mfapi/apicalls/file_get_links.c mfapi/apicalls/user_session.c mfapi/apicalls/folder_get_info.c mfapi/apicalls/folder_create.c mfapi/apicalls/folder_get_content.c)
set_target_properties(mfapi PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror")
@@ -12,3 +15,7 @@ set_target_properties(mfutils PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror")
add_executable(mfshell mfshell/main.c mfshell/mfshell.c mfshell/commands/auth.c mfshell/commands/chdir.c mfshell/commands/debug.c mfshell/commands/file.c mfshell/commands/get.c mfshell/commands/help.c mfshell/commands/host.c mfshell/commands/lcd.c mfshell/commands/links.c mfshell/commands/list.c mfshell/commands/lpwd.c mfshell/commands/mkdir.c mfshell/commands/pwd.c mfshell/commands/whoami.c)
set_target_properties(mfshell PROPERTIES COMPILE_FLAGS "-Wall -Wextra -Werror")
target_link_libraries(mfshell curl ssl crypto jansson mfapi mfutils)
enable_testing()
add_test(iwyu ../tests/iwyu.py)

View File

@@ -18,8 +18,8 @@
*/
#ifndef _MFSHELL_MFAPI_H_
#define _MFSHELL_FILE_INFO_H_
#ifndef _MFAPI_APICALLS_H_
#define _MFAPI_APICALLS_H_
#include <stdint.h>

View File

@@ -18,18 +18,15 @@
*/
#include <jansson.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <curl/curl.h>
#include <jansson.h>
#include "../apicalls.h"
#include "../mfconn.h"
#include "../../utils/strings.h"
#include "../../utils/json.h"
#include "../../utils/http.h"
#include "../../utils/json.h"
#include "../mfconn.h"
#include "../file.h"
#include "../apicalls.h" // IWYU pragma: keep
static int
_decode_file_get_info(mfhttp *conn, void *data);

View File

@@ -18,18 +18,15 @@
*/
#include <jansson.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <curl/curl.h>
#include <jansson.h>
#include "../apicalls.h"
#include "../mfconn.h"
#include "../../utils/strings.h"
#include "../../utils/json.h"
#include "../../utils/http.h"
#include "../../utils/json.h"
#include "../mfconn.h"
#include "../file.h"
#include "../apicalls.h" // IWYU pragma: keep
static int
_decode_file_get_links(mfhttp *conn, void *data);

View File

@@ -20,14 +20,10 @@
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <curl/curl.h>
#include "../apicalls.h"
#include "../mfconn.h"
#include "../../utils/http.h"
#include "../../utils/strings.h"
#include "../mfconn.h"
#include "../apicalls.h" // IWYU pragma: keep
int
mfconn_api_folder_create(mfconn *conn,char *parent,char *name)

View File

@@ -18,19 +18,16 @@
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <curl/curl.h>
#include <jansson.h>
#include <stdio.h>
#include <stdlib.h>
#include "../apicalls.h"
#include "../mfconn.h"
#include "../folder.h"
#include "../../utils/strings.h"
#include "../../utils/json.h"
#include "../../utils/http.h"
#include "../../utils/json.h"
#include "../../utils/strings.h"
#include "../folder.h"
#include "../mfconn.h"
#include "../apicalls.h" // IWYU pragma: keep
static int
_decode_folder_get_content_folders(mfhttp *conn, void *data);

View File

@@ -18,19 +18,15 @@
*/
#include <jansson.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <curl/curl.h>
#include <jansson.h>
#include "../apicalls.h"
#include "../mfconn.h"
#include "../folder.h"
#include "../../utils/strings.h"
#include "../../utils/json.h"
#include "../../utils/http.h"
#include "../../utils/json.h"
#include "../folder.h"
#include "../mfconn.h"
#include "../apicalls.h" // IWYU pragma: keep
static int
_decode_folder_get_info(mfhttp *conn, void *data);

View File

@@ -18,18 +18,13 @@
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <curl/curl.h>
#include <jansson.h>
#include <stdio.h>
#include "../apicalls.h"
#include "../mfconn.h"
#include "../../utils/strings.h"
#include "../../utils/json.h"
#include "../../utils/http.h"
#include "../../utils/json.h"
#include "../mfconn.h"
#include "../apicalls.h" // IWYU pragma: keep
static int
_decode_user_get_info(mfhttp *conn, void *data);

View File

@@ -18,18 +18,17 @@
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <curl/curl.h>
#include <jansson.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../apicalls.h"
#include "../mfconn.h"
#include "../../utils/http.h"
#include "../../utils/strings.h"
#include "../../utils/json.h"
#include "../../utils/strings.h"
#include "../mfconn.h"
#include "../apicalls.h" // IWYU pragma: keep
static int
_decode_get_session_token(mfhttp *conn, void *data);

View File

@@ -18,13 +18,19 @@
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include "../utils/http.h"
#include "../utils/strings.h"
#include "file.h"
struct _file_s
struct mffile
{
char quickkey[18];
char hash[65];
@@ -206,21 +212,6 @@ file_get_onetime_link(mffile *file)
return file->onetime_link;
}
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <curl/curl.h>
#include "mfconn.h"
#include "../utils/http.h"
#include "../utils/strings.h"
ssize_t
file_download_direct(mffile *file, char *local_dir)
{

View File

@@ -20,9 +20,9 @@
#ifndef __MFAPI_FILE_H__
#define __MFAPI_FILE_H__
typedef struct _file_s mffile;
#include <sys/types.h>
struct _file_s;
typedef struct mffile mffile;
mffile* file_alloc(void);

View File

@@ -18,13 +18,13 @@
*/
#include <stdint.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include "folder.h"
struct _folder_s
struct mffolder
{
char folderkey[20];
char name[41];

View File

@@ -20,9 +20,7 @@
#ifndef __MFAPI_FOLDER_H__
#define __MFAPI_FOLDER_H__
typedef struct _folder_s mffolder;
struct _folder_s;
typedef struct mffolder mffolder;
mffolder* folder_alloc(void);

View File

@@ -17,16 +17,16 @@
*
*/
#include <stdio.h>
#include <curl/curl.h>
#include <openssl/ssl.h>
#include <openssl/sha.h>
#include <openssl/md5.h>
#include <openssl/sha.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../utils/strings.h"
#include "mfconn.h"
#include "apicalls.h"
#include "mfconn.h"
struct mfconn
{

View File

@@ -20,6 +20,7 @@
#define __MFAPI_MFCONN_H__
#include <stdint.h>
#include <sys/types.h>
#include "file.h"

View File

@@ -18,14 +18,16 @@
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <termios.h>
#include <unistd.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
static char*
_get_login_from_user(void);

View File

@@ -20,11 +20,12 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/folder.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_chdir(mfshell *mfshell, int argc, char **argv)

View File

@@ -18,14 +18,13 @@
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_debug(mfshell *mfshell, int argc, char **argv)

View File

@@ -21,9 +21,11 @@
#include <stdio.h>
#include <string.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/file.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_file(mfshell *mfshell, int argc, char **argv)

View File

@@ -18,15 +18,17 @@
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/file.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_get(mfshell *mfshell, int argc, char **argv)

View File

@@ -20,10 +20,9 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_help(mfshell *mfshell, int argc, char **argv)

View File

@@ -18,12 +18,14 @@
*/
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
static char*
_get_host_from_user(void);

View File

@@ -20,11 +20,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_lcd(mfshell *mfshell, int argc, char **argv)

View File

@@ -21,9 +21,11 @@
#include <stdio.h>
#include <string.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/file.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_links(mfshell *mfshell, int argc, char **argv)

View File

@@ -19,12 +19,12 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/folder.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_list(mfshell *mfshell, int argc, char **argv)

View File

@@ -18,13 +18,13 @@
*/
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_lpwd(mfshell *mfshell, int argc, char **argv)

View File

@@ -19,12 +19,12 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../mfshell.h"
#include "../commands.h"
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/folder.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_mkdir(mfshell *mfshell, int argc, char **argv)

View File

@@ -19,12 +19,12 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../commands.h"
#include "../mfshell.h"
#include "../../utils/strings.h"
#include "../mfshell.h"
#include "../../mfapi/folder.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_pwd(mfshell *mfshell, int argc, char **argv)

View File

@@ -19,12 +19,11 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../commands.h"
#include "../mfshell.h"
#include "../../mfapi/apicalls.h"
#include "../mfshell.h"
#include "../../mfapi/mfconn.h"
#include "../commands.h" // IWYU pragma: keep
int
mfshell_cmd_whoami(mfshell *mfshell, int argc, char **argv)

View File

@@ -17,17 +17,15 @@
*
*/
#include <getopt.h>
#include <openssl/ssl.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <wordexp.h>
#include <openssl/ssl.h>
#include "mfshell.h"
#include "../utils/strings.h"
static void
mfshell_run(mfshell *mfshell);

View File

@@ -19,23 +19,13 @@
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <wordexp.h>
#include <sys/ioctl.h>
#include "mfshell.h"
#include "../utils/stringv.h"
#include <curl/curl.h>
#include "mfshell.h"
#include "commands.h"
#include "mfshell.h"
#include "../mfapi/folder.h"
struct mfcmd commands[] = {
{"help", "", "show this help", mfshell_cmd_help},

View File

@@ -24,6 +24,9 @@
#include "../mfapi/folder.h"
#include "../mfapi/mfconn.h"
struct mfcmd;
struct mfshell;
typedef struct mfcmd mfcmd;
typedef struct mfshell mfshell;

21
tests/iwyu.py Executable file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/env python
from __future__ import print_function
import json
import subprocess
with open("compile_commands.json", "r") as f:
tunits = json.load(f)
result = 0
for tu in tunits:
_,rest = tu["command"].split(" ",1)
# iwyu does not distinguish between different outcomes of its check
# so instead, we grep its stderr output
# see http://code.google.com/p/include-what-you-use/issues/detail?id=157
ret = subprocess.call("%s %s 2>&1 | grep \"has correct #\""%("iwyu", rest), shell=True)
if ret != 0:
result += 1
exit(result)

View File

@@ -20,6 +20,8 @@
#define _MFSHELL_HTTP_H_
#include <jansson.h>
#include <stddef.h>
#include <stdio.h>
typedef struct mfhttp mfhttp;

View File

@@ -18,7 +18,6 @@
#include <stdlib.h>
#include <string.h>
#include "json.h"
#include "stringv.h"

View File

@@ -17,11 +17,12 @@
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "strings.h"
#include "stringv.h"

View File

@@ -20,8 +20,6 @@
#ifndef _STR_TOOLS_H_
#define _STR_TOOLS_H_
#include <stdint.h>
char* strdup_printf(char* fmt, ...);
char* strdup_join(char *string1,char *string2);

View File

@@ -17,9 +17,8 @@
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "stringv.h"

View File

@@ -20,7 +20,7 @@
#ifndef _STRING_V_H_
#define _STRING_V_H_
#include <stdint.h>
#include <stddef.h>
#define STRINGV_FREE_ALL 1