diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-01-16 18:51:11 +0100 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-01-16 18:52:57 +0100 |
| commit | 2e5ca2ab6276b7b24895ade28e1533356ef523dc (patch) | |
| tree | f7afcc1bf3fa0a1c91303b9440305cfff9a9eec8 | |
| parent | 14430cdd03dd2487c086e53ffcf0222ed3ffc126 (diff) | |
| download | libft-2e5ca2ab6276b7b24895ade28e1533356ef523dc.tar.gz libft-2e5ca2ab6276b7b24895ade28e1533356ef523dc.tar.bz2 libft-2e5ca2ab6276b7b24895ade28e1533356ef523dc.zip | |
Testing config with travis
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | .travis.yml | 2 | ||||
| -rw-r--r-- | Makefile | 19 | ||||
| -rw-r--r-- | README.md | 31 | ||||
| -rw-r--r-- | libft.conf | 6 | ||||
| -rw-r--r-- | test/Makefile | 52 | ||||
| m--------- | test/ctest | 0 | ||||
| -rw-r--r-- | test/main_test.c | 7 | ||||
| -rw-r--r-- | test/str/ft_strlen_test.c | 23 | ||||
| -rw-r--r-- | test/test_libft.h | 8 |
11 files changed, 135 insertions, 17 deletions
@@ -3,5 +3,6 @@ *.a *.ghc a.out +test_libft main.c build/* diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b2fc13a --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test/ctest"] + path = test/ctest + url = https://github.com/HappyTramp/ctest diff --git a/.travis.yml b/.travis.yml index 31b76a3..07ce8a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ language: c compiler: gcc -script: make +script: make && make test @@ -12,25 +12,26 @@ LIB = ar rcs RM = rm -f +MAKE_ARGS = --no-print-directory CC = gcc CCFLAGS = -I$(INCLUDE_DIR) -Wall -Wextra -Werror NAME = libft.a +SRC_DIR = src +INCLUDE_DIR = include +BUILD_DIR = build +TEST_DIR = test # AVAILABLE_FEATURES = get_next_line ft_printf ft_lst CONF_FILE = libft.conf +# ifndef (FEATURES) +# endif ifeq ($(wildcard $(CONF_FILE)),) $(warning "No configuration file found with name $(CONF_FILE), using default") - SRC_DIR = src - BUILD_DIR = build - INCLUDE_DIR = include FEATURES = get_next_line else - SRC_DIR = $(shell sed -n 's/SRC_DIR=//p' $(CONF_FILE)) - BUILD_DIR = $(shell sed -n 's/BUILD_DIR=//p' $(CONF_FILE)) - INCLUDE_DIR = $(shell sed -n 's/INCLUDE_DIR=//p' $(CONF_FILE)) FEATURES = $(shell sed -n 's/FEATURES=//p' $(CONF_FILE)) endif @@ -45,7 +46,6 @@ ifeq ($(findstring ft_lst,$(FEATURES)),) endif SRC = $(shell find $(SRC_DIR) $(FIND_ARGS) -name *.c) - OBJ = $(SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o) HEADER_FILES = libft.h get_next_line.h @@ -53,6 +53,10 @@ HEADER = $(addprefix $(INCLUDE_DIR)/,$(HEADER_FILES)) all: make_build_dirs $(NAME) +.PHONY: test +test: + @$(MAKE) $(MAKE_ARGS) -C $(TEST_DIR) run_raw + make_build_dirs: @for dir in $$(find $(SRC_DIR)/* $(FIND_ARGS) -type d | \ sed 's_$(SRC_DIR)/_$(BUILD_DIR)/_g'); \ @@ -73,7 +77,6 @@ clean: @echo "Removing objects" @$(RM) -r $(BUILD_DIR) - fclean: clean @echo "Removing library" @$(RM) $(NAME) @@ -1,7 +1,32 @@ # libft [](https://travis-ci.com/HappyTramp/libft) -The state of this repo when I pass can be checked with the [raw](http://github.com/HappyTramp/libft/tree/raw) tag. +libft is an extension/remake of the standard library. -I have both the pre 2019 and current functions. There is also my [get\_nex\_line](http://github.com/HappyTramp/get_next_line) and [ft\_printf](http://github.com/HappyTramp/ft_printf) in the mix. +## Getting Started -The [rendu](http://github.com/HappyTramp/libft/tree/rendu) branch is the one I use for my other projects, it doesnt contain .gitignore, README.md and subjects. +``` +git clone https://github.com/HappyTramp/libft libft +cd libft +make all +``` + +This will produce a `libft.a` library which you can link to your project. + +## Testing + +To install the test, you will have to clone this repo with the `--recurse-submodules` flag or run the following commands: + +``` +git submodule init +git submodule update +``` + +Then: `make test` + +## Dependencies + +* [CTest](https://github.com/HappyTramp/ctest) - my testing library + +### School turn in + +The state of this project when I turned it in for correction is [here](http://github.com/HappyTramp/libft/tree/raw). @@ -1,11 +1,7 @@ # Making -SRC_DIR=src -INCLUDE_DIR=include -BUILD_DIR=build FEATURES=get_next_line ft_lst - # Repository -RENDU_IGNORE=subject.pdf README.md scripts build libft.conf +RENDU_IGNORE=subject.pdf README.md scripts build test libft.conf diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 0000000..3f31059 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,52 @@ +MAKE_ARGS = --no-print-directory + +NAME = test_libft + +BUILD_DIR = build +LIBFT_DIR = .. +CTEST_DIR = ctest + +CC = gcc +CCFLAGS = -Wall -Wextra -I$(LIBFT_DIR)/include -I$(CTEST_DIR) +LDFLAGS = -L$(LIBFT_DIR) -lft + +HEADER = $(shell find . -name "*.h") +SRC = $(shell find . -name "*_test.c") +SRC += $(shell find $(CTEST_DIR) -name "*.c") +OBJ = $(SRC:%.c=$(BUILD_DIR)/%.o) + +all: make_build_dirs $(NAME) + +run_raw: all + @./$(NAME) + +make_build_dirs: + @for dir in $$(find . -not -path "*build*" -type d | sed 's/.*/$(BUILD_DIR)\/&/'); \ + do \ + if [ ! -d "$$dir" ]; then \ + mkdir -p $$dir; echo "Making build dir: $$dir"; fi \ + done + +$(NAME): $(OBJ) libft_all + @echo "Test: Linking $@" + @$(CC) -o $@ $(OBJ) $(LDFLAGS) + +$(BUILD_DIR)/%.o: %.c $(HEADER) + @echo "Test: Compiling: $@" + @$(CC) $(CCFLAGS) -c -o $@ $< + +clean: + @echo "Test: Removing objects" + @$(RM) -r $(BUILD_DIR) + +fclean: clean + @echo "Test: Removing library" + @$(RM) $(NAME) + @echo "Test: Removing libft" + @$(MAKE) $(MAKE_ARGS) -C $(LIBFT_DIR) fclean + +re: fclean all + +libft_all: + @echo "Test: Making libft" + @$(MAKE) $(MAKE_ARGS) -C $(LIBFT_DIR) all diff --git a/test/ctest b/test/ctest new file mode 160000 +Subproject 61963f169ff5ae4dc18c5e6e1c7c6972745d6cf diff --git a/test/main_test.c b/test/main_test.c new file mode 100644 index 0000000..6b74ac4 --- /dev/null +++ b/test/main_test.c @@ -0,0 +1,7 @@ +#include "test_libft.h" + +int main(void) +{ + TEST_CALL(ft_strlen); + return 0; +} diff --git a/test/str/ft_strlen_test.c b/test/str/ft_strlen_test.c new file mode 100644 index 0000000..57ccee4 --- /dev/null +++ b/test/str/ft_strlen_test.c @@ -0,0 +1,23 @@ +#include <string.h> +#include "libft.h" +#include "ctest.h" + +TEST_SEGV_FUNC(ft_strlen, char *str) +{ + ft_strlen(str); +} +TEST_SEGV_FUNC_END + +ASSERT_FUNC1(ft_strlen, char*, str) +{ + return ft_strlen(str) == strlen(str); +} +ASSERT_FUNC1_END + + +TEST(ft_strlen) +{ + ASSERT(ft_strlen, "bonjour"); + ASSERT(ft_strlen, "yo"); + ASSERT(ft_strlen, "slt"); +} diff --git a/test/test_libft.h b/test/test_libft.h new file mode 100644 index 0000000..f4d489f --- /dev/null +++ b/test/test_libft.h @@ -0,0 +1,8 @@ +#ifndef TEST_LIBFT_H +# define TEST_LIBFT_H + +# include "ctest.h" + +TEST(ft_strlen); + +#endif |
