Quick Start

2 Your First LFE Project

A project? Already?! It sounds daunting, but it's just one command :-)

Head over to your favorite workspace in an open terminal and do this:

$ lfetool new library my-test-lib

As you watch the output crank away, read on to find out what it's doing:

  • lfetool created a skeleton project (of the "library" type)
  • rebar downloaded all the dependencies listed in the new rebar.config file that was created for your project
  • All the downloaded dependendencies were then compiled
  • During the first step, a failing test case was created for you; now, that test case has been run in the test suite and the error has been revealed (TDD!)

2.1 Tests First!

First things first: let's get that failing unit test passing.

Here's the output we saw:

                     {expression,"(: my-test-lib my-adder 2 2)"},

We can see that our test expected 4 but it got 5.

Before we go further, be sure you are in your project directory:

$ cd my-test-lib

Let's look at the test by opening up test/my-test-lib_tests.lfe.

Well, things there look good -- we should get 4 when 2 and 2 are added.

Let's take a look at the source module: src/my-test-lib.lfe. Ah-ha! a bug :-) There's an extra operation that's being done which we don't want.

To fix it, change this line:

  (+ x (+ y 1)))

to this:

  (+ x y))

Now re-run the unit tests:

$ make check-unit

And you should get a passing test:

==> my-test-lib (eunit)
======================== EUnit ========================
my-test-lib_tests: my-adder_test (module 'my-test-lib_tests')...[0.031 s] ok
  Test passed.

We'll talk about the make targets in a bit, but our target above run the unit tests without recompiling all the deps; just our project files and our unit tests.

2.2 Project Inventory

Okay, we've got our tests passing and our project looks healthy. But what does it have in it?

  • a README file in ReStructured Text
  • a Makefile
  • the rebar.config file we mentioned earlier (this has all your project dependencies in it)
  • a package.exs file for uploading your project to expm.co
  • the src directory which holds your project code, and
  • the test directory which holds the tests

There are some other things there (e.g., the deps directory created by rebar and the ebin directory that's created when everything is compiled).

2.3 Repo Ready to Go

lfetool also did one more thing for you: inited the project in git and added all the files:

$ git status
# On branch master
# Initial commit
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#   new file:   .gitignore
#   new file:   Makefile
#   new file:   README.rst
#   new file:   package.exs
#   new file:   rebar.config
#   new file:   src/my-test-lib.app.src
#   new file:   src/my-test-lib.lfe
#   new file:   test/my-test-lib_tests.lfe

All you need to do it git commit -a && git push --all to wherever you want to put your project :-)

Next Stop

You can taste it, can't you? That LFE flavor coming your way? Yup, you're right. You're going to be looking at LFE code next ...