diff --git a/.github/citools/includes/wrapper-library b/.github/citools/includes/wrapper-library index c16f8ca3..367dd941 100644 --- a/.github/citools/includes/wrapper-library +++ b/.github/citools/includes/wrapper-library @@ -25,6 +25,11 @@ run_command() { # md_code_tag } # run_command() +track_errors() { + ((retval++)) + printf "\nERROR: Failure detected in last command.\n" +} # track_errors() + print_ruler() { printf "\n " printf "=%.0s" {1..78} @@ -115,3 +120,34 @@ show_tool_versions_go() { # md_code_tag printf "\n" } # show_tool_versions_go() + +show_tool_versions_ruby_short() { + # md_code_tag text + printf "Ruby version:\n" + printf "\n" + ruby --version | paste /dev/null - + rbenv --version | paste /dev/null - + # md_code_tag + printf "\n" +} # show_tool_versions_ruby_short() + +show_tool_versions_ruby() { + # md_code_tag text + printf "Ruby version:\n" + printf "\n" + ruby --version | paste /dev/null - + rbenv --version | paste /dev/null - + # md_code_tag + printf "\n" + + if [[ -z ${GITHUB_ACTIONS} ]]; then + return + fi + + # md_code_tag text + printf "Installed Gem packages:\n" + printf "\n" + gem list | paste /dev/null - + # md_code_tag + printf "\n" +} # show_tool_versions_ruby() diff --git a/.github/citools/ruby/ruby-lint-rubycritic b/.github/citools/ruby/ruby-lint-rubycritic new file mode 100755 index 00000000..9d8dadb4 --- /dev/null +++ b/.github/citools/ruby/ruby-lint-rubycritic @@ -0,0 +1,28 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-lint-rubycritic +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +main() { + printf "\nRunning RubyCritic\n\n" + + show_tool_versions_ruby_short + + print_ruler + + # https://github.com/whitesmith/rubycritic + + run_command rubycritic --path .rubycritic --format console --no-browser . || ((retval++)) + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" diff --git a/.github/citools/ruby/ruby-setup-config b/.github/citools/ruby/ruby-setup-config new file mode 100755 index 00000000..e779a863 --- /dev/null +++ b/.github/citools/ruby/ruby-setup-config @@ -0,0 +1,24 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-setup-config +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +main() { + printf "Setup Ruby Environment\n\n" + + print_ruler + + printf "%s\n" "${HOME}/.rbenv/bin" "${HOME}/.rbenv/shims" | tee -a "${GITHUB_PATH}" + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" diff --git a/.github/citools/ruby/ruby-setup-install b/.github/citools/ruby/ruby-setup-install new file mode 100755 index 00000000..bdd766a3 --- /dev/null +++ b/.github/citools/ruby/ruby-setup-install @@ -0,0 +1,126 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-setup-install +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +main() { + printf "Ruby Installation\n\n" + + print_ruler + + echo Running: sudo apt update + time sudo apt update || track_errors + + print_ruler + + local -a debs + debs=( + autoconf + automake + bison + bc + build-essential + curl + g++ + gcc + git + gnupg + libc6-dev + libffi-dev + libgdbm-dev + libgmp-dev + libncurses5-dev + libreadline-dev + libsqlite3-dev + libssl-dev + libtool + libyaml-dev + make + pkg-config + sqlite3 + zlib1g-dev + ) + + echo Running: sudo apt install -y "${debs[@]}" + time sudo apt install -y "${debs[@]}" || track_errors + + print_ruler + + echo Running: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer \| bash + time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-installer | bash || track_errors + + print_ruler + + echo Running: rbenv -v + time rbenv -v || track_errors + + print_ruler + + printf "Configuring Shell: " + # shellcheck disable=SC2016 + { + echo 'export PATH="${HOME}/.rbenv/bin::${HOME}/.rbenv/bin/shims:${PATH}"' >>"${HOME}"/.bashrc + echo 'eval "$(rbenv init -)"' >>"${HOME}"/.bashrc + } + # shellcheck disable=SC1090 + source "${HOME}"/.bashrc || track_errors + printf "done\n" + + print_ruler + + echo Running: rbenv install --list + time rbenv install --list || track_errors + + print_ruler + + local ruby_version + ruby_version="$(rbenv install --list 2>/dev/null | grep '^3[.][0-9][.]' | tail -n 1)" || track_errors + + echo Running: rbenv install "${ruby_version}" + time rbenv install "${ruby_version}" || track_errors + + print_ruler + + echo Running: rbenv global "${ruby_version}" + time rbenv global "${ruby_version}" || track_errors + + print_ruler + + echo Running: ruby -v + time ruby -v || track_errors + + print_ruler + + local -a gems + gems=( + rspec + rspec-core + rspec-expectations + rspec-mocks + rspec-parameterized + rspec-support + rubycritic + simplecov + simplecov-cobertura + ) + + echo Running: gem install "${gems[@]}" + time gem install "${gems[@]}" || track_errors + + print_ruler + + echo Running: curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor \| bash + time curl -fsSL https://github.com/rbenv/rbenv-installer/raw/HEAD/bin/rbenv-doctor | bash || track_errors + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" diff --git a/.github/citools/ruby/ruby-setup-verify b/.github/citools/ruby/ruby-setup-verify new file mode 100755 index 00000000..c28cbfb2 --- /dev/null +++ b/.github/citools/ruby/ruby-setup-verify @@ -0,0 +1,58 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-setup-verify +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +declare -A ruby_cmds + +ruby_cmds=( + [ruby]=$( + command -v ruby >&/dev/null + echo "$?" + ) + [rubycritic]=$( + command -v rubycritic >&/dev/null + echo "$?" + ) +) + +main() { + printf "Verifying Ruby Installation\n\n" + + print_ruler + + printf "RBENV_SHELL=%s\n" "${RBENV_SHELL}" + printf "PATH=%s\n" "${PATH}" + + print_ruler + + echo Running: rbenv init - + time rbenv init - + + for key in "${!ruby_cmds[@]}"; do + if [[ ${ruby_cmds[${key}]} -ne 0 ]]; then + printf "ERROR: command [%s] not found.\n" "${key}" + ((retval++)) + fi + done + + if [[ ${retval} -ne 0 ]]; then + return "${retval}" + fi + + print_ruler + + show_tool_versions_ruby + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" diff --git a/.github/citools/ruby/ruby-test-with-coverage b/.github/citools/ruby/ruby-test-with-coverage new file mode 100755 index 00000000..b21db200 --- /dev/null +++ b/.github/citools/ruby/ruby-test-with-coverage @@ -0,0 +1,40 @@ +#!/bin/bash +# +# .github/citools/ruby/ruby-test-with-coverage +# + +# shellcheck disable=SC1091 +source ../../.github/citools/includes/wrapper-library || exit + +declare -i retval=0 + +main() { + printf "\nRunning Ruby Tests With Coverage\n\n" + + show_tool_versions_ruby_short + + print_ruler + + run_command rm -rf ./coverage + + print_ruler + + # https://github.com/simplecov-ruby/simplecov + # https://github.com/dashingrocket/simplecov-cobertura + # https://about.codecov.io/blog/getting-started-with-code-coverage-for-ruby/ + + run_command ruby ./*_test.rb -v || ((retval++)) + + print_ruler + + local coverage_raw + coverage_raw="$(xq -q coverage -a line-rate ./coverage/coverage.xml)" + printf "Coverage: %.1f%%\n" "$(bc <<<"scale=1; ${coverage_raw}* 100")" + + print_ruler + + echo Exit code: "${retval}" + return "${retval}" +} + +time main "${@}" diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml new file mode 100644 index 00000000..fc5abd89 --- /dev/null +++ b/.github/workflows/ruby.yml @@ -0,0 +1,214 @@ +--- +# +# .github/workflows/ruby.yml +# +name: Ruby Workflow 4.0 +on: # yamllint disable-line rule:truthy + pull_request: + workflow_dispatch: + +defaults: + run: + shell: bash + +jobs: + stage1: + name: Change Check + runs-on: 'ubuntu-latest' + outputs: + docs_changed: ${{ steps.check_file_changed.outputs.docs_changed }} + matrix_exercise: ${{ steps.check_file_changed.outputs.matrix_exercise }} + exercise_count: ${{ steps.check_file_changed.outputs.exercise_count }} + steps: + - name: Check GitHub Vars + id: github-vars-check + run: |- + { + printf "\`\`\`text\n" + printf "Runner environment info:\n" + set | grep -e ^CI -e ^GITHUB_ -e ^RUNNER_ + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + - name: Check GitHub User + id: github-user-check + run: |- + # get user info for default gh container + { + printf "\`\`\`text\n" + printf "Container user info:\n" + who + printf "\n" + id + printf "\n" + printf "HOME: %s\n" "${HOME}" + printf "\n" + printf "SHELL: %s\n" "$(getent passwd "${USER}" | awk -F: '{print $NF}')" + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + - name: Checkout Repo + id: checkout-repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{ github.ref }} + submodules: recursive + - name: Get Change List + id: check_file_changed + run: |- + { + printf "Workflow: %s\n\n" "${GITHUB_WORKFLOW}" + printf "Runner: name[%s] arch[%s]\n" "${RUNNER_NAME}" "${RUNNER_ARCH}" + printf "Repo: %s\n" "${GITHUB_REPOSITORY}" + printf "User: %s\n" "${GITHUB_TRIGGERING_ACTOR}" + printf "\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + + # Diff HEAD with the previous commit then output to stdout. + GIT_DIFF="$(git diff --name-only HEAD^ HEAD | tee /tmp/changed_files.txt)" + { + printf "=== Which files changed? ===\n" + printf "\`\`\`text\n" + printf "%s\n" "${GIT_DIFF}" + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + HAS_WF_DIFF=false + HAS_EX_DIFF=false + if printf "%s\n" "${GIT_DIFF}" | grep -E '^(.github/workflows/ruby.yml|.github/citools/ruby/)$'; then + HAS_WF_DIFF=true + fi + if printf "%s\n" "${GIT_DIFF}" | grep -E '^ruby/.*[.]rb$'; then + HAS_EX_DIFF=true + fi + printf "\n" + printf "=== Did WF/CI change without exercise changes? ===\n" + CI_FORCE_FULL=false + if ${HAS_WF_DIFF} && ! ${HAS_EX_DIFF}; then + CI_FORCE_FULL=true + printf "%s\n" "${CI_FORCE_FULL}" + fi + printf "\n" + + # Get changed exercise list. + if [[ ${GITHUB_EVENT_NAME} == pull_request ]] && ! ${CI_FORCE_FULL}; then + printf "Generating pull request changed exercise list.\n" + grep -E '^ruby/[-a-z0-9]+./.*$' /tmp/changed_files.txt | cut -f1,2 -d/ | sort -Vu | tee /tmp/exercises.txt || true + else + printf "Generating complete exercise list.\n" + find ./ruby/ -type d -print | grep -v -E '^[.]/ruby/(|[.].*)$' | sed -r -e 's:[.]/(ruby/[-a-z0-9]+)/?.*$:\1:g' | sort -Vu | tee /tmp/exercises.txt + HAS_DIFF=true + fi + printf "\n" + + # Check if the files are present in the changed file list (added, modified, deleted) then output to stdout. + HAS_DIFF="${HAS_DIFF:-false}" + printf "=== Which Ruby files changed? ===\n" + if printf "%s\n" "${GIT_DIFF}" | grep -E '^(ruby/.*[.]rb|.github/workflows/ruby.yml|.github/citools/ruby/)$'; then + HAS_DIFF=true + printf "%s\n" "${HAS_DIFF}" + fi + printf "\n" + + # Did Ruby files change? + printf "=== Did Ruby files change? ===\n" + printf "%s\n" "${HAS_DIFF}" + printf "\n" + + # Generate exercise job matrix from changed files list. + printf "=== Generating matrix exercise list. ===\n" + declare -i last=0 + declare -i count=0 + last=$(wc -l /tmp/exercises.txt | cut -f1 -d\ ) + ((last -= 1)) || true + entries="" + while read -r line; do + if [[ ! ${count} -lt ${last} ]]; then + comma="" + else + comma="," + fi + printf -v entry "\"%s\"%s\n" "${line}" "${comma}" + ((count += 1)) + entries+="${entry}" + done < <(sort -V /tmp/exercises.txt) + jq --sort-keys . >/tmp/exercises.json <> "${GITHUB_OUTPUT}" + check-matrix: + runs-on: ubuntu-latest + needs: stage1 + steps: + - name: Install json2yaml + run: sudo npm install -g json2yaml + - name: Check matrix::exercises + run: |- + exercise_count='${{ needs.stage1.outputs.exercise_count }}' + matrix_exercise='${{ needs.stage1.outputs.matrix_exercise }}' + { + printf "\`\`\`text\n" + printf "exercise_count=%s\n" "${exercise_count}" + printf "matrix_exercise=%s\n" "${matrix_exercise}" + printf "\`\`\`\n" + printf "json:\n" + printf "\`\`\`text\n" + printf "%s" "${matrix_exercise}" | jq . + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + { + printf "yaml:\n" + printf "\`\`\`text\n" + printf "{ \"matrix\": { \"exercise\": %s } }" "${matrix_exercise}" | json2yaml + printf "\`\`\`\n" + } | tee -a "${GITHUB_STEP_SUMMARY}" + stage2: + name: Ruby Checks + strategy: + matrix: + os: ["ubuntu-latest", "windows-latest", "macos-latest"] + exclude: + - os: "macos-latest" + - os: "windows-latest" + exercise: ${{fromJson(needs.stage1.outputs.matrix_exercise)}} + runs-on: "${{ matrix.os }}" + container: + image: vpayno/ci-generic-debian:latest + needs: [stage1] + if: needs.stage1.outputs.docs_changed == 'true' + steps: + - name: Checkout Repo [${{ matrix.exercise }}] + id: checkout-repo + uses: actions/checkout@v3 + - name: Config Ruby Tools [${{ matrix.exercise }}] + id: config-ruby-tools + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-setup-config + - name: Install Ruby Tools [${{ matrix.exercise }}] + id: install-ruby-tools + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-setup-install + - name: Show Ruby version [${{ matrix.exercise }}] + id: ruby-version + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-setup-verify + - name: Analysing the code with cargo check [${{ matrix.exercise }}] + id: cargo-check + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-lint-rubycritic + - name: Testing with cargo test coverage [${{ matrix.exercise }}] + id: cargo-test-coverage + run: |- + ./.github/citools/common/run_wrapper_script "./${{ matrix.exercise }}" ../../.github/citools/ruby/ruby-test-with-coverage diff --git a/.gitignore b/.gitignore index 77b30143..49b6cd4a 100644 --- a/.gitignore +++ b/.gitignore @@ -77,3 +77,6 @@ rust/index.scip # tcl # vimscript + +# ruby +# coverage diff --git a/README.md b/README.md index f4a45920..d898e100 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ Exercism Workspace [![Common Lisp Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/common-lisp.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/common-lisp.yml) [![C Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/c.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/c.yml) [![CPP Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/cpp.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/cpp.yml) +[![Ruby Workflow](https://github.com/vpayno/exercism-workspace/actions/workflows/ruby.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/ruby.yml) [![Git PR Checks](https://github.com/vpayno/exercism-workspace/actions/workflows/git-pr.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/git-pr.yml) [![Check Links](https://github.com/vpayno/exercism-workspace/actions/workflows/links.yml/badge.svg)](https://github.com/vpayno/exercism-workspace/actions/workflows/links.yml) @@ -128,6 +129,7 @@ Exercism Workspace - [Common Lisp Workflow](.github/workflows/common-lisp.yml) - [C Workflow](.github/workflows/c.yml) - [C++ Workflow](.github/workflows/cpp.yml) +- [Ruby Workflow](.github/workflows/ruby.yml) - [Link Checker Workflow](.github/workflows/links.yml) - [CodeQL Workflow](.github/workflows/codeql-analysis.yml) - [Woke PR](.github/workflows/woke-pr.yml) @@ -149,6 +151,7 @@ Exercism Workspace - [Common Lisp](common-lisp/README.md) - [C](c/README.md) - [C++](cpp/README.md) +- [Ruby](ruby/README.md) ## Tools/Scripts @@ -166,3 +169,4 @@ Exercism Workspace - [Common Lisp run-tests](./common-lisp/run-tests) - [C run-tests](./c/run-tests) - [C++ run-tests](./cpp/run-tests) +- [Ruby run-tests](./ruby/run-tests) diff --git a/ruby/README.md b/ruby/README.md new file mode 100644 index 00000000..3efcdf78 --- /dev/null +++ b/ruby/README.md @@ -0,0 +1,16 @@ +# Exercism Ruby Track + +[Home Page](https://exercism.org/tracks/ruby) + +[My Profile](https://exercism.org/profiles/vpayno) + +## Tools + +- [for_each](./for_each) +- [run-tests](./run-tests) +- [submit_files](./submit_files) +- [update_readmes](./update_readmes) + +## [Exercises](https://exercism.org/tracks/ruby/exercises) + +- [hello-world](./hello-world/README.md) diff --git a/ruby/for_each b/ruby/for_each new file mode 100755 index 00000000..717b1149 --- /dev/null +++ b/ruby/for_each @@ -0,0 +1,24 @@ +#!/bin/bash + +declare -i retval=0 +declare pkg_name +declare d + +time for d in ./*; do + [[ -d ${d} ]] || continue + cd "${d}" || continue + printf "[dir: %s]\n\n" "${PWD}" + + pkg_name="$(basename "${PWD}")" + + printf "[pkg: %s]\n\n" "${pkg_name}" + + echo "${@}" + time "${@}" || ((retval++)) + + printf "\n" + + cd - || break +done + +exit "${retval}" diff --git a/ruby/hello-world/.exercism/config.json b/ruby/hello-world/.exercism/config.json new file mode 100644 index 00000000..f38024e0 --- /dev/null +++ b/ruby/hello-world/.exercism/config.json @@ -0,0 +1,39 @@ +{ + "authors": [ + "ramonh" + ], + "contributors": [ + "abartov", + "bgrabow", + "budmc29", + "gilmatic", + "hilary", + "iHiD", + "Insti", + "jpotts244", + "Kosmas", + "kotp", + "kytrinyx", + "mike-hewitson", + "NeimadTL", + "sivabudh", + "skeskali", + "thejoycekung", + "trayo", + "tryantwit" + ], + "files": { + "solution": [ + "hello_world.rb" + ], + "test": [ + "hello_world_test.rb" + ], + "example": [ + ".meta/example.rb" + ] + }, + "blurb": "The classical introductory exercise. Just say \"Hello, World!\".", + "source": "This is an exercise to introduce users to using Exercism", + "source_url": "https://en.wikipedia.org/wiki/%22Hello,_world!%22_program" +} diff --git a/ruby/hello-world/.exercism/metadata.json b/ruby/hello-world/.exercism/metadata.json new file mode 100644 index 00000000..89b03e35 --- /dev/null +++ b/ruby/hello-world/.exercism/metadata.json @@ -0,0 +1 @@ +{"track":"ruby","exercise":"hello-world","id":"b1dd6717fcb54524b591175ff6a60ade","url":"https://exercism.org/tracks/ruby/exercises/hello-world","handle":"vpayno","is_requester":true,"auto_approve":false} \ No newline at end of file diff --git a/ruby/hello-world/.rubycritic/lint.txt b/ruby/hello-world/.rubycritic/lint.txt new file mode 100644 index 00000000..3966a05e --- /dev/null +++ b/ruby/hello-world/.rubycritic/lint.txt @@ -0,0 +1,3 @@ +hello_world.rb:1: (IrresponsibleModule) HelloWorld has no descriptive comment + +hello_world_test.rb:28: (IrresponsibleModule) HelloWorldTest has no descriptive comment diff --git a/ruby/hello-world/HELP.md b/ruby/hello-world/HELP.md new file mode 100644 index 00000000..4388e216 --- /dev/null +++ b/ruby/hello-world/HELP.md @@ -0,0 +1,54 @@ +# Help + +## Running the tests + +For running the tests provided, you will need the Minitest gem. Open a +terminal window and run the following command to install minitest: + +``` +gem install minitest +``` + + +Run the tests from the exercise directory using the following command: + +``` +ruby _test.rb +``` + +Please replace `` with your exercise name in snake_case. + +## Color output + +You can `require 'minitest/pride'` or run the following command to get colored output: + +``` +ruby -r minitest/pride _test.rb +``` + +## Submitting your solution + +You can submit your solution using the `exercism submit hello_world.rb` command. +This command will upload your solution to the Exercism website and print the solution page's URL. + +It's possible to submit an incomplete solution which allows you to: + +- See how others have completed the exercise +- Request help from a mentor + +## Need to get help? + +If you'd like help solving the exercise, check the following pages: + +- The [Ruby track's documentation](https://exercism.org/docs/tracks/ruby) +- The [Ruby track's programming category on the forum](https://forum.exercism.org/c/programming/ruby) +- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5) +- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs) + +Should those resources not suffice, you could submit your (incomplete) solution to request mentoring. + +To get help if you're having trouble, you can use one of the following resources: + +- [Ruby Documentation](http://ruby-doc.org/) +- [StackOverflow](http://stackoverflow.com/questions/tagged/ruby) +- [/r/ruby](https://www.reddit.com/r/ruby) is the Ruby subreddit. \ No newline at end of file diff --git a/ruby/hello-world/README.md b/ruby/hello-world/README.md new file mode 100644 index 00000000..3f7fdf4c --- /dev/null +++ b/ruby/hello-world/README.md @@ -0,0 +1,57 @@ +# Hello World + +Welcome to Hello World on Exercism's Ruby Track. +If you need help running the tests or submitting your code, check out `HELP.md`. + +## Instructions + +The classical introductory exercise. +Just say "Hello, World!". + +["Hello, World!"][hello-world] is the traditional first program for beginning programming in a new language or environment. + +The objectives are simple: + +- Modify the provided code so that it produces the string "Hello, World!". +- Run the test suite and make sure that it succeeds. +- Submit your solution and check it at the website. + +If everything goes well, you will be ready to fetch your first real exercise. + +[hello-world]: https://en.wikipedia.org/wiki/%22Hello,_world!%22_program + +## Source + +### Created by + +- @ramonh + +### Contributed to by + +- @abartov +- @bgrabow +- @budmc29 +- @gilmatic +- @hilary +- @iHiD +- @Insti +- @jpotts244 +- @Kosmas +- @kotp +- @kytrinyx +- @mike-hewitson +- @NeimadTL +- @sivabudh +- @skeskali +- @thejoycekung +- @trayo +- @tryantwit + +### Based on + +This is an exercise to introduce users to using Exercism - https://en.wikipedia.org/wiki/%22Hello,_world!%22_program + +### My Solution + +- [my solution](./hello_world.rb) +- [run-tests](./run-tests-ruby.txt) diff --git a/ruby/hello-world/coverage/.last_run.json b/ruby/hello-world/coverage/.last_run.json new file mode 100644 index 00000000..52d2bf29 --- /dev/null +++ b/ruby/hello-world/coverage/.last_run.json @@ -0,0 +1,5 @@ +{ + "result": { + "line": 100.0 + } +} diff --git a/ruby/hello-world/coverage/.resultset.json b/ruby/hello-world/coverage/.resultset.json new file mode 100644 index 00000000..5e765975 --- /dev/null +++ b/ruby/hello-world/coverage/.resultset.json @@ -0,0 +1,16 @@ +{ + "test:exercism": { + "coverage": { + "/home/vpayno/git_vpayno/exercism-workspace/ruby/hello-world/hello_world.rb": { + "lines": [ + 1, + 1, + 1, + null, + null + ] + } + }, + "timestamp": 1696313634 + } +} diff --git a/ruby/hello-world/coverage/.resultset.json.lock b/ruby/hello-world/coverage/.resultset.json.lock new file mode 100644 index 00000000..e69de29b diff --git a/ruby/hello-world/coverage/coverage.xml b/ruby/hello-world/coverage/coverage.xml new file mode 100644 index 00000000..c15d48be --- /dev/null +++ b/ruby/hello-world/coverage/coverage.xml @@ -0,0 +1,22 @@ + + + + + + /home/vpayno/git_vpayno/exercism-workspace/ruby/hello-world + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ruby/hello-world/hello_world.rb b/ruby/hello-world/hello_world.rb new file mode 100644 index 00000000..a89cc196 --- /dev/null +++ b/ruby/hello-world/hello_world.rb @@ -0,0 +1,5 @@ +class HelloWorld + def self.hello + "Hello, World!" + end +end diff --git a/ruby/hello-world/hello_world_test.rb b/ruby/hello-world/hello_world_test.rb new file mode 100644 index 00000000..4fdccd44 --- /dev/null +++ b/ruby/hello-world/hello_world_test.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: false + +# https://github.com/simplecov-ruby/simplecov +require 'simplecov' + +# https://about.codecov.io/blog/getting-started-with-code-coverage-for-ruby/ +require 'simplecov-cobertura' +SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter + +# line coverage +SimpleCov.start if ENV['COVERAGE'] != 'branch' + +# branch coverage +if ENV['COVERAGE'] == 'branch' + SimpleCov.start do + enable_coverage :branch + primary_coverage :branch + end +end + +# name the test file/group +SimpleCov.command_name 'test:exercism' + +# original exercism tests +require 'minitest/autorun' +require_relative 'hello_world' + +class HelloWorldTest < Minitest::Test + def test_say_hi + # skip + assert_equal "Hello, World!", HelloWorld.hello + end +end diff --git a/ruby/hello-world/run-tests-ruby.txt b/ruby/hello-world/run-tests-ruby.txt new file mode 100644 index 00000000..d997d0c3 --- /dev/null +++ b/ruby/hello-world/run-tests-ruby.txt @@ -0,0 +1,137 @@ +Running automated test file(s): + + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-lint-rubycritic + +Running RubyCritic + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + + + ============================================================================== + +Running: rubycritic --path .rubycritic --format console --no-browser . + +running flay smells + +running flog smells +.. +running reek smells +.. +running complexity +.. +running attributes +.. +running churn +.. +running simple_cov +.. +/home/vpayno/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubycritic-4.6.1/lib/rubycritic/generators/text/list.rb:13: warning: Passing safe_level with the 2nd argument of ERB.new is deprecated. Do not use it, and specify other arguments as keyword arguments. +/home/vpayno/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/rubycritic-4.6.1/lib/rubycritic/generators/text/list.rb:13: warning: Passing trim_mode with the 3rd argument of ERB.new is deprecated. Use keyword argument like ERB.new(str, trim_mode: ...) instead. +HelloWorld: + Rating: A + Churn: 0 + Complexity: 0.0 + Duplication: 0 + Smells: 1 + * (IrresponsibleModule) HelloWorld has no descriptive comment + - hello_world.rb:1 + +HelloWorldTest: + Rating: A + Churn: 0 + Complexity: 2.4 + Duplication: 0 + Smells: 1 + * (IrresponsibleModule) HelloWorldTest has no descriptive comment + - hello_world_test.rb:28 +Score: 99.7 + +real 0m0.610s +user 0m0.479s +sys 0m0.130s + + + ============================================================================== + +Exit code: 0 + +real 0m0.660s +user 0m0.495s +sys 0m0.165s + +real 0m0.664s +user 0m0.497s +sys 0m0.167s + +=============================================================================== + +Running: ../../.github/citools/ruby/ruby-test-with-coverage + +Running Ruby Tests With Coverage + +Ruby version: + + ruby 3.1.1p18 (2022-02-18 revision 53f5fc4236) [x86_64-linux] + + + ============================================================================== + +Running: rm -rf ./coverage + + +real 0m0.001s +user 0m0.000s +sys 0m0.001s + + + ============================================================================== + +Running: ruby ./hello_world_test.rb -v + +Run options: -v --seed 41052 + +# Running: + +HelloWorldTest#test_say_hi = 0.00 s = . + +Finished in 0.001509s, 662.5219 runs/s, 662.5219 assertions/s. + +1 runs, 1 assertions, 0 failures, 0 errors, 0 skips +Coverage report generated for test:exercism to /home/vpayno/git_vpayno/exercism-workspace/ruby/hello-world/coverage/coverage.xml. 3 / 3 LOC (100.00%) covered + +real 0m0.171s +user 0m0.125s +sys 0m0.046s + + + ============================================================================== + +Exit code: 0 + +real 0m0.209s +user 0m0.139s +sys 0m0.072s + +real 0m0.211s +user 0m0.140s +sys 0m0.074s + +=============================================================================== + +Running: misspell . + +real 0m0.026s +user 0m0.020s +sys 0m0.019s + +=============================================================================== + +/home/vpayno/git_vpayno/exercism-workspace/ruby + +=============================================================================== + diff --git a/ruby/run-tests b/ruby/run-tests new file mode 100755 index 00000000..859b95c0 --- /dev/null +++ b/ruby/run-tests @@ -0,0 +1,39 @@ +#!/bin/bash + +print_ruler() { + printf "\n" + printf "=%.0s" {1..79} + printf "\n" + printf "\n" +} # print_ruler() + +main() { + printf "Running automated test file(s):\n\n" + + print_ruler + + echo Running: ../../.github/citools/ruby/ruby-lint-rubycritic + time ../../.github/citools/ruby/ruby-lint-rubycritic + + print_ruler + + echo Running: ../../.github/citools/ruby/ruby-test-with-coverage + time ../../.github/citools/ruby/ruby-test-with-coverage + + print_ruler + + # go install github.com/client9/misspell/cmd/misspell@latest + # still looking for a working version for ruby + + echo Running: misspell . + time misspell . + + print_ruler + + cd .. + pwd + + print_ruler +} # main() + +time main "$@" |& tee ./run-tests-ruby.txt diff --git a/ruby/submit_files b/ruby/submit_files new file mode 100755 index 00000000..e8e6213f --- /dev/null +++ b/ruby/submit_files @@ -0,0 +1,38 @@ +#!/bin/bash + +if [[ ! -d .exercism ]]; then + printf "ERROR: Run from inside a project directory.\n\n" + exit 1 +fi + +# declare package_name_snake + +get_track_package_name() { + # these are kebab-case + basename "${PWD}" +} # get_track_package_name() + +kebab_case_to_pascal_case() { + printf "%s" "${@}" | sed -r -e 's/(^|[-])(\w)/\U\2/g' +} # kebab_case_to_pascal_case() + +kebab_case_to_camel_case() { + printf "%s" "${@}" | sed -r -e 's/([-])(\w)/\U\2/g' +} # kebab_case_to_camel_case() + +kebab_case_to_snake_case() { + printf "%s" "${@}" | sed -r -e 's/(\w)([-])(\w)/\1_\3/g' +} # kebab_case_to_snake_case() + +package_name_snake="$(kebab_case_to_snake_case "$(get_track_package_name)")" + +declare -a RUBY_FILES=("./${package_name_snake}.rb" ./run-tests-ruby.txt) + +# mapfile -t RUBY_FILES < <( +# find . -type f -name "*[.]go" | grep -v "_test[.]go" +# find . -type f -name "*_examples_test[.]go" +#) + +echo Running: exercism submit "${RUBY_FILES[@]}" +time exercism submit "${RUBY_FILES[@]}" +printf "\n" diff --git a/ruby/update_readmes b/ruby/update_readmes new file mode 100755 index 00000000..2137498f --- /dev/null +++ b/ruby/update_readmes @@ -0,0 +1,78 @@ +#!/bin/bash + +shopt -s nullglob + +if [[ ! -d .exercism ]]; then + printf "ERROR: Run from inside a project directory.\n\n" + exit 1 +fi + +declare package_name +declare project_dir + +get_track_package_name() { + basename "${PWD}" +} # get_track_package_name() + +package_name="$(get_track_package_name)" +project_dir="$(basename "${PWD}")" + +if ! grep -q ./"${project_dir}"/README.md ../README.md; then + + cat >>../README.md <>./README.md <