GithubHelp home page GithubHelp logo

cucumber / gherkin-c Goto Github PK

View Code? Open in Web Editor NEW
10.0 12.0 12.0 6.19 MB

[READ-ONLY] Gherkin for C - subtree of monorepo https://github.com/cucumber/cucumber -- moved to https://github.com/cucumber/gherkin

License: MIT License

Makefile 1.49% C 95.89% CMake 0.75% HTML 1.65% jq 0.22%

gherkin-c's Introduction

Using the Gherkin library

The Gherkin library is using functions in the math library, so the math library needs also to be linked when the Gherkin library is used.

Example:

#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>

#include "ast_builder.h"
#include "compiler.h"
#include "error.h"
#include "file_reader.h"
#include "gherkin_document.h"
#include "id_generator.h"
#include "incrementing_id_generator.h"
#include "parser.h"
#include "pickle.h"
#include "string_token_scanner.h"
#include "token_matcher.h"

setlocale(LC_ALL, "en_US.UTF-8");
TokenMatcher* token_matcher = TokenMatcher_new(L"en");
IdGenerator* id_generator = IncrementingIdGenerator_new();
Builder* builder = AstBuilder_new(id_generator);
Parser* parser = Parser_new(builder);
Compiler* compiler = Compiler_new(id_generator);
const char* filename = "minimal.feature";
FileReader* file_reader = FileReader_new(filename);
const wchar_t* content = FileReader_read(file_reader);
TokenScanner* token_scanner = StringTokenScanner_new(FileReader_read(file_reader));
int result_code = 0;
result_code = Parser_parse(parser, token_matcher, token_scanner);
if (result_code == 0) {
    const GherkinDocument* gherkin_document = AstBuilder_get_result(builder, filename);
    result_code = Compiler_compile(compiler, gherkin_document, content);
    if (result_code == 0) {
        while (Compiler_has_more_pickles(compiler)) {
            const Pickle* pickle = Compiler_next_pickle(compiler);
            // process pickle
            Pickle_delete(pickle);
        }
    }
    GherkinDocument_delete(gherkin_document);
}
else {
    while (Parser_has_more_errors(parser)) {
        Error* error = Parser_next_error(parser);
        // handle error
        Error_delete(error);
    }
}
TokenScanner_delete(token_scanner);
free((void*)content);
FileReader_delete(file_reader);
Compiler_delete(compiler);
Parser_delete(parser);
AstBuilder_delete(builder);
id_generator->id_generator_delete(id_generator);
TokenMatcher_delete(token_matcher);

The source file gherkin_cli.c can be used as an example of using the Gherkin library.

The Gherkin library contains only an incrementing id generator (generating the ids "1", "2", ...), should UUIDs be necessary, the user needs to provide an implementation of the id_generator.h interface that generates UUID strings.

Building

Three artifacts can be built:

  • the Gherkin library for static linking (libgherkin.a)
  • the Gherkin library for dynamic linking (libgherkin.so.<version>)
  • the cli binary used for running the Gherkin acceptance tests (gherkin)

Both Makefiles and definition files for cmake are available in the repository.

Build using make:

  • The make target "libs" is used to build the Gherkin library for static linking
  • The make target "libs_so" is used to build the Gherkin library for static linking
  • The make target "cli" is used to biuld the cli binary (the Gherkin library for static linking will aslo be build, since it is used when linking the cli).

Building the cli with gcc:

make cli

Building the with clang

make CC=clang cli

Building Windows cli with mingw

Install the toolchain (OS X)

brew install mingw-w64
# Run `brew info mingw-w64` to verify the path before next command
export PATH=/usr/local/Cellar/mingw-w64/5.0.1/bin:$PATH
# Install wine - for testing
brew cask install xquartz
brew install wine

Build:

make CC=i686-w64-mingw32-gcc cli

Build the cli with other compilers

Edit src/Makefile and set CC, CC_FLAGS, AR, AR_FLAGS, LD, LD_FLAGS appropriately, then run make cli

Build using cmake

mkdir build
cd build
cmake ..
cmake --build . --target install

You can use this library in your project like this

cmake_minimum_required(VERSION 3.0)
project(gherkincsample)
list(APPEND CMAKE_PREFIX_PATH "INSTALLATION_DIRECTORY")
set(CMAKE_CXX_STANDARD 11)
find_package(gherkin REQUIRED)
add_executable(gherkincsample main.cpp)
target_link_libraries(gherkincsample gherkin::gherkin)

You can build this library as an external project in you project like this

cmake_minimum_required(VERSION 3.7)
project(gherkincsample)
include(ExternalProject)
ExternalProject_Add(gherkin_proj
  GIT_REPOSITORY https://github.com/cucumber/common.git
  GIT_TAG        <commit SHA or tag>
  SOURCE_SUBDIR  gherkin/c
)
...

Docs

The docs are here.

gherkin-c's People

Contributors

alaahong avatar aslakhellesoy avatar aurelien-reeves avatar avsd avatar brasmusson avatar coderbyheart avatar corristo avatar cyocum avatar dbrock98 avatar dewjunkie avatar edinuser avatar ehuelsmann avatar gasparnagy avatar hkosova avatar johnknoop avatar lukaswoodtli avatar mgiustiniani avatar mlvandijk avatar mpkorstanje avatar mxygem avatar nvmkpk avatar plavcik avatar rjwittams avatar roskee avatar sappo avatar sergio-forero avatar vincent-psarga avatar vjacheslavvytjagov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gherkin-c's Issues

Add CMake support

There are projects using this repository through CMake.
For example link
I'll create PR for this issue.

Segfault when file does not exist

Steps to Reproduce

  1. Build gherkin-c cli via make
  2. Run the following:
./bin/gherkin test.fea

Outcome

[1]    15198 segmentation fault (core dumped)  ./bin/gherkin test.fea

The problem is in file_reader.c which does not check the result of fopen. When the file does not exist, it causes a segfault.

CMake configuration on Windows

Thank you for creating a C implementation, and adding Cmake. I think there's an easy solution to this, but I just don't know it because I've not seen this happen by default before:

With Visual Studio, CMake is generating a DLL by default for some reason, maybe that's what is desired:

gherkin.vcxproj -> D:\sources\git-conan\gherkin-c\build\Debug\gherkin.dll

But then tries to link to gherkin.lib instead of gherkin.dll:

LINK : fatal error LNK1104: cannot open file 'Debug\gherkin.lib'

Of note, I used the commands on the readme, with CMake 3.10 and Visual studio 2017.

mkdir build
cd build
cmake ..
cmake --build . --target install

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.