From 83eb06d0c5e1e79b70cb0917aa6404537e9c7aa4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Erik=20Hedenstro=CC=88m?= <erik@hedenstroem.com>
Date: Wed, 11 Nov 2015 12:46:36 +0100
Subject: [PATCH] All public functions speced

---
 .gitlab-ci.yml                  |  8 +-------
 Makefile                        |  8 ++++----
 include/gurka.hrl               | 14 +++++++-------
 rebar.config                    |  5 +++++
 src/gurka.erl                   | 15 +++++++++++++++
 src/gurka_eunit.erl             | 23 +++++++++++++++++------
 src/gurka_formatter_compact.erl |  8 ++++++--
 src/gurka_formatter_plain.erl   |  8 ++++++--
 src/gurka_parser.erl            |  4 +++-
 src/gurka_transform.erl         |  1 +
 10 files changed, 65 insertions(+), 29 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2b755a3..f042910 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,7 +1,4 @@
 before_script:
-  - banner "Environment"
-  - env | sort
-  - docker info
   - git config --global url.https://.insteadOf git://
   - mkdir -p ~/.hex ~/.config/rebar3
   - printf "{key,<<\"$HEX_KEY\">>}.\n{username,<<\"$HEX_USERNAME\">>}.\n" > ~/.hex/hex.config
@@ -18,14 +15,12 @@ stages:
 compile:
   stage: compile
   script:
-    - banner "compile"
     - rebar3 as production do compile
 
 test:
   stage: test
   script:
-    - banner "test"
-    - rebar3 as test do eunit --cover --dir=test, cover --verbose
+    - rebar3 as test do eunit --cover --dir=test, cover --verbose, dialyzer
     - coverage.escript _build/test/cover/eunit.coverdata
 
 publish:
@@ -33,6 +28,5 @@ publish:
   only:
     - /^\d+[.]\d+[.]\d+$/ # Only publish HEAD tagged with semantic version
   script:
-    - banner "publish"
     - rebar3 update
     - echo Y | rebar3 hex publish
diff --git a/Makefile b/Makefile
index 33df7b3..843e42f 100644
--- a/Makefile
+++ b/Makefile
@@ -6,21 +6,21 @@ REBAR := $(CURDIR)/rebar3
 $(shell if ! [ -e "$(REBAR)" ]; then curl -jksSL -o $(REBAR) https://s3.amazonaws.com/rebar3/rebar3; chmod +x $(REBAR); fi)
 endif
 
-all: tests
+all: eunit
 
 compile:
 	@$(REBAR) compile
 
-tests:
+eunit:
 	@$(REBAR) do eunit --cover --dir=test, cover --verbose
 
-analyze:
+dialyzer:
 	@$(REBAR) dialyzer
 
 release:
 	@$(REBAR) release
 
-docs:
+edoc:
 	@$(REBAR) edoc
 
 clean:
diff --git a/include/gurka.hrl b/include/gurka.hrl
index 601b8b6..8c2abdd 100644
--- a/include/gurka.hrl
+++ b/include/gurka.hrl
@@ -1,10 +1,3 @@
--type phase() :: feature | background | scenario | scenario_outline | meta.
--type action() :: skip | start | 'end' | desc | title | given | 'when' | then | examples | headers | values | tags | table | docstring.
--type tokens() :: [tokens() | binary() | {table, any()} | {docstring, any()}].
--type row() :: integer().
--type meta() :: [{atom(),term()}].
--type lines() :: [{row(), binary(), tokens()}].
-
 -record(step, {
     phase :: phase(),
     action = [] :: action(),
@@ -13,4 +6,11 @@
     meta = [] :: meta()
 }).
 
+-type phase() :: feature | background | scenario | scenario_outline | meta.
+-type action() :: skip | start | 'end' | desc | title | given | 'when' | then | examples | headers | values | tags | table | docstring.
+-type tokens() :: [tokens() | binary() | {table, any()} | {docstring, any()}].
+-type row() :: integer().
+-type meta() :: [{atom(),term()}].
+-type lines() :: [{row(), binary(), tokens()}].
 -type feature() :: [#step{}].
+-type result() :: [{ok | error | term(), #step{}} | result()].
diff --git a/rebar.config b/rebar.config
index 8d42c8a..32b92d8 100644
--- a/rebar.config
+++ b/rebar.config
@@ -5,6 +5,11 @@
     {extended_start_script, true}
 ]}.
 
+{edoc_opts, [
+    {preprocess, true},
+    {includes, ["include"]}
+]}.
+
 {profiles, [
     {test, [
         {eunit_opts, [{report, {eunit_surefire, [{dir, "_build/test"}]}}]},
diff --git a/src/gurka.erl b/src/gurka.erl
index 4cf0e02..120c3f2 100644
--- a/src/gurka.erl
+++ b/src/gurka.erl
@@ -4,13 +4,28 @@
 
 -export([run/1, run/2, run/3]).
 
+-spec run(File) -> {ok, Result} | {fail, Result} | {error, Reason} when
+    File :: file:name_all(),
+    Result :: result(),
+    Reason :: file:posix() | badarg | terminated | system_limit.
 run(File) ->
     run(File, []).
 
+-spec run(File, Options) -> {ok, Result} | {fail, Result} | {error, Reason} when
+    File :: file:name_all(),
+    Options :: [term()],
+    Result :: result(),
+    Reason :: file:posix() | badarg | terminated | system_limit.
 run(File, Options) ->
     Module = list_to_atom("feature_" ++ filename:basename(File, ".feature")),
     run(File, Module, Options).
 
+-spec run(File, Module, Options) -> {ok, Result} | {fail, Result} | {error, Reason} when
+    File :: file:name_all(),
+    Module :: module(),
+    Options :: [term()],
+    Result :: result(),
+    Reason :: file:posix() | badarg | terminated | system_limit.
 run(File, Module, Options) ->
     case gurka_parser:parse(File) of
         {ok, Feature} ->
diff --git a/src/gurka_eunit.erl b/src/gurka_eunit.erl
index 0b405d4..d40ff5f 100644
--- a/src/gurka_eunit.erl
+++ b/src/gurka_eunit.erl
@@ -4,12 +4,23 @@
 
 -export([setup/1, setup/2, setup/3]).
 
+-type eunit_fixture() :: {setup, spawn, Setup::fun(), Cleanup::fun(), Tests::fun()}.
+
+-spec setup(Setup) -> eunit_fixture() when
+    Setup :: fun().
 setup(Setup) ->
     setup(Setup, fun(_) -> ok end).
 
+-spec setup(Setup, Cleanup) -> eunit_fixture() when
+    Setup :: fun(),
+    Cleanup :: fun().
 setup(Setup, Cleanup) ->
     setup(Setup, Cleanup, fun(Message) -> io:fwrite(user, "~s~n", [Message]) end).
 
+-spec setup(Setup, Cleanup, Log) -> eunit_fixture() when
+    Setup :: [file:name_all()] | fun(),
+    Cleanup :: fun(),
+    Log :: fun().
 setup(Features, Cleanup, Log) when is_list(Features) ->
     setup(fun() -> Features end, Cleanup, Log);
 
@@ -25,12 +36,12 @@ feature(Log, File) ->
     Tags = parse_tags(),
     Formatter = parse_format(),
     Options = [{file, File}, {tags, Tags}, {formatter, Formatter}, {log, Log}],
-    Result = gurka:run(File, Options),
-    Log(io_lib:format("~s", [Formatter:format(Result, Options)])),
-    case Result of
-        {ok, _} ->
+    {Status, Result} = gurka:run(File, Options),
+    Log(io_lib:format("~s", [Formatter:format(Status, Result, Options)])),
+    case Status of
+        ok ->
             ok;
-        {fail, _} ->
+        fail ->
             erlang:error({failed, File})
     end.
 
@@ -63,4 +74,4 @@ list_to_number(L) ->
     catch
         error:badarg ->
             list_to_integer(L)
-    end.
\ No newline at end of file
+    end.
diff --git a/src/gurka_formatter_compact.erl b/src/gurka_formatter_compact.erl
index 8e419ee..fb1b15d 100644
--- a/src/gurka_formatter_compact.erl
+++ b/src/gurka_formatter_compact.erl
@@ -2,9 +2,13 @@
 
 -include("gurka.hrl").
 
--export([format/2]).
+-export([format/3]).
 
-format({Status, Result}, Opts) ->
+-spec format(Status, Result, Opts) -> io_lib:chars() when
+    Status :: ok | fail | error,
+    Result :: result() | file:posix() | badarg | terminated | system_limit,
+    Opts :: [term()].
+format(Status, Result, Opts) ->
     case proplists:get_value(file, Opts) of
         undefined ->
             format_steps(Result);
diff --git a/src/gurka_formatter_plain.erl b/src/gurka_formatter_plain.erl
index c24d8b6..8b8977d 100644
--- a/src/gurka_formatter_plain.erl
+++ b/src/gurka_formatter_plain.erl
@@ -2,9 +2,13 @@
 
 -include("gurka.hrl").
 
--export([format/2]).
+-export([format/3]).
 
-format({Status, Result}, Opts) ->
+-spec format(Status, Result, Opts) -> io_lib:chars() when
+    Status :: ok | fail | error,
+    Result :: result() | file:posix() | badarg | terminated | system_limit,
+    Opts :: [term()].
+format(Status, Result, Opts) ->
     format_header(Status, Opts) ++ format_steps(Result, undefined).
 
 format_header(Status, Opts) ->
diff --git a/src/gurka_parser.erl b/src/gurka_parser.erl
index ff876a2..abfab8d 100644
--- a/src/gurka_parser.erl
+++ b/src/gurka_parser.erl
@@ -5,7 +5,7 @@
 -export([parse/1, tokens/1]).
 
 -spec parse(File) -> {ok, Feature} | {error, Reason} when
-    File :: file:name(),
+    File :: file:name_all(),
     Feature :: feature(),
     Reason :: file:posix() | badarg | terminated | system_limit.
 parse(File) ->
@@ -125,6 +125,8 @@ build_docstring([{_Row, Line, _Tokens} | Lines], Docstring) ->
 normalize_token(Token) ->
     hd(string:tokens(string:to_lower(binary_to_list(Token)), ":")).
 
+-spec tokens(Line) -> [binary()] when
+    Line :: binary().
 tokens(Line) ->
     [strip_quotes(Token) || Token <- tokens(Line, [], <<>>)].
 
diff --git a/src/gurka_transform.erl b/src/gurka_transform.erl
index 48c585c..de91ac6 100644
--- a/src/gurka_transform.erl
+++ b/src/gurka_transform.erl
@@ -1,6 +1,7 @@
 -module(gurka_transform).
 -export([parse_transform/2]).
 
+%% @private
 parse_transform(Forms, _Options) ->
     forms(Forms).
 
-- 
GitLab