Browse Source

Add tests and document the SP variable

People who prefer spaces instead of tabs are now covered.
Loïc Hoguin 9 years ago
parent
commit
beec62e994
2 changed files with 81 additions and 1 deletions
  1. 19 0
      doc/src/guide/getting_started.asciidoc
  2. 62 1
      test/plugin_bootstrap.mk

+ 19 - 0
doc/src/guide/getting_started.asciidoc

@@ -183,6 +183,25 @@ Eshell V7.0  (abort with ^G)
 
 
 Simple as that!
 Simple as that!
 
 
+=== Using spaces instead of tabs
+
+Erlang.mk defaults to tabs when creating files from templates.
+This is in part because of a personal preference, and in part
+because it is much easier to convert tabs to spaces than the
+opposite.
+
+Use the `SP` variable if you prefer spaces. Set it to the number
+of spaces per indentation level you want.
+
+For example, if you prefer two spaces per indentation level:
+
+[source,bash]
+$ make -f erlang.mk bootstrap SP=2
+
+When you bootstrap the project initially, the variable automatically
+gets added to the Makefile, so you only need to provide it when
+you get started.
+
 === Using templates
 === Using templates
 
 
 It is no secret that Erlang's OTP behaviors tend to have some
 It is no secret that Erlang's OTP behaviors tend to have some

+ 62 - 1
test/plugin_bootstrap.mk

@@ -1,6 +1,6 @@
 # Bootstrap plugin.
 # Bootstrap plugin.
 
 
-BOOTSTRAP_CASES = app lib rel templates
+BOOTSTRAP_CASES = app lib rel sp tab templates
 BOOTSTRAP_TARGETS = $(addprefix bootstrap-,$(BOOTSTRAP_CASES))
 BOOTSTRAP_TARGETS = $(addprefix bootstrap-,$(BOOTSTRAP_CASES))
 BOOTSTRAP_CLEAN_TARGETS = $(addprefix clean-,$(BOOTSTRAP_TARGETS))
 BOOTSTRAP_CLEAN_TARGETS = $(addprefix clean-,$(BOOTSTRAP_TARGETS))
 
 
@@ -116,6 +116,67 @@ endif
 	$i "Check that there's no erl_crash.dump file"
 	$i "Check that there's no erl_crash.dump file"
 	$t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
 	$t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
 
 
+bootstrap-sp: build clean-bootstrap-sp
+
+	$i "Bootstrap a new OTP application named $(APP)"
+	$t mkdir $(APP)/
+	$t cp ../erlang.mk $(APP)/
+	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap SP=2 $v
+
+	$i "Check that all bootstrapped files exist"
+	$t test -f $(APP)/Makefile
+ifdef LEGACY
+	$t test -f $(APP)/src/$(APP).app.src
+endif
+	$t test -f $(APP)/src/$(APP)_app.erl
+	$t test -f $(APP)/src/$(APP)_sup.erl
+
+	$i "Check that bootstrapped files have no tabs"
+ifdef LEGACY
+	$t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
+endif
+	$t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
+	$t test -z "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
+
+# Everything looks OK, but let's compile the application to make sure.
+	$i "Build the application"
+	$t $(MAKE) -C $(APP) $v
+
+	$i "Check that all compiled files exist"
+	$t test -f $(APP)/ebin/$(APP).app
+	$t test -f $(APP)/ebin/$(APP)_app.beam
+	$t test -f $(APP)/ebin/$(APP)_sup.beam
+
+	$i "Check that the application was compiled correctly"
+	$t $(ERL) -pa $(APP)/ebin/ -eval " \
+		ok = application:start($(APP)), \
+		{ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
+		{module, $(APP)_app} = code:load_file($(APP)_app), \
+		{module, $(APP)_sup} = code:load_file($(APP)_sup), \
+		halt()"
+
+bootstrap-tab: build clean-bootstrap-tab
+
+	$i "Bootstrap a new OTP application named $(APP)"
+	$t mkdir $(APP)/
+	$t cp ../erlang.mk $(APP)/
+	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
+
+	$i "Check that all bootstrapped files exist"
+	$t test -f $(APP)/Makefile
+ifdef LEGACY
+	$t test -f $(APP)/src/$(APP).app.src
+endif
+	$t test -f $(APP)/src/$(APP)_app.erl
+	$t test -f $(APP)/src/$(APP)_sup.erl
+
+	$i "Check that bootstrapped files have tabs"
+ifdef LEGACY
+	$t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP).app.src`"
+endif
+	$t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_app.erl`"
+	$t test "`awk -F "\t" 'NF > 1' $(APP)/src/$(APP)_sup.erl`"
+
 bootstrap-templates: build clean-bootstrap-templates
 bootstrap-templates: build clean-bootstrap-templates
 
 
 	$i "Bootstrap a new OTP library named $(APP)"
 	$i "Bootstrap a new OTP library named $(APP)"