aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-16 18:51:11 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-16 18:52:57 +0100
commit2e5ca2ab6276b7b24895ade28e1533356ef523dc (patch)
treef7afcc1bf3fa0a1c91303b9440305cfff9a9eec8
parent14430cdd03dd2487c086e53ffcf0222ed3ffc126 (diff)
downloadlibft-2e5ca2ab6276b7b24895ade28e1533356ef523dc.tar.gz
libft-2e5ca2ab6276b7b24895ade28e1533356ef523dc.tar.bz2
libft-2e5ca2ab6276b7b24895ade28e1533356ef523dc.zip
Testing config with travis
-rw-r--r--.gitignore1
-rw-r--r--.gitmodules3
-rw-r--r--.travis.yml2
-rw-r--r--Makefile19
-rw-r--r--README.md31
-rw-r--r--libft.conf6
-rw-r--r--test/Makefile52
m---------test/ctest0
-rw-r--r--test/main_test.c7
-rw-r--r--test/str/ft_strlen_test.c23
-rw-r--r--test/test_libft.h8
11 files changed, 135 insertions, 17 deletions
diff --git a/.gitignore b/.gitignore
index f84848e..c58fcb1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/Makefile b/Makefile
index a73327b..76765dc 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
diff --git a/README.md b/README.md
index 4c74c94..632fa8b 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,32 @@
# libft [![Build Status](https://api.travis-ci.com/HappyTramp/libft.svg?branch=master)](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).
diff --git a/libft.conf b/libft.conf
index a9f3ea7..47f2a55 100644
--- a/libft.conf
+++ b/libft.conf
@@ -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