Skip to content

Commit

Permalink
Format test files with clang-format (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenmathieson committed Sep 8, 2020
1 parent 34f9066 commit efe4713
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 200 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MKDIR = mkdir -p

SRC = $(wildcard src/*.c)
COMMON_SRC = $(wildcard src/common/*.c)
ALL_SRC = $(wildcard src/*.c src/*.h src/common/*.c src/common/*.h)
ALL_SRC = $(wildcard src/*.c src/*.h src/common/*.c src/common/*.h test/package/*.c test/cache/*.c)
SDEPS = $(wildcard deps/*/*.c)
ODEPS = $(SDEPS:.c=.o)
DEPS = $(filter-out $(ODEPS), $(SDEPS))
Expand Down
52 changes: 23 additions & 29 deletions test/cache/cache-test.c
Original file line number Diff line number Diff line change
@@ -1,56 +1,48 @@
#include <stdlib.h>
#include "../../src/common/clib-cache.h"
#include "fs/fs.h"
#include "rimraf/rimraf.h"
#include <describe/describe.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <describe/describe.h>
#include "rimraf/rimraf.h"
#include "fs/fs.h"
#include "../../src/common/clib-cache.h"


#define assert_exists(f) assert_equal(0, fs_exists(f));

static void assert_cached_dir(char *pkg_dir, int exists)
{
assert_equal(exists, fs_exists(pkg_dir));
static void assert_cached_dir(char *pkg_dir, int exists) {
assert_equal(exists, fs_exists(pkg_dir));
}

static void assert_cached_file(char *pkg_dir, char *file)
{
char path[BUFSIZ];
sprintf(path, "%s/%s", pkg_dir, file);
static void assert_cached_file(char *pkg_dir, char *file) {
char path[BUFSIZ];
sprintf(path, "%s/%s", pkg_dir, file);

assert_exists(path);
assert_exists(path);
}

static void assert_cached_files(char *pkg_dir)
{
assert_cached_file(pkg_dir, "copy.c");
assert_cached_file(pkg_dir, "copy.h");
assert_cached_file(pkg_dir, "package.json");
static void assert_cached_files(char *pkg_dir) {
assert_cached_file(pkg_dir, "copy.c");
assert_cached_file(pkg_dir, "copy.h");
assert_cached_file(pkg_dir, "package.json");
}

int
main() {
int main() {

rimraf(clib_cache_dir());

describe("clib-cache opearions") {


char *author = "author";
char *name = "pkg";
char *version = "1.2.0";
char pkg_dir[BUFSIZ];


it("should initialize succesfully") {
assert_equal(0, clib_cache_init(1));
}
it("should initialize succesfully") { assert_equal(0, clib_cache_init(1)); }

sprintf(pkg_dir, "%s/author_pkg_1.2.0", clib_cache_dir());

it("should manage package the cache") {
assert_equal(0, clib_cache_save_package(author, name, version, "../../deps/copy"));
assert_equal(
0, clib_cache_save_package(author, name, version, "../../deps/copy"));
assert_equal(1, clib_cache_has_package(author, name, version));
assert_equal(0, clib_cache_is_expired_package(author, name, version));

Expand All @@ -65,7 +57,8 @@ main() {
assert_null(clib_cache_read_json("a", "n", "v"));

assert_equal(2, clib_cache_save_json("a", "n", "v", "{}"));
assert_equal(0, strcmp("{}", cached_json = clib_cache_read_json("a", "n", "v")));
assert_equal(
0, strcmp("{}", cached_json = clib_cache_read_json("a", "n", "v")));
free(cached_json);
assert_equal(1, clib_cache_has_json("a", "n", "v"));

Expand All @@ -84,7 +77,8 @@ main() {

assert_equal(13, clib_cache_save_search("<html></html>"));
assert_equal(1, clib_cache_has_search());
assert_equal(0, strcmp("<html></html>", cached_search = clib_cache_read_search()));
assert_equal(
0, strcmp("<html></html>", cached_search = clib_cache_read_search()));
free(cached_search);

assert_equal(0, clib_cache_delete_search());
Expand Down
14 changes: 8 additions & 6 deletions test/package/package-dependency-new.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

#include "describe/describe.h"
#include "clib-package.h"
#include "describe/describe.h"

int
main() {
int main() {
curl_global_init(CURL_GLOBAL_ALL);

describe("clib_package_dependency_new") {
Expand All @@ -13,7 +12,8 @@ main() {
}

it("should return a clib-dependency when given valid input") {
clib_package_dependency_t *dep = clib_package_dependency_new("foo/bar", "1.2.3");
clib_package_dependency_t *dep =
clib_package_dependency_new("foo/bar", "1.2.3");
assert(dep);
assert_str_equal("foo", dep->author);
assert_str_equal("bar", dep->name);
Expand All @@ -22,14 +22,16 @@ main() {
}

it("should transform \"*\" to \"master\"") {
clib_package_dependency_t *dep = clib_package_dependency_new("foo/bar", "*");
clib_package_dependency_t *dep =
clib_package_dependency_new("foo/bar", "*");
assert(dep);
assert_str_equal("master", dep->version);
clib_package_dependency_free(dep);
}

it("should default to \"clibs\" when no repo author is given") {
clib_package_dependency_t *dep = clib_package_dependency_new("foo", "master");
clib_package_dependency_t *dep =
clib_package_dependency_new("foo", "master");
assert(dep);
assert_str_equal("clibs", dep->author);
assert_str_equal("master", dep->version);
Expand Down
60 changes: 34 additions & 26 deletions test/package/package-install-dependencies.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

#include "clib-package.h"
#include "describe/describe.h"
#include "rimraf/rimraf.h"
#include "fs/fs.h"
#include "clib-package.h"
#include "rimraf/rimraf.h"

int
main() {
int main() {
curl_global_init(CURL_GLOBAL_ALL);
clib_package_set_opts((clib_package_opts_t) {
.skip_cache = 1,
.prefix = 0,
.force = 1,
clib_package_set_opts((clib_package_opts_t){
.skip_cache = 1,
.prefix = 0,
.force = 1,
});

describe("clib_package_install_dependencies") {
Expand All @@ -19,38 +18,46 @@ main() {
}

it("should install the dep in its own directory") {
clib_package_t *dep = clib_package_new_from_slug("stephenmathieson/mkdirp.c", 0);
clib_package_t *dep =
clib_package_new_from_slug("stephenmathieson/mkdirp.c", 0);
assert(dep);
assert(0 == clib_package_install_dependencies(dep, "./test/fixtures/", 0));
assert(0 ==
clib_package_install_dependencies(dep, "./test/fixtures/", 0));
assert(0 == fs_exists("./test/fixtures/"));
assert(0 == fs_exists("./test/fixtures/path-normalize"));
clib_package_free(dep);
rimraf("./test/fixtures/");
}

it("should install the dependency's package.json") {
clib_package_t *pkg = clib_package_new_from_slug("stephenmathieson/mkdirp.c", 0);
clib_package_t *pkg =
clib_package_new_from_slug("stephenmathieson/mkdirp.c", 0);
assert(pkg);
assert(0 == clib_package_install_dependencies(pkg, "./test/fixtures/", 0));
assert(0 ==
clib_package_install_dependencies(pkg, "./test/fixtures/", 0));
assert(0 == fs_exists("./test/fixtures/path-normalize/package.json"));
clib_package_free(pkg);
rimraf("./test/fixtures/");
}

it("should install the dependency's sources") {
clib_package_t *pkg = clib_package_new_from_slug("stephenmathieson/mkdirp.c", 0);
clib_package_t *pkg =
clib_package_new_from_slug("stephenmathieson/mkdirp.c", 0);
assert(pkg);
assert(0 == clib_package_install_dependencies(pkg, "./test/fixtures/", 0));
assert(0 ==
clib_package_install_dependencies(pkg, "./test/fixtures/", 0));
assert(0 == fs_exists("./test/fixtures/path-normalize/path-normalize.c"));
assert(0 == fs_exists("./test/fixtures/path-normalize/path-normalize.h"));
clib_package_free(pkg);
rimraf("./test/fixtures");
}

it("should install the dependency's dependencies") {
clib_package_t *pkg = clib_package_new_from_slug("stephenmathieson/rimraf.c", 0);
clib_package_t *pkg =
clib_package_new_from_slug("stephenmathieson/rimraf.c", 0);
assert(pkg);
assert(0 == clib_package_install_dependencies(pkg, "./test/fixtures/", 0));
assert(0 ==
clib_package_install_dependencies(pkg, "./test/fixtures/", 0));
// deps
assert(0 == fs_exists("./test/fixtures/path-join/"));
assert(0 == fs_exists("./test/fixtures/path-join/package.json"));
Expand All @@ -63,21 +70,22 @@ main() {
assert(0 == fs_exists("./test/fixtures/str-ends-with/str-ends-with.c"));
assert(0 == fs_exists("./test/fixtures/str-starts-with/"));
assert(0 == fs_exists("./test/fixtures/str-starts-with/package.json"));
assert(0 == fs_exists("./test/fixtures/str-starts-with/str-starts-with.h"));
assert(0 == fs_exists("./test/fixtures/str-starts-with/str-starts-with.c"));
assert(0 ==
fs_exists("./test/fixtures/str-starts-with/str-starts-with.h"));
assert(0 ==
fs_exists("./test/fixtures/str-starts-with/str-starts-with.c"));
clib_package_free(pkg);
rimraf("./test/fixtures");
}

it("should handle unresolved packages") {
char json[] =
"{"
" \"dependencies\": {"
" \"linenoise\": \"*\","
" \"stephenmathieson/substr.c\": \"*\","
" \"stephenmathieson/emtter.c\": \"*\""
" }"
"}";
char json[] = "{"
" \"dependencies\": {"
" \"linenoise\": \"*\","
" \"stephenmathieson/substr.c\": \"*\","
" \"stephenmathieson/emtter.c\": \"*\""
" }"
"}";

clib_package_t *pkg = clib_package_new(json, 0);
assert(pkg);
Expand Down
26 changes: 13 additions & 13 deletions test/package/package-install-dev-dependencies.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

#include "clib-package.h"
#include "describe/describe.h"
#include "rimraf/rimraf.h"
#include "fs/fs.h"
#include "clib-package.h"
#include "rimraf/rimraf.h"

int
main() {
int main() {
curl_global_init(CURL_GLOBAL_ALL);
clib_package_set_opts((clib_package_opts_t) {
.skip_cache = 1,
.prefix = 0,
.force = 1,
clib_package_set_opts((clib_package_opts_t){
.skip_cache = 1,
.prefix = 0,
.force = 1,
});

describe("clib_package_install_development") {
Expand All @@ -19,22 +18,23 @@ main() {
}

it("should return -1 when given a bad dir") {
clib_package_t *pkg = clib_package_new_from_slug("stephenmathieson/mkdirp.c", 0);
clib_package_t *pkg =
clib_package_new_from_slug("stephenmathieson/mkdirp.c", 0);
assert(pkg);
assert(-1 == clib_package_install_development(pkg, NULL, 0));
clib_package_free(pkg);
}

it("should install the package's development dependencies") {
clib_package_t *pkg = clib_package_new_from_slug("stephenmathieson/[email protected]", 0);
clib_package_t *pkg =
clib_package_new_from_slug("stephenmathieson/[email protected]", 0);
assert(pkg);
assert(0 == clib_package_install_development(pkg, "./test/fixtures", 0));
assert(0 == fs_exists("./test/fixtures/describe"));
assert(0 == fs_exists("./test/fixtures/describe/describe.h"));
assert(0 == fs_exists("./test/fixtures/describe/package.json"));
assert(0 == fs_exists(
"./test/fixtures/assertion-macros/assertion-macros.h"
));
assert(0 ==
fs_exists("./test/fixtures/assertion-macros/assertion-macros.h"));
assert(0 == fs_exists("./test/fixtures/assertion-macros/package.json"));
rimraf("./test/fixtures");
clib_package_free(pkg);
Expand Down
Loading

0 comments on commit efe4713

Please sign in to comment.