]> granicus.if.org Git - ejabberd/commitdiff
Add logger macro to help troubleshooting Elixir tests
authorMickael Remond <mremond@process-one.net>
Fri, 1 Apr 2016 09:11:42 +0000 (11:11 +0200)
committerMickael Remond <mremond@process-one.net>
Fri, 1 Apr 2016 09:11:42 +0000 (11:11 +0200)
include/logger.hrl
test/README-quicktest.md [new file with mode: 0644]

index 18dc7041ccfc4b76da75ca5f32332a5b6d8bdbd2..df0776863ee950af310358dfb235ba4f8f503315 100644 (file)
 
 -define(CRITICAL_MSG(Format, Args),
        lager:critical(Format, Args)).
+
+%% Use only when trying to troubleshoot test problem with ExUnit
+-define(EXUNIT_LOG(Format, Args),
+        case lists:keyfind(logger, 1, application:loaded_applications()) of
+            false -> ok;
+            _ -> 'Elixir.Logger':bare_log(error, io_lib:format(Format, Args), [?MODULE])
+        end).
diff --git a/test/README-quicktest.md b/test/README-quicktest.md
new file mode 100644 (file)
index 0000000..43c71e8
--- /dev/null
@@ -0,0 +1,33 @@
+# Elixir unit tests
+
+## Running Elixir unit tests
+
+You can run Elixir unit tests with command:
+
+make quicktest
+
+You need to have ejabberd compile with Elixir and tools enabled.
+
+## Troubleshooting test
+
+To help with troubleshooting Elixir tests, we have added a special macro in ejabberd `logger.hrl` include file: ?EXUNIT_LOG
+
+To use this, in test file:
+
+1. in `setup_all, add:
+
+    ```
+    Application.start(:logger)
+    ```
+
+2. Enable log capture for the test you want to analyse by adding
+   `capture_log` tag before test implementation:
+
+   ```
+   @tag capture_log: true
+   ```
+
+In the ejabberd code, if `logger.hrl` is included, you can code adds a
+EXUNIT_LOG macro:
+
+    ?EXUNIT_LOG("My debug log:~p ~p", [Arg1, Arg2])