From 085610cccf8b1ad4731588ec2c2713283bb597d2 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 1 Apr 2015 03:51:19 +0200 Subject: [PATCH 1/6] Display a tests vs code ratio (RSpec and Symfony2-PHPUnit-tests). --- powerlevel9k.zsh-theme | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 86c16ecb..9d823ff3 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -294,6 +294,41 @@ prompt_aws() { fi } +# RSpec test ratio +prompt_rspec_stats() { + if [[ (-d app && -d spec) ]]; then + local code_amount=$(wc -l app/**/*.rb | grep -oE "[0-9]+" | tail -n 1) + local tests_amount=$(wc -l spec/**/*.rb | grep -oE "[0-9]+" | tail -n 1) + + 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.01 + 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 From 18cbe235b8e4f7e5ef30937664a5afbcdb887e47 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 01:59:02 +0200 Subject: [PATCH 2/6] Added documentation. --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 100fd588..1782e15f 100644 --- a/README.md +++ b/README.md @@ -75,7 +75,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** - 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). From a06c53902d626af6a7b2eb7152082dba9ccf4c5f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 02:17:25 +0200 Subject: [PATCH 3/6] Whitespace. --- powerlevel9k.zsh-theme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 53f5023d..f279f994 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -336,9 +336,9 @@ build_test_stats() { local tests_amount=$3+0.01 local headline=$4 - # Set float precision to 2 digits: - typeset -F 2 ratio - local ratio=$(( (tests_amount/code_amount) * 100 )) + # 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%%" From aadf37bd35c960fd337f73f78b91774e2ee13b0f Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 09:43:57 +0200 Subject: [PATCH 4/6] Documentation is now correct. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6ab7870..cb72bcde 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ 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** - Show a ratio of test classes vs code classes for RSpec. +* **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. From 94af6aae4335a01b522cc1379d6e1ff96025e3fb Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 09:49:26 +0200 Subject: [PATCH 5/6] Better implementation of counting Classes and Tests for RSpec. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index f279f994..92efcaee 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -313,8 +313,8 @@ prompt_aws() { # RSpec test ratio prompt_rspec_stats() { if [[ (-d app && -d spec) ]]; then - local code_amount=$(wc -l app/**/*.rb | grep -oE "[0-9]+" | tail -n 1) - local tests_amount=$(wc -l spec/**/*.rb | grep -oE "[0-9]+" | tail -n 1) + 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 From 4ad84c0936cde7549e46d85a05d3586946a28fef Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Thu, 2 Apr 2015 09:54:40 +0200 Subject: [PATCH 6/6] Improved correction factor, so that the ratio is a nice percentage. --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 92efcaee..b13b2159 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -333,7 +333,7 @@ prompt_symfony2_tests() { # Show a ratio of tests vs code build_test_stats() { local code_amount=$2 - local tests_amount=$3+0.01 + local tests_amount=$3+0.00001 local headline=$4 # Set float precision to 2 digits: