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

Disallow uppercase characters in application names

Loïc Hoguin 6 лет назад
Родитель
Сommit
9dfa5dd6fa
2 измененных файлов с 46 добавлено и 8 удалено
  1. 8 4
      plugins/bootstrap.mk
  2. 38 4
      test/plugin_bootstrap.mk

+ 8 - 4
plugins/bootstrap.mk

@@ -421,7 +421,8 @@ ifneq ($(wildcard src/),)
 	$(error Error: src/ directory already exists)
 endif
 	$(eval p := $(PROJECT))
-	$(if $(findstring -,$p),$(error Error: The dash cannot be used in application names))
+	$(if $(shell echo $p | grep -x "[a-z0-9_]*"),,\
+		$(error Error: Invalid characters in the application name))
 	$(eval n := $(PROJECT)_sup)
 	$(call render_template,bs_Makefile,Makefile)
 	$(verbose) echo "include erlang.mk" >> Makefile
@@ -437,7 +438,8 @@ ifneq ($(wildcard src/),)
 	$(error Error: src/ directory already exists)
 endif
 	$(eval p := $(PROJECT))
-	$(if $(findstring -,$p),$(error Error: The dash cannot be used in application names))
+	$(if $(shell echo $p | grep -x "[a-z0-9_]*"),,\
+		$(error Error: Invalid characters in the application name))
 	$(call render_template,bs_Makefile,Makefile)
 	$(verbose) echo "include erlang.mk" >> Makefile
 	$(verbose) mkdir src/
@@ -466,7 +468,8 @@ ifneq ($(wildcard $(APPS_DIR)/$in),)
 	$(error Error: Application $in already exists)
 endif
 	$(eval p := $(in))
-	$(if $(findstring -,$p),$(error Error: The dash cannot be used in application names))
+	$(if $(shell echo $p | grep -x "[a-z0-9_]*"),,\
+		$(error Error: Invalid characters in the application name))
 	$(eval n := $(in)_sup)
 	$(verbose) mkdir -p $(APPS_DIR)/$p/src/
 	$(call render_template,bs_apps_Makefile,$(APPS_DIR)/$p/Makefile)
@@ -484,7 +487,8 @@ ifneq ($(wildcard $(APPS_DIR)/$in),)
 	$(error Error: Application $in already exists)
 endif
 	$(eval p := $(in))
-	$(if $(findstring -,$p),$(error Error: The dash cannot be used in application names))
+	$(if $(shell echo $p | grep -x "[a-z0-9_]*"),,\
+		$(error Error: Invalid characters in the application name))
 	$(verbose) mkdir -p $(APPS_DIR)/$p/src/
 	$(call render_template,bs_apps_Makefile,$(APPS_DIR)/$p/Makefile)
 ifdef LEGACY

+ 38 - 4
test/plugin_bootstrap.mk

@@ -37,21 +37,35 @@ endif
 		{module, $(APP)_sup} = code:load_file($(APP)_sup), \
 		halt()"
 
-bootstrap-invalid-app-name: build clean
+bootstrap-invalid-app-name-dash: build clean
 
 	$i "Try to bootstrap a new OTP application named test_$@"
 	$t mkdir test_$@/
 	$t cp ../erlang.mk test_$@/
 	$t ! $(MAKE) -C test_$@ -f erlang.mk bootstrap $v
 
-bootstrap-invalid-lib-name: build clean
+bootstrap-invalid-app-name-uppercase: build clean
+
+	$i "Try to bootstrap a new OTP application named $(APP)_HELLO"
+	$t mkdir $(APP)_HELLO/
+	$t cp ../erlang.mk $(APP)_HELLO/
+	$t ! $(MAKE) -C $(APP)_HELLO -f erlang.mk bootstrap $v
+
+bootstrap-invalid-lib-name-dash: build clean
 
 	$i "Try to bootstrap a new OTP library named test_$@"
 	$t mkdir test_$@/
 	$t cp ../erlang.mk test_$@/
 	$t ! $(MAKE) -C test_$@ -f erlang.mk bootstrap-lib $v
 
-bootstrap-invalid-new-app-name: build clean
+bootstrap-invalid-lib-name-uppercase: build clean
+
+	$i "Try to bootstrap a new OTP library named $(APP)_HELLO"
+	$t mkdir $(APP)_HELLO/
+	$t cp ../erlang.mk $(APP)_HELLO/
+	$t ! $(MAKE) -C $(APP)_HELLO -f erlang.mk bootstrap-lib $v
+
+bootstrap-invalid-new-app-name-dash: build clean
 
 	$i "Bootstrap a new OTP library named $(APP)"
 	$t mkdir $(APP)/
@@ -61,7 +75,17 @@ bootstrap-invalid-new-app-name: build clean
 	$i "Try to create a new application my-app"
 	$t ! $(MAKE) -C $(APP) new-app in=my-app $v
 
-bootstrap-invalid-new-lib-name: build clean
+bootstrap-invalid-new-app-name-uppercase: build clean
+
+	$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 "Try to create a new application My_app"
+	$t ! $(MAKE) -C $(APP) new-app in=My_app $v
+
+bootstrap-invalid-new-lib-name-dash: build clean
 
 	$i "Bootstrap a new OTP library named $(APP)"
 	$t mkdir $(APP)/
@@ -71,6 +95,16 @@ bootstrap-invalid-new-lib-name: build clean
 	$i "Try to create a new library my-lib"
 	$t ! $(MAKE) -C $(APP) new-lib in=my-lib $v
 
+bootstrap-invalid-new-lib-name-uppercase: build clean
+
+	$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 "Try to create a new library My_lib"
+	$t ! $(MAKE) -C $(APP) new-lib in=My_lib $v
+
 bootstrap-lib: build clean
 
 	$i "Bootstrap a new OTP library named $(APP)"