bashcov 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -3
  3. data/Gemfile +2 -0
  4. data/Guardfile +2 -0
  5. data/LICENSE.txt +1 -1
  6. data/README.md +60 -5
  7. data/Rakefile +2 -0
  8. data/bashcov.gemspec +4 -3
  9. data/bin/bashcov +3 -2
  10. data/lib/bashcov/bash_info.rb +32 -0
  11. data/lib/bashcov/errors.rb +16 -0
  12. data/lib/bashcov/field_stream.rb +77 -0
  13. data/lib/bashcov/lexer.rb +13 -7
  14. data/lib/bashcov/line.rb +4 -2
  15. data/lib/bashcov/runner.rb +96 -21
  16. data/lib/bashcov/version.rb +4 -1
  17. data/lib/bashcov/xtrace.rb +150 -35
  18. data/lib/bashcov.rb +64 -31
  19. metadata +9 -58
  20. data/.gitignore +0 -19
  21. data/.rspec +0 -4
  22. data/.rubocop.yml +0 -27
  23. data/.travis.yml +0 -21
  24. data/spec/bashcov/lexer_spec.rb +0 -11
  25. data/spec/bashcov/runner_spec.rb +0 -98
  26. data/spec/bashcov_spec.rb +0 -82
  27. data/spec/spec_helper.rb +0 -25
  28. data/spec/support/common.rb +0 -7
  29. data/spec/support/test_app.rb +0 -35
  30. data/spec/test_app/.simplecov +0 -2
  31. data/spec/test_app/README.md +0 -1
  32. data/spec/test_app/never_called.sh +0 -4
  33. data/spec/test_app/scripts/README.md +0 -1
  34. data/spec/test_app/scripts/case.sh +0 -15
  35. data/spec/test_app/scripts/delete.sh +0 -9
  36. data/spec/test_app/scripts/executable +0 -4
  37. data/spec/test_app/scripts/exit_non_zero.sh +0 -3
  38. data/spec/test_app/scripts/function.sh +0 -20
  39. data/spec/test_app/scripts/long_line.sh +0 -7
  40. data/spec/test_app/scripts/multiline.sh +0 -24
  41. data/spec/test_app/scripts/nested/simple.sh +0 -13
  42. data/spec/test_app/scripts/one_liner.sh +0 -9
  43. data/spec/test_app/scripts/simple.sh +0 -13
  44. data/spec/test_app/scripts/source.sh +0 -6
  45. data/spec/test_app/scripts/sourced.txt +0 -4
  46. data/spec/test_app/scripts/unicode.sh +0 -4
  47. data/spec/test_app/test_suite.sh +0 -5
data/spec/bashcov_spec.rb DELETED
@@ -1,82 +0,0 @@
1
- require "spec_helper"
2
-
3
- shared_examples "a fatal error" do
4
- it "outputs to stderr" do
5
- expect($stderr).to receive(:write).at_least(:once)
6
- ignore_exception(SystemExit) { subject }
7
- end
8
-
9
- it "exits with non-zero" do
10
- expect { subject }.to raise_error { |error|
11
- expect(error).to be_a SystemExit
12
- expect(error.status).not_to eq(0)
13
- }
14
- end
15
- end
16
-
17
- describe Bashcov do
18
- it "preserves the exit status" do
19
- system("./bin/bashcov ./spec/test_app/scripts/exit_non_zero.sh")
20
- expect($?.exitstatus).not_to eq(0)
21
- end
22
-
23
- describe ".parse_options!" do
24
- before { @args = [] }
25
-
26
- subject { Bashcov.parse_options! @args }
27
-
28
- context "without any options" do
29
- it_behaves_like "a fatal error"
30
- end
31
-
32
- context "with a filename" do
33
- before { @args << "script.sh" }
34
-
35
- context "with the --skip-uncovered flag" do
36
- before { @args << "--skip-uncovered" }
37
-
38
- it "sets it properly" do
39
- subject
40
- expect(Bashcov.options.skip_uncovered).to be true
41
- end
42
- end
43
-
44
- context "with the --mute flag" do
45
- before { @args << "--mute" }
46
-
47
- it "sets it properly" do
48
- subject
49
- expect(Bashcov.options.mute).to be true
50
- end
51
- end
52
-
53
- context "with the --help flag" do
54
- before { @args << "--help" }
55
-
56
- it_behaves_like "a fatal error"
57
- end
58
-
59
- context "with the --version flag" do
60
- before { @args << "--version" }
61
-
62
- it "outputs to stdout" do
63
- expect($stdout).to receive(:write).at_least(:once)
64
- ignore_exception(SystemExit) { subject }
65
- end
66
-
67
- it "exits with zero" do
68
- expect { subject }.to raise_error { |error|
69
- expect(error).to be_a SystemExit
70
- expect(error.status).to eq(0)
71
- }
72
- end
73
- end
74
- end
75
- end
76
-
77
- describe ".name" do
78
- it "includes the version" do
79
- expect(Bashcov.name).to include Bashcov::VERSION
80
- end
81
- end
82
- end
data/spec/spec_helper.rb DELETED
@@ -1,25 +0,0 @@
1
- unless RUBY_ENGINE == "rbx" # coverage support is broken on rbx
2
- require "simplecov"
3
- require "coveralls"
4
-
5
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter
8
- ]
9
- SimpleCov.start do
10
- minimum_coverage 100
11
- add_group "Sources", "lib"
12
- add_group "Tests", "spec"
13
- end
14
- end
15
-
16
- require "bashcov"
17
-
18
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |file| require file }
19
-
20
- RSpec.configure do |config|
21
- config.before(:each) do
22
- Bashcov.set_default_options!
23
- Bashcov.options.mute = true # don't print testsuite output
24
- end
25
- end
@@ -1,7 +0,0 @@
1
- # Common helpers
2
-
3
- def ignore_exception(exception)
4
- yield
5
- rescue exception
6
- nil
7
- end
@@ -1,35 +0,0 @@
1
- def test_app
2
- File.expand_path("../../test_app", __FILE__)
3
- end
4
-
5
- def test_suite
6
- "#{test_app}/test_suite.sh"
7
- end
8
-
9
- def uncovered_files
10
- ["#{test_app}/never_called.sh"]
11
- end
12
-
13
- def expected_coverage
14
- {
15
- "#{test_app}/never_called.sh" => [nil, nil, 0],
16
- "#{test_app}/scripts/case.sh" => [nil, nil, nil, 6, 1, nil, 0, 0, 1, nil, nil, nil, 1, 1],
17
- "#{test_app}/scripts/delete.sh" => [nil, nil, 1, nil, 0, 0, nil, 1, 1],
18
- "#{test_app}/scripts/function.sh" => [nil, nil, nil, 2, nil, nil, nil, 1, 1, nil, nil, nil, nil, 1, nil, nil, 1, 1, 1],
19
- "#{test_app}/scripts/long_line.sh" => [nil, nil, 1, 1, 1, 0],
20
- "#{test_app}/scripts/nested/simple.sh" => [nil, nil, nil, nil, 1, 1, nil, 0, nil, nil, 1],
21
- "#{test_app}/scripts/one_liner.sh" => [nil, nil, 2, nil, 1, nil, 0],
22
- "#{test_app}/scripts/simple.sh" => [nil, nil, nil, nil, 1, 1, nil, 0, nil, nil, 1],
23
- "#{test_app}/scripts/source.sh" => [nil, nil, 1, nil, 2],
24
- "#{test_app}/scripts/sourced.txt" => [nil, nil, 1],
25
- "#{test_app}/scripts/unicode.sh" => [nil, nil, nil, 1],
26
- "#{test_app}/scripts/multiline.sh" => [nil, nil, nil, 1, nil, 0, nil, 1, nil, 1, nil, 0, nil, nil, 1, 2, 1, 1, 0, nil, nil, 0, 1, 2],
27
- "#{test_app}/scripts/executable" => [nil, nil, 1],
28
- "#{test_app}/scripts/exit_non_zero.sh" => [nil, nil, 1],
29
- "#{test_app}/test_suite.sh" => [nil, nil, 2, nil, 1],
30
- }
31
- end
32
-
33
- def correct_coverage
34
- expected_coverage.merge!("#{test_app}/scripts/multiline.sh" => [nil, nil, 1, 2, 1, 1, 0, nil, nil, 1, 1, 1])
35
- end
@@ -1,2 +0,0 @@
1
- SimpleCov.add_group 'Bash Scripts', '\.sh$'
2
- SimpleCov.add_group 'Nested scripts', '/nested'
@@ -1 +0,0 @@
1
- I'm just a README, I shouldn't interfere with anything.
@@ -1,4 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo "I'm never executed by any script"
4
-
@@ -1 +0,0 @@
1
- I'm just a README, I shouldn't interfere with anything.
@@ -1,15 +0,0 @@
1
- #!/bin/bash
2
-
3
- function switch() {
4
- case $1 in
5
- -h|--help) echo help
6
- ;;
7
- -v|--version)
8
- echo version;;
9
- *) echo "what?";;
10
- esac
11
- }
12
-
13
- switch -h
14
- switch bug
15
-
@@ -1,9 +0,0 @@
1
- #!/bin/bash
2
-
3
- cat > tmp.sh <<'BASH'
4
- #!/bin/bash
5
- rm -v $0
6
- BASH
7
-
8
- chmod +x tmp.sh
9
- ./tmp.sh
@@ -1,4 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo "Although I'm extension-less, I am an executable Bash script"
4
-
@@ -1,3 +0,0 @@
1
- #!/bin/bash
2
-
3
- exit 21
@@ -1,20 +0,0 @@
1
- #!/bin/bash
2
-
3
- function f1 {
4
- echo f1
5
- }
6
-
7
- f2() {
8
- f1
9
- echo f2
10
- }
11
-
12
- __a_bc()
13
- {
14
- echo __a_bc
15
- }
16
-
17
- f1
18
- f2
19
- __a_bc
20
-
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo 1 && \
4
- echo 2 \
5
- && echo 3 \
6
- || echo 0
7
-
@@ -1,24 +0,0 @@
1
- #!/bin/bash
2
-
3
- if
4
- [[ false = true ]]
5
- then
6
- echo 1
7
- elif
8
- [[ 2 ]]
9
- then
10
- echo 2
11
- else
12
- echo 3
13
- fi
14
-
15
- [ false = true ] || \
16
- [[ 42 -eq 1337 ]] || [[ 1 -eq 1 ]] \
17
- && true && \
18
- echo 'what?' || \
19
- echo 'no!'
20
-
21
- variable=($(
22
- echo hi
23
- ))
24
- echo after
@@ -1,13 +0,0 @@
1
- #!/bin/bash
2
-
3
- # basic test program
4
-
5
- if true; then
6
- echo 42
7
- else
8
- echo nope
9
- fi
10
-
11
- echo "error on stderr" >&2
12
-
13
-
@@ -1,9 +0,0 @@
1
- #!/bin/bash
2
-
3
- [ "one" = "two" ] && echo nah || echo yup
4
-
5
- if false
6
- then
7
- never
8
- fi
9
-
@@ -1,13 +0,0 @@
1
- #!/bin/bash
2
-
3
- # basic test program
4
-
5
- if true; then
6
- echo 42
7
- else
8
- echo nope
9
- fi
10
-
11
- echo "error on stderr" >&2
12
-
13
-
@@ -1,6 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo "I'm sourcing sourced.txt"
4
-
5
- . $(dirname $0)/sourced.txt
6
-
@@ -1,4 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo "I'm sourced.txt"
4
-
@@ -1,4 +0,0 @@
1
- #!/bin/bash
2
-
3
- # ¹²³
4
- echo 'I am full of unicode characters! äéíóúü¿æ'
@@ -1,5 +0,0 @@
1
- #!/bin/bash
2
-
3
- cd $(dirname $0)
4
-
5
- find scripts -type f -perm -111 -exec bash '{}' \;