diff --git a/init.sh b/init.sh index 9264d30..4bffaba 100755 --- a/init.sh +++ b/init.sh @@ -32,7 +32,7 @@ convert_string() { echo "${input_string}" | tr ' ' '_' | tr '[:upper:]' '[:lower:]' | tr -d '-' ;; "namespace" | "class_name") - echo "${input_string}" | awk -F" " '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));} 1' | tr -d ' -' + echo "${input_string}" | awk -F" " '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) substr($i,2); } 1' | tr -d ' -' ;; "package_name") echo "${input_string}" | tr ' ' '-' | tr '[:upper:]' '[:lower:]' @@ -318,6 +318,7 @@ main() { # Make sure the input become valid value. project="$(convert_string "${project}" "package_name")" + namespace="$(convert_string "${namespace}" "namespace")" use_php="$(ask_yesno "Use PHP")" diff --git a/tests/scaffold/functional.init.bats b/tests/scaffold/functional.init.bats index bc0a3eb..9e83b57 100644 --- a/tests/scaffold/functional.init.bats +++ b/tests/scaffold/functional.init.bats @@ -612,3 +612,71 @@ export SCRIPT_FILE="init.sh" assert_output_contains "Initialization complete." } + +@test "Init, Namespace invalid input has space, workflow" { + answers=( + "Yodas Hut" # organisation + "force-crystal" # project + "Jane Doe" # author + "nothing" # use PHP + "nothing" # use PHP Command + "nothing" # CLI command name + "nothing" # use PHP Command Build + "nothing" # use NodeJS + "nothing" # use Shell + "nothing" # Shell command name + "nothing" # use GitHub release drafter + "nothing" # use GitHub pr auto-assign + "nothing" # use GitHub funding + "nothing" # use GitHub PR template + "nothing" # use Renovate + "nothing" # remove docs + "nothing" # remove init script + "nothing" # proceed with init + ) + tui_run "${answers[@]}" + + assert_output_contains "Please follow the prompts to adjust your project configuration" + assert_files_present_common "${BUILD_DIR}" + assert_files_present_php "${BUILD_DIR}" + assert_files_present_nodejs "${BUILD_DIR}" + assert_files_present_shell "${BUILD_DIR}" + assert_workflow_php "${BUILD_DIR}" + assert_workflow_php_command_build "${BUILD_DIR}" + + assert_output_contains "Initialization complete." +} + +@test "Init, Namespace invalid input has hyphen, workflow" { + answers=( + "Yodas-Hut" # organisation + "force-crystal" # project + "Jane Doe" # author + "nothing" # use PHP + "nothing" # use PHP Command + "nothing" # CLI command name + "nothing" # use PHP Command Build + "nothing" # use NodeJS + "nothing" # use Shell + "nothing" # Shell command name + "nothing" # use GitHub release drafter + "nothing" # use GitHub pr auto-assign + "nothing" # use GitHub funding + "nothing" # use GitHub PR template + "nothing" # use Renovate + "nothing" # remove docs + "nothing" # remove init script + "nothing" # proceed with init + ) + tui_run "${answers[@]}" + + assert_output_contains "Please follow the prompts to adjust your project configuration" + assert_files_present_common "${BUILD_DIR}" + assert_files_present_php "${BUILD_DIR}" + assert_files_present_nodejs "${BUILD_DIR}" + assert_files_present_shell "${BUILD_DIR}" + assert_workflow_php "${BUILD_DIR}" + assert_workflow_php_command_build "${BUILD_DIR}" + + assert_output_contains "Initialization complete." +} diff --git a/tests/scaffold/unit.init.bats b/tests/scaffold/unit.init.bats index d474ee2..30ecb40 100644 --- a/tests/scaffold/unit.init.bats +++ b/tests/scaffold/unit.init.bats @@ -23,6 +23,10 @@ load "../../init.sh" "$input" "log_entry" "I am a_string-With spaces 13" "$input" "code_comment_title" "I am a_string-With spaces 13" "$input" "dummy_type" "Invalid conversion type" + "HelloWorld" "namespace" "HelloWorld" + "Hello World" "namespace" "HelloWorld" + "Hello world" "namespace" "HelloWorld" + "Hello-world" "namespace" "Helloworld" ) dataprovider_run "convert_string" 3