diff options
author | Ben Hilburn <bhilburn@gmail.com> | 2015-04-02 19:10:12 +0300 |
---|---|---|
committer | Ben Hilburn <bhilburn@gmail.com> | 2015-04-02 19:10:12 +0300 |
commit | 6d07fccaf2ffb7e2343fbde1d00899d8d2811d24 (patch) | |
tree | 78e3b50390d2e3d68b6d65653d0f51810da22f5b | |
parent | 393e1c827b921f31cc0d74c9bf65076b69876708 (diff) | |
parent | 4ad84c0936cde7549e46d85a05d3586946a28fef (diff) |
Merge pull request #19 from dritter/dritter/test-ratio
Show a ratio of test classes vs real classes (Ruby and Symfony2)
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | powerlevel9k.zsh-theme | 35 |
2 files changed, 37 insertions, 0 deletions
@@ -76,7 +76,9 @@ currently available are: * **dir** - Your current working directory. * **history** - The command number for the current line. * **rbenv** - Ruby environment information (if one is active). +* **rspec_stats** - Show a ratio of test classes vs code classes for RSpec. * **status** - The return code of the previous command, and status of background jobs. +* **symfony2_tests** - Show a ratio of test classes vs code classes for Symfony2. * **time** - System time. * **vcs** - Information about this `git` or `hg` repository (if you are in one). diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 443f7cc3..b13b2159 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -310,6 +310,41 @@ prompt_aws() { fi } +# RSpec test ratio +prompt_rspec_stats() { + if [[ (-d app && -d spec) ]]; then + local code_amount=$(ls -1 app/**/*.rb | wc -l) + local tests_amount=$(ls -1 spec/**/*.rb | wc -l) + + build_test_stats $1 $code_amount $tests_amount "RSpec" + fi +} + +# Symfony2-PHPUnit test ratio +prompt_symfony2_tests() { + if [[ (-d src && -d app && -f app/AppKernel.php) ]]; then + local code_amount=$(ls -1 src/**/*.php | grep -v Tests | wc -l) + local tests_amount=$(ls -1 src/**/*.php | grep Tests | wc -l) + + build_test_stats $1 $code_amount $tests_amount "SF2-Tests" + fi +} + +# Show a ratio of tests vs code +build_test_stats() { + local code_amount=$2 + local tests_amount=$3+0.00001 + local headline=$4 + + # Set float precision to 2 digits: + typeset -F 2 ratio + local ratio=$(( (tests_amount/code_amount) * 100 )) + + [[ ratio -ge 0.75 ]] && $1_prompt_segment cyan $DEFAULT_COLOR "$headline: $ratio%%" + [[ ratio -ge 0.5 && ratio -lt 0.75 ]] && $1_prompt_segment yellow $DEFAULT_COLOR "$headline: $ratio%%" + [[ ratio -lt 0.5 ]] && $1_prompt_segment red $DEFAULT_COLOR "$headline: $ratio%%" +} + # Main prompt build_left_prompt() { if [[ ${#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS} == 0 ]]; then |