mirror of
https://gitlab.com/klmp200/fish.git
synced 2024-12-22 15:51:09 +00:00
Début de l'intégration des tests
This commit is contained in:
parent
9b6e5c7bc5
commit
209c36e7fd
@ -9,9 +9,9 @@ build:
|
||||
# instead of calling g++ directly you can also use some build toolkit like make
|
||||
# install the necessary build tools when needed
|
||||
before_script:
|
||||
- apt update && apt -y install make autoconf cmake
|
||||
- apt update && apt -y install make cmake python
|
||||
script:
|
||||
- mkdir build && cd build && cmake .. && make
|
||||
- mkdir build && cd build && cmake .. && make && make test
|
||||
#artifacts:
|
||||
# paths:
|
||||
# - mybinary
|
||||
|
@ -1,9 +1,52 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(fish)
|
||||
project(fish_shell)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -fpic -Wextra")
|
||||
# We need thread support
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
set(SOURCE_FILES main.c fish_shell/fish_core.c fish_shell/fish_core.h fish_shell/fish_commands.c fish_shell/fish_commands.h fish_shell/fish_types.h fish_shell/fish_utils.c fish_shell/fish_utils.h fish_shell/fish_globbing.c fish_shell/fish_globbing.h)
|
||||
add_executable(fish ${SOURCE_FILES})
|
||||
# Enable ExternalProject CMake module
|
||||
include(ExternalProject)
|
||||
|
||||
# Download and install GoogleTest
|
||||
ExternalProject_Add(
|
||||
gtest
|
||||
URL https://github.com/google/googletest/archive/master.zip
|
||||
PREFIX ${CMAKE_CURRENT_BINARY_DIR}/gtest
|
||||
# Disable install step
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
|
||||
# Get GTest source and binary directories from CMake project
|
||||
ExternalProject_Get_Property(gtest source_dir binary_dir)
|
||||
|
||||
# Create a libgtest target to be used as a dependency by test programs
|
||||
add_library(libgtest IMPORTED STATIC GLOBAL)
|
||||
add_dependencies(libgtest gtest)
|
||||
|
||||
# Set libgtest properties
|
||||
set_target_properties(libgtest PROPERTIES
|
||||
"IMPORTED_LOCATION" "${binary_dir}/googlemock/gtest/libgtest.a"
|
||||
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}"
|
||||
)
|
||||
|
||||
# Create a libgmock target to be used as a dependency by test programs
|
||||
add_library(libgmock IMPORTED STATIC GLOBAL)
|
||||
add_dependencies(libgmock gtest)
|
||||
|
||||
# Set libgmock properties
|
||||
set_target_properties(libgmock PROPERTIES
|
||||
"IMPORTED_LOCATION" "${binary_dir}/googlemock/libgmock.a"
|
||||
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}"
|
||||
)
|
||||
|
||||
include_directories(
|
||||
"${source_dir}/googletest/include"
|
||||
"${source_dir}/googlemock/include"
|
||||
)
|
||||
|
||||
add_subdirectory(fish_shell)
|
||||
add_subdirectory(fish_shell_tests)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(fish_tests fish_shell_tests/fish_tests)
|
||||
|
8
fish_shell/CMakeLists.txt
Normal file
8
fish_shell/CMakeLists.txt
Normal file
@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(fish_shell)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -fpic -Wextra -Wshadow")
|
||||
|
||||
set(SOURCE_FILES main.c fish_core.c fish_core.h fish_commands.c fish_commands.h fish_types.h fish_utils.c fish_utils.h fish_globbing.c fish_globbing.h)
|
||||
add_executable(fish ${SOURCE_FILES})
|
@ -7,9 +7,9 @@
|
||||
|
||||
/* Necessary global variables */
|
||||
char * builtinCommandsStr[] = {
|
||||
"cd",
|
||||
"help",
|
||||
"exit"
|
||||
(char *) "cd",
|
||||
(char *) "help",
|
||||
(char *) "exit"
|
||||
};
|
||||
|
||||
|
||||
|
@ -23,7 +23,7 @@ void fishLoop(Settings * settings){
|
||||
printf("%s", settings->PS1);
|
||||
line = fishReadLine();
|
||||
|
||||
splited = split(line, FISH_TOKENS);
|
||||
splited = split(line, (char*) FISH_TOKENS);
|
||||
splited = fishExpand(splited);
|
||||
|
||||
array = wordListToWordArray(splited);
|
||||
@ -72,7 +72,7 @@ WordList * split(char *string, char *separator){
|
||||
char *fishReadLine() {
|
||||
size_t bufferSize = FISH_BUFFER_SIZE;
|
||||
int position = 0;
|
||||
char *line = malloc(sizeof(char*) * bufferSize);
|
||||
char *line = (char*) malloc(sizeof(char*) * bufferSize);
|
||||
int c;
|
||||
|
||||
if (line == NULL){
|
||||
@ -96,7 +96,7 @@ char *fishReadLine() {
|
||||
|
||||
if ((size_t) position > bufferSize){
|
||||
bufferSize+=bufferSize;
|
||||
line = realloc(line, bufferSize);
|
||||
line = (char*) realloc(line, bufferSize);
|
||||
if (line == NULL){
|
||||
crash();
|
||||
}
|
||||
|
@ -10,10 +10,10 @@
|
||||
|
||||
void crash(){
|
||||
char *crashErrors[] = {
|
||||
"fish: Fucking malloc always returning NULL pointer !",
|
||||
"fish: Error allocating fucking pointer !",
|
||||
"fish: C language exploding again",
|
||||
"fish: It's not you're fault for this time"
|
||||
(char *) "fish: Fucking malloc always returning NULL pointer !",
|
||||
(char *) "fish: Error allocating fucking pointer !",
|
||||
(char *) "fish: C language exploding again",
|
||||
(char *) "fish: It's not you're fault for this time"
|
||||
};
|
||||
int picked = 0;
|
||||
|
||||
@ -28,9 +28,9 @@ char *getInsult(){
|
||||
static int init = 0;
|
||||
int picked = 0;
|
||||
char *insults[] = {
|
||||
"Apprend à écrire crétin !",
|
||||
"Bolos !",
|
||||
"Mois aussi je sais écrire de la merde, pourtant je le fait pas !"
|
||||
(char *) "Apprend à écrire crétin !",
|
||||
(char *) "Bolos !",
|
||||
(char *) "Mois aussi je sais écrire de la merde, pourtant je le fait pas !"
|
||||
};
|
||||
if (!init){
|
||||
srand((unsigned int) time(NULL));
|
||||
@ -67,19 +67,19 @@ WordList *createWordList() {
|
||||
}
|
||||
|
||||
void addWordList(WordList *list, char *word) {
|
||||
WordListElement *new = (WordListElement*) malloc(sizeof(WordListElement));
|
||||
if (new == NULL) crash();
|
||||
WordListElement *newElement = (WordListElement*) malloc(sizeof(WordListElement));
|
||||
if (newElement == NULL) crash();
|
||||
else {
|
||||
new->next = NULL;
|
||||
new->previous = list->last;
|
||||
newElement->next = NULL;
|
||||
newElement->previous = list->last;
|
||||
if (list->size == 0){
|
||||
list->first = new;
|
||||
list->last = new;
|
||||
list->first = newElement;
|
||||
list->last = newElement;
|
||||
} else {
|
||||
list->last->next = new;
|
||||
list->last = new;
|
||||
list->last->next = newElement;
|
||||
list->last = newElement;
|
||||
}
|
||||
new->word = strdup(word);
|
||||
newElement->word = strdup(word);
|
||||
list->size++;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdlib.h>
|
||||
#include "fish_shell/fish_core.h"
|
||||
#include "fish_shell/fish_types.h"
|
||||
#include "fish_core.h"
|
||||
#include "fish_types.h"
|
||||
|
||||
int main() {
|
||||
/* todo load config file */
|
20
fish_shell_tests/CMakeLists.txt
Normal file
20
fish_shell_tests/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(fish_shell_tests)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -c")
|
||||
|
||||
include_directories(
|
||||
"${source_dir}/googletest/include"
|
||||
"${source_dir}/googlemock/include"
|
||||
)
|
||||
|
||||
set(SOURCE_FILES_TESTS main.cpp FishCoreTests.cpp FishCoreTests.h)
|
||||
|
||||
add_executable(fish_tests ${SOURCE_FILES_TESTS})
|
||||
|
||||
target_link_libraries(fish_tests libgtest libgmock)
|
||||
|
||||
|
38
fish_shell_tests/FishCoreTests.cpp
Normal file
38
fish_shell_tests/FishCoreTests.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 15/05/2017.
|
||||
//
|
||||
|
||||
#include "FishCoreTests.h"
|
||||
|
||||
//
|
||||
// Created by Antoine Bartuccio on 15/05/2017.
|
||||
//
|
||||
|
||||
#include "../fish_shell/fish_core.c"
|
||||
|
||||
|
||||
//TEST_F(FishCoreTests, split){
|
||||
// ASSERT_TRUE(true);
|
||||
//}
|
||||
|
||||
TEST(simple_split, split){
|
||||
char input[] = "git push --force";
|
||||
char *output[] = {
|
||||
(char *) "git",
|
||||
(char *) "push",
|
||||
(char *) "--force"
|
||||
};
|
||||
WordList *list = split(input, (char *) FISH_TOKENS);
|
||||
WordListElement *current = list->first;
|
||||
int i = 0;
|
||||
|
||||
ASSERT_FALSE(current == NULL);
|
||||
while(current != NULL){
|
||||
ASSERT_STREQ(current->word, output[i]);
|
||||
current = current->next;
|
||||
i++;
|
||||
}
|
||||
|
||||
freeWordList(list);
|
||||
|
||||
}
|
15
fish_shell_tests/FishCoreTests.h
Normal file
15
fish_shell_tests/FishCoreTests.h
Normal file
@ -0,0 +1,15 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 15/05/2017.
|
||||
//
|
||||
|
||||
#ifndef FISH_FISH_CORE_TESTS_H
|
||||
#define FISH_FISH_CORE_TESTS_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
class FishCoreTests : public ::testing::Test {
|
||||
void SetUp() {}
|
||||
void TearDown(){}
|
||||
};
|
||||
|
||||
#endif //FISH_FISH_CORE_TESTS_H
|
16
fish_shell_tests/main.cpp
Normal file
16
fish_shell_tests/main.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 15/05/2017.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
printf("Je mange des patates");
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
int ret = RUN_ALL_TESTS();
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user