From d8e00119b4953bc118bf163cb84d299748ee3cc2 Mon Sep 17 00:00:00 2001 From: josch Date: Sat, 20 Sep 2014 09:40:59 +0200 Subject: [PATCH] add test with iwyu and fix all headers accordingly --- CMakeLists.txt | 7 +++++++ mfapi/apicalls.h | 4 ++-- mfapi/apicalls/file_get_info.c | 13 +++++-------- mfapi/apicalls/file_get_links.c | 13 +++++-------- mfapi/apicalls/folder_create.c | 8 ++------ mfapi/apicalls/folder_get_content.c | 17 +++++++---------- mfapi/apicalls/folder_get_info.c | 14 +++++--------- mfapi/apicalls/user_get_info.c | 13 ++++--------- mfapi/apicalls/user_session.c | 15 +++++++-------- mfapi/file.c | 25 ++++++++----------------- mfapi/file.h | 4 ++-- mfapi/folder.c | 4 ++-- mfapi/folder.h | 4 +--- mfapi/mfconn.c | 12 ++++++------ mfapi/mfconn.h | 1 + mfshell/commands/auth.c | 6 ++++-- mfshell/commands/chdir.c | 7 ++++--- mfshell/commands/debug.c | 9 ++++----- mfshell/commands/file.c | 6 ++++-- mfshell/commands/get.c | 10 ++++++---- mfshell/commands/help.c | 3 +-- mfshell/commands/host.c | 4 +++- mfshell/commands/lcd.c | 4 ++-- mfshell/commands/links.c | 6 ++++-- mfshell/commands/list.c | 8 ++++---- mfshell/commands/lpwd.c | 4 ++-- mfshell/commands/mkdir.c | 8 ++++---- mfshell/commands/pwd.c | 6 +++--- mfshell/commands/whoami.c | 7 +++---- mfshell/main.c | 10 ++++------ mfshell/mfshell.c | 16 +++------------- mfshell/mfshell.h | 3 +++ tests/iwyu.py | 21 +++++++++++++++++++++ utils/http.h | 2 ++ utils/json.c | 1 - utils/strings.c | 9 +++++---- utils/strings.h | 2 -- utils/stringv.c | 3 +-- utils/stringv.h | 2 +- 39 files changed, 152 insertions(+), 159 deletions(-) create mode 100755 tests/iwyu.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 486ec42..e79b406 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/mfapi/apicalls.h b/mfapi/apicalls.h index 2b2e4e4..c11484a 100644 --- a/mfapi/apicalls.h +++ b/mfapi/apicalls.h @@ -18,8 +18,8 @@ */ -#ifndef _MFSHELL_MFAPI_H_ -#define _MFSHELL_FILE_INFO_H_ +#ifndef _MFAPI_APICALLS_H_ +#define _MFAPI_APICALLS_H_ #include diff --git a/mfapi/apicalls/file_get_info.c b/mfapi/apicalls/file_get_info.c index 31126e9..d2a5fc8 100644 --- a/mfapi/apicalls/file_get_info.c +++ b/mfapi/apicalls/file_get_info.c @@ -18,18 +18,15 @@ */ +#include #include #include -#include -#include -#include - -#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); diff --git a/mfapi/apicalls/file_get_links.c b/mfapi/apicalls/file_get_links.c index 68e5e95..b3d9af5 100644 --- a/mfapi/apicalls/file_get_links.c +++ b/mfapi/apicalls/file_get_links.c @@ -18,18 +18,15 @@ */ +#include #include #include -#include -#include -#include - -#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); diff --git a/mfapi/apicalls/folder_create.c b/mfapi/apicalls/folder_create.c index 47a12a5..5b4a890 100644 --- a/mfapi/apicalls/folder_create.c +++ b/mfapi/apicalls/folder_create.c @@ -20,14 +20,10 @@ #include #include -#include -#include - -#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) diff --git a/mfapi/apicalls/folder_get_content.c b/mfapi/apicalls/folder_get_content.c index cfe15e0..87f5f03 100644 --- a/mfapi/apicalls/folder_get_content.c +++ b/mfapi/apicalls/folder_get_content.c @@ -18,19 +18,16 @@ */ -#include -#include -#include - -#include #include +#include +#include -#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); diff --git a/mfapi/apicalls/folder_get_info.c b/mfapi/apicalls/folder_get_info.c index 879941f..d72e860 100644 --- a/mfapi/apicalls/folder_get_info.c +++ b/mfapi/apicalls/folder_get_info.c @@ -18,19 +18,15 @@ */ +#include #include #include -#include -#include -#include - -#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); diff --git a/mfapi/apicalls/user_get_info.c b/mfapi/apicalls/user_get_info.c index 73b11f7..7e9d29a 100644 --- a/mfapi/apicalls/user_get_info.c +++ b/mfapi/apicalls/user_get_info.c @@ -18,18 +18,13 @@ */ -#include -#include -#include - -#include #include +#include -#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); diff --git a/mfapi/apicalls/user_session.c b/mfapi/apicalls/user_session.c index 4029293..1d0d65e 100644 --- a/mfapi/apicalls/user_session.c +++ b/mfapi/apicalls/user_session.c @@ -18,18 +18,17 @@ */ -#include -#include -#include - -#include #include +#include +#include +#include +#include -#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); diff --git a/mfapi/file.c b/mfapi/file.c index ad58def..55b139b 100644 --- a/mfapi/file.c +++ b/mfapi/file.c @@ -18,13 +18,19 @@ */ +#include +#include #include -#include +#include +#include #include +#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 -#include -#include -#include -#include - -#include -#include - -#include - -#include "mfconn.h" -#include "../utils/http.h" -#include "../utils/strings.h" - ssize_t file_download_direct(mffile *file, char *local_dir) { diff --git a/mfapi/file.h b/mfapi/file.h index 1129550..5e0da21 100644 --- a/mfapi/file.h +++ b/mfapi/file.h @@ -20,9 +20,9 @@ #ifndef __MFAPI_FILE_H__ #define __MFAPI_FILE_H__ -typedef struct _file_s mffile; +#include -struct _file_s; +typedef struct mffile mffile; mffile* file_alloc(void); diff --git a/mfapi/folder.c b/mfapi/folder.c index ce28cae..3db0a92 100644 --- a/mfapi/folder.c +++ b/mfapi/folder.c @@ -18,13 +18,13 @@ */ +#include #include -#include #include #include "folder.h" -struct _folder_s +struct mffolder { char folderkey[20]; char name[41]; diff --git a/mfapi/folder.h b/mfapi/folder.h index 8f43550..6e9f54a 100644 --- a/mfapi/folder.h +++ b/mfapi/folder.h @@ -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); diff --git a/mfapi/mfconn.c b/mfapi/mfconn.c index 0abbbb6..532030b 100644 --- a/mfapi/mfconn.c +++ b/mfapi/mfconn.c @@ -17,16 +17,16 @@ * */ -#include - -#include -#include -#include #include +#include +#include +#include +#include +#include #include "../utils/strings.h" -#include "mfconn.h" #include "apicalls.h" +#include "mfconn.h" struct mfconn { diff --git a/mfapi/mfconn.h b/mfapi/mfconn.h index e4212f3..fe9f900 100644 --- a/mfapi/mfconn.h +++ b/mfapi/mfconn.h @@ -20,6 +20,7 @@ #define __MFAPI_MFCONN_H__ #include +#include #include "file.h" diff --git a/mfshell/commands/auth.c b/mfshell/commands/auth.c index c6ea1fe..3d39145 100644 --- a/mfshell/commands/auth.c +++ b/mfshell/commands/auth.c @@ -18,14 +18,16 @@ */ +#include #include #include #include -#include #include +#include #include "../mfshell.h" -#include "../commands.h" +#include "../../mfapi/mfconn.h" +#include "../commands.h" // IWYU pragma: keep static char* _get_login_from_user(void); diff --git a/mfshell/commands/chdir.c b/mfshell/commands/chdir.c index 01d54d5..a9b1056 100644 --- a/mfshell/commands/chdir.c +++ b/mfshell/commands/chdir.c @@ -20,11 +20,12 @@ #include #include -#include -#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) diff --git a/mfshell/commands/debug.c b/mfshell/commands/debug.c index c8d76f8..6ca4015 100644 --- a/mfshell/commands/debug.c +++ b/mfshell/commands/debug.c @@ -18,14 +18,13 @@ */ -#include -#include -#include - #include +#include +#include #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) diff --git a/mfshell/commands/file.c b/mfshell/commands/file.c index 57eedb2..2d21828 100644 --- a/mfshell/commands/file.c +++ b/mfshell/commands/file.c @@ -21,9 +21,11 @@ #include #include -#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) diff --git a/mfshell/commands/get.c b/mfshell/commands/get.c index bb6fb68..d563084 100644 --- a/mfshell/commands/get.c +++ b/mfshell/commands/get.c @@ -18,15 +18,17 @@ */ +#include #include +#include #include #include -#include -#include -#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) diff --git a/mfshell/commands/help.c b/mfshell/commands/help.c index 66a26ad..0347399 100644 --- a/mfshell/commands/help.c +++ b/mfshell/commands/help.c @@ -20,10 +20,9 @@ #include #include -#include #include "../mfshell.h" -#include "../commands.h" +#include "../commands.h" // IWYU pragma: keep int mfshell_cmd_help(mfshell *mfshell, int argc, char **argv) diff --git a/mfshell/commands/host.c b/mfshell/commands/host.c index 8200089..f87fbe4 100644 --- a/mfshell/commands/host.c +++ b/mfshell/commands/host.c @@ -18,12 +18,14 @@ */ +#include #include #include #include #include "../mfshell.h" -#include "../commands.h" +#include "../../mfapi/mfconn.h" +#include "../commands.h" // IWYU pragma: keep static char* _get_host_from_user(void); diff --git a/mfshell/commands/lcd.c b/mfshell/commands/lcd.c index cbfa4e9..76425a3 100644 --- a/mfshell/commands/lcd.c +++ b/mfshell/commands/lcd.c @@ -20,11 +20,11 @@ #include #include -#include #include +#include #include "../mfshell.h" -#include "../commands.h" +#include "../commands.h" // IWYU pragma: keep int mfshell_cmd_lcd(mfshell *mfshell, int argc, char **argv) diff --git a/mfshell/commands/links.c b/mfshell/commands/links.c index 94f9578..1b9ad8c 100644 --- a/mfshell/commands/links.c +++ b/mfshell/commands/links.c @@ -21,9 +21,11 @@ #include #include -#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) diff --git a/mfshell/commands/list.c b/mfshell/commands/list.c index d0af226..10e5ea0 100644 --- a/mfshell/commands/list.c +++ b/mfshell/commands/list.c @@ -19,12 +19,12 @@ #include -#include -#include -#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) diff --git a/mfshell/commands/lpwd.c b/mfshell/commands/lpwd.c index e00dbd6..8591e64 100644 --- a/mfshell/commands/lpwd.c +++ b/mfshell/commands/lpwd.c @@ -18,13 +18,13 @@ */ +#include #include #include #include -#include #include "../mfshell.h" -#include "../commands.h" +#include "../commands.h" // IWYU pragma: keep int mfshell_cmd_lpwd(mfshell *mfshell, int argc, char **argv) diff --git a/mfshell/commands/mkdir.c b/mfshell/commands/mkdir.c index 488c539..37243a3 100644 --- a/mfshell/commands/mkdir.c +++ b/mfshell/commands/mkdir.c @@ -19,12 +19,12 @@ #include -#include -#include -#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) diff --git a/mfshell/commands/pwd.c b/mfshell/commands/pwd.c index 71ff920..69d69bb 100644 --- a/mfshell/commands/pwd.c +++ b/mfshell/commands/pwd.c @@ -19,12 +19,12 @@ #include -#include #include -#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) diff --git a/mfshell/commands/whoami.c b/mfshell/commands/whoami.c index ee2f9a3..d8ff89a 100644 --- a/mfshell/commands/whoami.c +++ b/mfshell/commands/whoami.c @@ -19,12 +19,11 @@ #include -#include -#include -#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) diff --git a/mfshell/main.c b/mfshell/main.c index f338cb4..05a0f1b 100644 --- a/mfshell/main.c +++ b/mfshell/main.c @@ -17,17 +17,15 @@ * */ +#include +#include +#include #include #include -#include -#include -#include +#include #include -#include - #include "mfshell.h" -#include "../utils/strings.h" static void mfshell_run(mfshell *mfshell); diff --git a/mfshell/mfshell.c b/mfshell/mfshell.c index 44f97be..1cb763b 100644 --- a/mfshell/mfshell.c +++ b/mfshell/mfshell.c @@ -19,23 +19,13 @@ #include -#include -#include #include -#include -#include +#include #include -#include - -#include "mfshell.h" -#include "../utils/stringv.h" - - -#include - -#include "mfshell.h" #include "commands.h" +#include "mfshell.h" +#include "../mfapi/folder.h" struct mfcmd commands[] = { {"help", "", "show this help", mfshell_cmd_help}, diff --git a/mfshell/mfshell.h b/mfshell/mfshell.h index b51613d..9ddabcb 100644 --- a/mfshell/mfshell.h +++ b/mfshell/mfshell.h @@ -24,6 +24,9 @@ #include "../mfapi/folder.h" #include "../mfapi/mfconn.h" +struct mfcmd; +struct mfshell; + typedef struct mfcmd mfcmd; typedef struct mfshell mfshell; diff --git a/tests/iwyu.py b/tests/iwyu.py new file mode 100755 index 0000000..e25398e --- /dev/null +++ b/tests/iwyu.py @@ -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) diff --git a/utils/http.h b/utils/http.h index 10ce516..8072ea7 100644 --- a/utils/http.h +++ b/utils/http.h @@ -20,6 +20,8 @@ #define _MFSHELL_HTTP_H_ #include +#include +#include typedef struct mfhttp mfhttp; diff --git a/utils/json.c b/utils/json.c index 1808d95..3ca753f 100644 --- a/utils/json.c +++ b/utils/json.c @@ -18,7 +18,6 @@ #include -#include #include "json.h" #include "stringv.h" diff --git a/utils/strings.c b/utils/strings.c index 7e965c3..703ac0f 100644 --- a/utils/strings.c +++ b/utils/strings.c @@ -17,11 +17,12 @@ */ -#include -#include -#include -#include #include +#include +#include +#include +#include +#include #include "strings.h" #include "stringv.h" diff --git a/utils/strings.h b/utils/strings.h index 850f8d8..2b36d3e 100644 --- a/utils/strings.h +++ b/utils/strings.h @@ -20,8 +20,6 @@ #ifndef _STR_TOOLS_H_ #define _STR_TOOLS_H_ -#include - char* strdup_printf(char* fmt, ...); char* strdup_join(char *string1,char *string2); diff --git a/utils/stringv.c b/utils/stringv.c index bd8ec84..6941abe 100644 --- a/utils/stringv.c +++ b/utils/stringv.c @@ -17,9 +17,8 @@ */ +#include #include -#include -#include #include #include "stringv.h" diff --git a/utils/stringv.h b/utils/stringv.h index 0dbc530..f8c94e6 100644 --- a/utils/stringv.h +++ b/utils/stringv.h @@ -20,7 +20,7 @@ #ifndef _STRING_V_H_ #define _STRING_V_H_ -#include +#include #define STRINGV_FREE_ALL 1