Skip to content

Commit

Permalink
Make changes in preparation for LFE 2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
oubiwann committed Aug 15, 2020
1 parent 1402201 commit ff9d44e
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 23 deletions.
15 changes: 8 additions & 7 deletions include/ltest-macros.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
(defun to-unders (atm)
(re:replace (atom_to_list atm) "-" "_" '(#(return list) global)))

;; XXX this is no longer used anywhere, right? remove it!
(defun list-body
((body) (when (is_list body))
body)
Expand Down Expand Up @@ -89,7 +90,7 @@
;;;===================================================================

(eval-when-compile
;;Return true if we have (tuple "name"...) or #("Name"...)
;; Return true if we have (tuple "name"...) or #("Name"...)
(defun is-named-tuple
((t) (when (is_tuple t))
(io_lib:printable_list (element 1 t)))
Expand All @@ -98,7 +99,7 @@
(io_lib:printable_list (cadr t))))
((other) 'false))

;;Return (tuple "Name" lambda() ...) from (tuple "Name" ...)
;; Return (tuple "Name" lambda() ...) from (tuple "Name" ...)
(defun mk-named-tuple
((t) (when (is_tuple t))
`(tuple ,(element 1 t)
Expand Down Expand Up @@ -209,7 +210,7 @@

(defmacro is-exit
"Equivalent to [[is-exception/3]] with `'exit` as `expected-class`."
(`(,expression) `(is-exit _ ,expression))
(`(,expression) `(is-exit _ ,expression))
(`(,expected-term ,expression) `(assertExit ,expected-term ,expression)))

(defmacro is-not-exit
Expand All @@ -221,7 +222,7 @@

(defmacro is-throw
"Equivalent to [[is-exception/3]] with `'throw` as `expected-class`."
(`(,expression) `(is-throw _ ,expression))
(`(,expression) `(is-throw _ ,expression))
(`(,expected-term ,expression) `(assertThrow ,expected-term ,expression)))

(defmacro is-not-throw
Expand Down Expand Up @@ -285,17 +286,17 @@

(defmacro is-exit*
"Return a test object that wraps [[is-exit/2]]"
(`(,expression) `(is-exit* _ ,expression))
(`(,expression) `(is-exit* _ ,expression))
(`(,expected-term ,expression) `(_assertExit ,expected-term ,expression)))

(defmacro is-not-exit* (expected-term expression)
"Return a test object that wraps [[is-not-exit/2]]."
(`(,expression) `(is-not-exit* _ ,expression))
(`(,expression) `(is-not-exit* _ ,expression))
(`(,expected-term ,body) `(_test (is-not-exit ,expected-term ,expression))))

(defmacro is-throw* (expected-term expression)
"Return a test object that wraps [[is-throw/2]]."
(`(,expression) `(is-throw* _ ,expression))
(`(,expression) `(is-throw* _ ,expression))
(`(,expected-term ,body) `(_assertThrow ,expected-term ,expression)))

(defmacro is-not-throw* (expected-term expression)
Expand Down
2 changes: 1 addition & 1 deletion include/ltest-records.lfe
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(defrecord state
(status (orddict:new))
status
test-type
(ok 0)
(fail 0)
Expand Down
23 changes: 15 additions & 8 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@

{pre_hooks, [
%% DEBUG:
% {"(linux|darwin|solaris|freebsd|netbsd|openbsd)", compile,
% "echo REBAR_DEPS_DIR = $REBAR_DEPS_DIR"},
%% {"(linux|darwin|solaris|freebsd|netbsd|openbsd)", compile,
%% "echo REBAR_DEPS_DIR = $REBAR_DEPS_DIR"},
{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", app_compile,
"$REBAR_DEPS_DIR/lfe/bin/lfe $REBAR_DEPS_DIR/lfe/bin/lfec"
" -o $REBAR_DEPS_DIR/ltest/ebin"
" src/*.lfe"},
%% TODO: equivalent win32 hook
{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", eunit,
"$REBAR_DEPS_DIR/lfe/bin/lfe $REBAR_DEPS_DIR/lfe/bin/lfec"
" -o $REBAR_DEPS_DIR/ltest/ebin"
" test/*.lfe"}
" src/*.lfe"}
%% TODO: Test this on a win32 box
%% {"win32", ct,
%% "bin/lfe bin/lfec -o $REBAR_DEPS_DIR/ltest/test test/*_SUITE.lfe"}
]}.

{profiles, [
{test, [
{pre_hooks, [
{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", app_compile,
"$REBAR_DEPS_DIR/lfe/bin/lfe $REBAR_DEPS_DIR/lfe/bin/lfec "
"-o $REBAR_DEPS_DIR/ltest/ebin "
"src/*.lfe"},
{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", app_compile,
"$REBAR_DEPS_DIR/lfe/bin/lfe $REBAR_DEPS_DIR/lfe/bin/lfec "
"-o $REBAR_DEPS_DIR/ltest/ebin "
"test/*.lfe"}
]}
]},
{repl, [
{pre_hooks, [
{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", app_compile,
Expand Down
2 changes: 1 addition & 1 deletion src/ltest-formatter.lfe
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(defmodule ltest-formatter
(export all))

(include-lib "ltest/include/ltest-records.lfe")
(include-lib "include/ltest-records.lfe")

(defun test-suite-header ()
(io:format (get-suite-header)))
Expand Down
6 changes: 4 additions & 2 deletions src/ltest-listener.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(behaviour eunit_listener)
(export all))

(include-lib "ltest/include/ltest-records.lfe")
(include-lib "include/ltest-records.lfe")

(defun start ()
(start '()))
Expand All @@ -11,7 +11,9 @@
(eunit_listener:start (MODULE) options))

(defun init (options)
(make-state test-type (proplists:get_value 'test-type options)))
(make-state
status (orddict:new)
test-type (proplists:get_value 'test-type options)))

(defun handle_begin
(('group (= `(,_ #(desc undefined) ,_ ,_) data) state)
Expand Down
2 changes: 1 addition & 1 deletion src/ltest-util.lfe
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(defmodule ltest-util
(export all))

(include-lib "ltest/include/ltest-records.lfe")
(include-lib "include/ltest-records.lfe")

(defun get-module (bin-data)
(beam->module (get-beam bin-data)))
Expand Down
44 changes: 41 additions & 3 deletions src/ltest.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,32 @@

(include-lib "include/ltest-macros.lfe")

(defun skip-test-patt () '".*_skip")
(defun skip-test-group-patt () '"(.*)(_skip)")

(defun skip-test-patt () ".*_skip")
(defun skip-test-group-patt () "(.*)(_skip)")

;; XXX this code actually assumes two possible layouts for different versions of
;; rebar; those paths don't belong in a general purpose library, but rather
;; in a rebar3 plugin.
;;
;; instead, there should be two path functions:
;; - one that takes two arguments, a prefix and a regex, where the two are
;; filename:joined and then pumped into filelib:wildcard, and
;; - one that takes one argument, a regex, and then calls the two-arg
;; function with a default (e.g., ".")
;;
;; come to think of it, though, that also feels like a bad approach. it
;; should just recurse through a given directory, and look for beam files.
;; in a rebar3 plugin, the appropriate path can be computed.
;;
;; so, some examination should be done of the latest rebar3 code, to see
;; what public utility functions there are for locating beam files for a
;; given app (or, in the case of releases, set of apps). That would mean
;; we wouldn't need to do any wild-carding whatsoever ...
;;
;; see XXX comment on `get-possible-test-beams` for more thoughts ...
;;
;; related ticket: https://github.com/lfex/ltest/issues/61
;;
(defun paths (path)
(lists:append
(list
Expand All @@ -15,6 +38,21 @@
;; XXX this should be _build/<profile(s)>/lib/...
(list path "_build/*/lib/*/ebin/*.beam"))))))

;; XXX do we need this? after examining the current rebar3 utils, we might not.
;;
;; this library baiscally uses behaviours as "marker interfaces" and that's
;; why we're jumping through all these hoops. so we should ask some basic
;; questions:
;;
;; - is there a better way to do this in Erlang/LFE? for example, eunit
;; expects functions to have a particular suffix; we could do the same
;; to distinguish unit, system, and integration tests
;; - is there a more elegant way to check for a behaviour in a beam file?
;; - does rebar3 offer some utility functions that do this better, that we
;; can use?
;;
;; related ticket: https://github.com/lfex/ltest/issues/61
;;
(defun get-possible-test-beams (path)
"Get the compiled .beam files, but without the .beam extension. The list of
files generated by this function are meant to be consumed by (code:load_abs)."
Expand Down

0 comments on commit ff9d44e

Please sign in to comment.