From 783979111f0a55ec50d261d2d4d7de2e56eee2ef Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Tue, 5 May 2020 14:15:24 +0200 Subject: [PATCH 1/6] Adding units tests, functional tests and build CI --- .github/workflows/build.yml | 18 ++++++++++++++++++ .github/workflows/functional.yml | 16 ++++++++++++++++ .github/workflows/tests.yml | 30 ++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/functional.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5244628 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,18 @@ +name: Check if the app builds + +on: + push: + branches: + - master + pull_requests: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Build with Makefile + run: make fclean && make clean && make re && make \ No newline at end of file diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml new file mode 100644 index 0000000..8eef577 --- /dev/null +++ b/.github/workflows/functional.yml @@ -0,0 +1,16 @@ +name: Run functional tests + +on: + push: + pull_requests: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Build with Makefile & Execute tests + run: make func \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..822e05d --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,30 @@ +name: Run unit tests + +on: + push: + pull_requests: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Set up Python + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install Criterion + run: sudo add-apt-repository ppa:snaipewastaken/ppa && + sudo apt-get update && + sudo apt-get install --yes criterion-dev + - name: Install Gcovr + run: python -m pip install --upgrade pip gcovr + - name: Build with Makefile + run: make unit_tests + - name: Execute tests + run: ./unit_tests + - name: Output coverage + run: gcovr -e tests/ \ No newline at end of file From 9b4f2e77930831c0f1e66b736fe6014a9ba92928 Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Tue, 5 May 2020 14:18:13 +0200 Subject: [PATCH 2/6] Oups --- .github/workflows/build.yml | 2 +- .github/workflows/functional.yml | 2 +- .github/workflows/tests.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5244628..8024c03 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,7 @@ on: push: branches: - master - pull_requests: + pull_request: branches: - master diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 8eef577..e1e59ee 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -2,7 +2,7 @@ name: Run functional tests on: push: - pull_requests: + pull_request: branches: - master diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 822e05d..bc732ff 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,7 +2,7 @@ name: Run unit tests on: push: - pull_requests: + pull_request: branches: - master From d3fbbd149a13ee4aed9deabc7b3f41cbde15d841 Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Tue, 5 May 2020 14:19:53 +0200 Subject: [PATCH 3/6] Preventing the CI to be run twice on PR --- .github/workflows/build.yml | 8 +------- .github/workflows/functional.yml | 6 +----- .github/workflows/tests.yml | 6 +----- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8024c03..36ed08e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,12 +1,6 @@ name: Check if the app builds -on: - push: - branches: - - master - pull_request: - branches: - - master +on: [push] jobs: build: diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index e1e59ee..3e690e7 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -1,10 +1,6 @@ name: Run functional tests -on: - push: - pull_request: - branches: - - master +on: [push] jobs: build: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bc732ff..84134be 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,10 +1,6 @@ name: Run unit tests -on: - push: - pull_request: - branches: - - master +on: [push] jobs: build: From 0b8b8511ef80870df5b727bfd8503614f1f26b95 Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Tue, 5 May 2020 14:22:24 +0200 Subject: [PATCH 4/6] Fixing the CI for UT and the makefile for functional tests --- .github/workflows/tests.yml | 2 +- Makefile | 4 ++-- tests/tester/tester.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 84134be..5f861c4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,7 +19,7 @@ jobs: - name: Install Gcovr run: python -m pip install --upgrade pip gcovr - name: Build with Makefile - run: make unit_tests + run: make tests_run - name: Execute tests run: ./unit_tests - name: Output coverage diff --git a/Makefile b/Makefile index 13d2849..52b6810 100644 --- a/Makefile +++ b/Makefile @@ -61,8 +61,8 @@ tests_run: clean $(UT) func: all - cd tests/tester/ && cp ../../mysh mysh && ./tester.sh - rm tests/tester/mysh + cd tests/tester/ && cp ../../$(NAME) $(NAME) && ./tester.sh + rm tests/tester/$(NAME) clean: $(RM) $(OBJ) diff --git a/tests/tester/tester.sh b/tests/tester/tester.sh index 1b3e9b0..f721879 100755 --- a/tests/tester/tester.sh +++ b/tests/tester/tester.sh @@ -1,6 +1,6 @@ #!/bin/bash -MYSHELL="$PWD/mysh" +MYSHELL="$PWD/42sh" REFER="/bin/tcsh -f" TRAPSIG=0 From df5d54901ef80b66b84650bd35b2831c2991448f Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Tue, 5 May 2020 14:26:28 +0200 Subject: [PATCH 5/6] Solving ut --- Makefile | 1 + src/main.c | 7 ------- src/utility/get_return.c | 15 +++++++++++++++ 3 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 src/utility/get_return.c diff --git a/Makefile b/Makefile index 52b6810..d05eeeb 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ SRC = src/shell.c \ src/utility/split_str.c \ src/utility/fusion.c \ src/utility/split_commands.c \ + src/utility/get_return.c OBJ = $(SRC:%.c=%.o) OBJ += src/main.o diff --git a/src/main.c b/src/main.c index 3f7131e..6e98fc0 100644 --- a/src/main.c +++ b/src/main.c @@ -11,13 +11,6 @@ #include #include -int get_return(char *ret) -{ - if (!ret) - return (0); - return (atoi(ret)); -} - int main(int argc, char **argv, char **env) { env_t *envt = malloc(sizeof(*envt)); diff --git a/src/utility/get_return.c b/src/utility/get_return.c new file mode 100644 index 0000000..f18c07f --- /dev/null +++ b/src/utility/get_return.c @@ -0,0 +1,15 @@ +/* +** EPITECH PROJECT, 2020 +** ash +** File description: +** get_return +*/ + +#include + +int get_return(char *ret) +{ + if (!ret) + return (0); + return (atoi(ret)); +} \ No newline at end of file From 85f04bb154f015d7d0cd23cdb7623c90cba75990 Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Tue, 5 May 2020 14:31:05 +0200 Subject: [PATCH 6/6] Disabling a test that won't ever work on github --- tests/texecute.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/tests/texecute.c b/tests/texecute.c index 032450b..8233d55 100644 --- a/tests/texecute.c +++ b/tests/texecute.c @@ -13,7 +13,7 @@ void eval(char *cmd, char **argv, env_t* env); extern char **environ; -Test(execute, get_path) +Test(execute, get_path, .init = cr_redirect_stdout) { env_t *env = malloc(sizeof(env_t)); env->vars = NULL; @@ -24,16 +24,17 @@ Test(execute, get_path) cr_assert_fail(); } -Test(execute, absolute) -{ - env_t *env = malloc(sizeof(env_t)); - env->vars = NULL; - env->env = environ; - char **argv = get_argv("/usr/bin/ls"); +// Disabled since github does not have ls in the /usr/bin/ls path. +// Test(execute, absolute, .init = cr_redirect_stdout) +// { +// env_t *env = malloc(sizeof(env_t)); +// env->vars = NULL; +// env->env = environ; +// char **argv = get_argv("/usr/bin/ls"); - eval(argv[0], argv, env); - cr_assert_fail(); -} +// eval(argv[0], argv, env); +// cr_assert_fail(); +// } Test(execute, notfound, .init = cr_redirect_stderr) {