Skip to content

Commit

Permalink
[#172] Fixed invalid namespace handling in init.sh (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 authored May 3, 2024
1 parent 83c8cec commit cbc02e9
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
3 changes: 2 additions & 1 deletion init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:]'
Expand Down Expand Up @@ -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")"

Expand Down
68 changes: 68 additions & 0 deletions tests/scaffold/functional.init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
4 changes: 4 additions & 0 deletions tests/scaffold/unit.init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

1 comment on commit cbc02e9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.