Просмотр исходного кода

Add test for and fix DTL_FULL_PATH

Loïc Hoguin 9 лет назад
Родитель
Сommit
f7ac6d1b54
2 измененных файлов с 40 добавлено и 7 удалено
  1. 9 4
      plugins/erlydtl.mk
  2. 31 3
      test/plugin_erlydtl.mk

+ 9 - 4
plugins/erlydtl.mk

@@ -3,7 +3,7 @@
 
 # Configuration.
 
-DTL_FULL_PATH ?= 0
+DTL_FULL_PATH ?=
 DTL_PATH ?= templates/
 DTL_SUFFIX ?= _dtl
 
@@ -16,10 +16,10 @@ dtl_verbose = $(dtl_verbose_$(V))
 
 define erlydtl_compile.erl
 	[begin
-		Module0 = case $(DTL_FULL_PATH) of
-			0 ->
+		Module0 = case "$(strip $(DTL_FULL_PATH))" of
+			"" ->
 				filename:basename(F, ".dtl");
-			1 ->
+			_ ->
 				"$(DTL_PATH)" ++ F2 = filename:rootname(F, ".dtl"),
 				re:replace(F2, "/",  "_",  [{return, list}, global])
 		end,
@@ -35,7 +35,12 @@ endef
 ifneq ($(wildcard src/),)
 
 DTL_FILES = $(sort $(call core_find,$(DTL_PATH),*.dtl))
+
+ifdef DTL_FULL_PATH
+BEAM_FILES += $(addprefix ebin/,$(patsubst %.dtl,%_dtl.beam,$(subst /,_,$(DTL_FILES:$(DTL_PATH)%=%))))
+else
 BEAM_FILES += $(addprefix ebin/,$(patsubst %.dtl,%_dtl.beam,$(notdir $(DTL_FILES))))
+endif
 
 ebin/$(PROJECT).app:: $(DTL_FILES)
 	$(if $(strip $?),\

+ 31 - 3
test/plugin_erlydtl.mk

@@ -1,6 +1,6 @@
 # ErlyDTL plugin.
 
-ERLYDTL_CASES = compile
+ERLYDTL_CASES = compile full-path
 ERLYDTL_TARGETS = $(addprefix erlydtl-,$(ERLYDTL_CASES))
 ERLYDTL_CLEAN_TARGETS = $(addprefix clean-,$(ERLYDTL_TARGETS))
 
@@ -24,7 +24,7 @@ erlydtl-compile: build clean-erlydtl-compile
 	$t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = erlydtl\n"}' $(APP)/Makefile
 
 	$i "Generate ErlyDTL templates"
-	$t mkdir $(APP)/templates
+	$t mkdir $(APP)/templates/
 	$t touch $(APP)/templates/$(APP)_one.dtl
 	$t touch $(APP)/templates/$(APP)_two.dtl
 
@@ -33,10 +33,38 @@ erlydtl-compile: build clean-erlydtl-compile
 
 	$i "Check that ErlyDTL templates are compiled"
 	$t test -f $(APP)/ebin/$(APP)_one_dtl.beam
-	$t test -f $(APP)/ebin/$(APP)_one_dtl.beam
+	$t test -f $(APP)/ebin/$(APP)_two_dtl.beam
 
 	$i "Check that ErlyDTL generated modules are included in .app file"
 	$t $(ERL) -pa $(APP)/ebin/ -eval " \
 		ok = application:load($(APP)), \
 		{ok, [$(APP_)_one_dtl, $(APP)_two_dtl]} = application:get_key($(APP), modules), \
 		halt()"
+
+erlydtl-full-path: build clean-erlydtl-full-path
+
+	$i "Bootstrap a new OTP library named $(APP)"
+	$t mkdir $(APP)/
+	$t cp ../erlang.mk $(APP)/
+	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
+
+	$i "Add ErlyDTL to the list of dependencies; set DTL_FULL_PATH"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = erlydtl\nDTL_FULL_PATH = 1\n"}' $(APP)/Makefile
+
+	$i "Generate ErlyDTL templates"
+	$t mkdir -p $(APP)/templates/deep/
+	$t touch $(APP)/templates/$(APP)_one.dtl
+	$t touch $(APP)/templates/deep/$(APP)_two.dtl
+
+	$i "Build the application"
+	$t $(MAKE) -C $(APP) $v
+
+	$i "Check that ErlyDTL templates are compiled"
+	$t test -f $(APP)/ebin/$(APP)_one_dtl.beam
+	$t test -f $(APP)/ebin/deep_$(APP)_two_dtl.beam
+
+	$i "Check that ErlyDTL generated modules are included in .app file"
+	$t $(ERL) -pa $(APP)/ebin/ -eval " \
+		ok = application:load($(APP)), \
+		{ok, [deep_$(APP)_two_dtl, $(APP_)_one_dtl]} = application:get_key($(APP), modules), \
+		halt()"