mirror of
https://gitlab.com/klmp200/fish.git
synced 2024-11-14 12:53:20 +00:00
commit
56fb8aa9d5
@ -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,59 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
project(fish)
|
||||
project(fish_shell)
|
||||
|
||||
# We need thread support
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# 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"
|
||||
)
|
||||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -fpic -Wextra")
|
||||
set(CMAKE_C_FLAGS "-Wall -Werror -pedantic -fpic -Wextra -Wshadow")
|
||||
|
||||
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})
|
||||
add_subdirectory(fish_shell)
|
||||
|
||||
add_subdirectory(fish_shell_tests)
|
||||
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(NAME fish_tests
|
||||
COMMAND 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")
|
||||
|
||||
file(GLOB SOURCE_FILES *)
|
||||
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 */
|
19
fish_shell_tests/CMakeLists.txt
Normal file
19
fish_shell_tests/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
||||
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}")
|
||||
|
||||
include_directories(
|
||||
"${source_dir}/googletest/include"
|
||||
"${source_dir}/googlemock/include"
|
||||
)
|
||||
|
||||
file(GLOB SOURCE_FILES_TESTS *)
|
||||
|
||||
add_executable(fish_tests ${SOURCE_FILES_TESTS})
|
||||
|
||||
target_link_libraries(fish_tests libgtest libgmock)
|
||||
|
36
fish_shell_tests/FishCoreTests.cpp
Normal file
36
fish_shell_tests/FishCoreTests.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 15/05/2017.
|
||||
//
|
||||
|
||||
#include "FishCoreTests.h"
|
||||
#include "../fish_shell/fish_core.c"
|
||||
#include "../fish_shell/fish_utils.c"
|
||||
#include "../fish_shell/fish_commands.c"
|
||||
#include "../fish_shell/fish_globbing.c"
|
||||
|
||||
|
||||
//TEST_F(FishCoreTests, split){
|
||||
// ASSERT_TRUE(true);
|
||||
//}
|
||||
|
||||
TEST(command_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
|
10
fish_shell_tests/main.cpp
Normal file
10
fish_shell_tests/main.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by Antoine Bartuccio on 15/05/2017.
|
||||
//
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
int main(int argc, char **argv){
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Reference in New Issue
Block a user