boom 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/roundup ADDED
@@ -0,0 +1,307 @@
1
+ #!/bin/sh
2
+ # [r5]: roundup.5.html
3
+ # [r1t]: roundup-1-test.sh.html
4
+ # [r5t]: roundup-5-test.sh.html
5
+ #
6
+ # _(c) 2010 Blake Mizerany - MIT License_
7
+ #
8
+ # Spray **roundup** on your shells to eliminate weeds and bugs. If your shells
9
+ # survive **roundup**'s deathly toxic properties, they are considered
10
+ # roundup-ready.
11
+ #
12
+ # **roundup** reads shell scripts to form test plans. Each
13
+ # test plan is sourced into a sandbox where each test is executed.
14
+ #
15
+ # See [roundup-1-test.sh.html][r1t] or [roundup-5-test.sh.html][r5t] for example
16
+ # test plans.
17
+ #
18
+ # __Install__
19
+ #
20
+ # git clone http://github.com/bmizerany/roundup.git
21
+ # cd roundup
22
+ # make
23
+ # sudo make install
24
+ # # Alternatively, copy `roundup` wherever you like.
25
+ #
26
+ # __NOTE__: Because test plans are sourced into roundup, roundup prefixes its
27
+ # variable and function names with `roundup_` to avoid name collisions. See
28
+ # "Sandbox Test Runs" below for more insight.
29
+
30
+ # Usage and Prerequisites
31
+ # -----------------------
32
+
33
+ # Exit if any following command exits with a non-zero status.
34
+ set -e
35
+
36
+ # The current version is set during `make version`. Do not modify this line in
37
+ # anyway unless you know what you're doing.
38
+ ROUNDUP_VERSION="0.0.5"
39
+ export ROUNDUP_VERSION
40
+
41
+ # Usage is defined in a specific comment syntax. It is `grep`ed out of this file
42
+ # when needed (i.e. The Tomayko Method). See
43
+ # [shocco](http://rtomayko.heroku.com/shocco) for more detail.
44
+ #/ usage: roundup [--help|-h] [--version|-v] [plan ...]
45
+
46
+ roundup_usage() {
47
+ grep '^#/' <"$0" | cut -c4-
48
+ }
49
+
50
+ while test "$#" -gt 0
51
+ do
52
+ case "$1" in
53
+ --help|-h)
54
+ roundup_usage
55
+ exit 0
56
+ ;;
57
+ --version|-v)
58
+ echo "roundup version $ROUNDUP_VERSION"
59
+ exit 0
60
+ ;;
61
+ --color)
62
+ color=always
63
+ shift
64
+ ;;
65
+ -)
66
+ echo >&2 "roundup: unknown switch $1"
67
+ exit 1
68
+ ;;
69
+ *)
70
+ break
71
+ ;;
72
+ esac
73
+ done
74
+
75
+ # Consider all scripts with names matching `*-test.sh` the plans to run unless
76
+ # otherwise specified as arguments.
77
+ if [ "$#" -gt "0" ]
78
+ then
79
+ roundup_plans="$@"
80
+ else
81
+ roundup_plans="$(ls *-test.sh)"
82
+ fi
83
+
84
+ : ${color:="auto"}
85
+
86
+ # Create a temporary storage place for test output to be retrieved for display
87
+ # after failing tests.
88
+ roundup_tmp="$PWD/.roundup.$$"
89
+ mkdir -p "$roundup_tmp"
90
+
91
+ trap "rm -rf \"$roundup_tmp\"" EXIT INT
92
+
93
+ # __Tracing failures__
94
+ roundup_trace() {
95
+ # Delete the first two lines that represent roundups execution of the
96
+ # test function. They are useless to the user.
97
+ sed '1d' |
98
+ # Delete the last line which is the "set +x" of the error trap
99
+ sed '$d' |
100
+ # Replace the rc=$? of the error trap with an verbose string appended
101
+ # to the failing command trace line.
102
+ sed '$s/.*rc=/exit code /' |
103
+ # Trim the two left most `+` signs. They represent the depth at which
104
+ # roundup executed the function. They also, are useless and confusing.
105
+ sed 's/^++//' |
106
+ # Indent the output by 4 spaces to align under the test name in the
107
+ # summary.
108
+ sed 's/^/ /' |
109
+ # Highlight the last line in front of the exit code to bring notice to
110
+ # where the error occurred.
111
+ #
112
+ # The sed magic puts every line into the hold buffer first, then
113
+ # substitutes in the previous hold buffer content, prints that and starts
114
+ # with the next cycle. At the end the last line (in the hold buffer)
115
+ # is printed without substitution.
116
+ sed -n "x;1!{ \$s/\(.*\)/$mag\1$clr/; };1!p;\$x;\$p"
117
+ }
118
+
119
+ # __Other helpers__
120
+
121
+ # Track the test stats while outputting a real-time report. This takes input on
122
+ # **stdin**. Each input line must come in the format of:
123
+ #
124
+ # # The plan description to be displayed
125
+ # d <plan description>
126
+ #
127
+ # # A passing test
128
+ # p <test name>
129
+ #
130
+ # # A failed test
131
+ # f <test name>
132
+ roundup_summarize() {
133
+ set -e
134
+
135
+ # __Colors for output__
136
+
137
+ # Use colors if we are writing to a tty device.
138
+ if (test -t 1) || (test $color = always)
139
+ then
140
+ red=$(printf "\033[31m")
141
+ grn=$(printf "\033[32m")
142
+ mag=$(printf "\033[35m")
143
+ clr=$(printf "\033[m")
144
+ cols=$(tput cols)
145
+ fi
146
+
147
+ # Make these available to `roundup_trace`.
148
+ export red grn mag clr
149
+
150
+ ntests=0
151
+ passed=0
152
+ failed=0
153
+
154
+ : ${cols:=10}
155
+
156
+ while read status name
157
+ do
158
+ case $status in
159
+ p)
160
+ ntests=$(expr $ntests + 1)
161
+ passed=$(expr $passed + 1)
162
+ printf " %-48s " "$name:"
163
+ printf "$grn[PASS]$clr\n"
164
+ ;;
165
+ f)
166
+ ntests=$(expr $ntests + 1)
167
+ failed=$(expr $failed + 1)
168
+ printf " %-48s " "$name:"
169
+ printf "$red[FAIL]$clr\n"
170
+ roundup_trace < "$roundup_tmp/$name"
171
+ ;;
172
+ d)
173
+ printf "%s\n" "$name"
174
+ ;;
175
+ esac
176
+ done
177
+ # __Test Summary__
178
+ #
179
+ # Display the summary now that all tests are finished.
180
+ yes = | head -n 57 | tr -d '\n'
181
+ printf "\n"
182
+ printf "Tests: %3d | " $ntests
183
+ printf "Passed: %3d | " $passed
184
+ printf "Failed: %3d" $failed
185
+ printf "\n"
186
+
187
+ # Exit with an error if any tests failed
188
+ test $failed -eq 0 || exit 2
189
+ }
190
+
191
+ # Sandbox Test Runs
192
+ # -----------------
193
+
194
+ # The above checks guarantee we have at least one test. We can now move through
195
+ # each specified test plan, determine its test plan, and administer each test
196
+ # listed in a isolated sandbox.
197
+ for roundup_p in $roundup_plans
198
+ do
199
+ # Create a sandbox, source the test plan, run the tests, then leave
200
+ # without a trace.
201
+ (
202
+ # Consider the description to be the `basename` of the plan minus the
203
+ # tailing -test.sh.
204
+ roundup_desc=$(basename "$roundup_p" -test.sh)
205
+
206
+ # Define functions for
207
+ # [roundup(5)][r5]
208
+
209
+ # A custom description is recommended, but optional. Use `describe` to
210
+ # set the description to something more meaningful.
211
+ # TODO: reimplement this.
212
+ describe() {
213
+ roundup_desc="$*"
214
+ }
215
+
216
+ # Provide default `before` and `after` functions that run only `:`, a
217
+ # no-op. They may or may not be redefined by the test plan.
218
+ before() { :; }
219
+ after() { :; }
220
+
221
+ # Seek test methods and aggregate their names, forming a test plan.
222
+ # This is done before populating the sandbox with tests to avoid odd
223
+ # conflicts.
224
+
225
+ # TODO: I want to do this with sed only. Please send a patch if you
226
+ # know a cleaner way.
227
+ roundup_plan=$(
228
+ grep "^it_.*()" $roundup_p |
229
+ sed "s/\(it_[a-zA-Z0-9_]*\).*$/\1/g"
230
+ )
231
+
232
+ # We have the test plan and are in our sandbox with [roundup(5)][r5]
233
+ # defined. Now we source the plan to bring its tests into scope.
234
+ . ./$roundup_p
235
+
236
+ # Output the description signal
237
+ printf "d %s" "$roundup_desc" | tr "\n" " "
238
+ printf "\n"
239
+
240
+ for roundup_test_name in $roundup_plan
241
+ do
242
+ # Any number of things are possible in `before`, `after`, and the
243
+ # test. Drop into an subshell to contain operations that may throw
244
+ # off roundup; such as `cd`.
245
+ (
246
+ # Output `before` trace to temporary file. If `before` runs cleanly,
247
+ # the trace will be overwritten by the actual test case below.
248
+ {
249
+ # redirect tracing output of `before` into file.
250
+ {
251
+ set -x
252
+ # If `before` wasn't redefined, then this is `:`.
253
+ before
254
+ } &>"$roundup_tmp/$roundup_test_name"
255
+ # disable tracing again. Its trace output goes to /dev/null.
256
+ set +x
257
+ } &>/dev/null
258
+
259
+ # exit subshell with return code of last failing command. This
260
+ # is needed to see the return code 253 on failed assumptions.
261
+ # But, only do this if the error handling is activated.
262
+ set -E
263
+ trap 'rc=$?; set +x; set -o | grep "errexit.*on" >/dev/null && exit $rc' ERR
264
+
265
+ # If `before` wasn't redefined, then this is `:`.
266
+ before
267
+
268
+ # Momentarily turn off auto-fail to give us access to the tests
269
+ # exit status in `$?` for capturing.
270
+ set +e
271
+ (
272
+ # Set `-xe` before the test in the subshell. We want the
273
+ # test to fail fast to allow for more accurate output of
274
+ # where things went wrong but not in _our_ process because a
275
+ # failed test should not immediately fail roundup. Each
276
+ # tests trace output is saved in temporary storage.
277
+ set -xe
278
+ $roundup_test_name
279
+ ) >"$roundup_tmp/$roundup_test_name" 2>&1
280
+
281
+ # We need to capture the exit status before returning the `set
282
+ # -e` mode. Returning with `set -e` before we capture the exit
283
+ # status will result in `$?` being set with `set`'s status
284
+ # instead.
285
+ roundup_result=$?
286
+
287
+ # It's safe to return to normal operation.
288
+ set -e
289
+
290
+ # If `after` wasn't redefined, then this runs `:`.
291
+ after
292
+
293
+ # This is the final step of a test. Print its pass/fail signal
294
+ # and name.
295
+ if [ "$roundup_result" -ne 0 ]
296
+ then printf "f"
297
+ else printf "p"
298
+ fi
299
+
300
+ printf " $roundup_test_name\n"
301
+ )
302
+ done
303
+ )
304
+ done |
305
+
306
+ # All signals are piped to this for summary.
307
+ roundup_summarize
data/test/run ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+ #
3
+ # A shim to run our tests in shell. Boom is written for the shell, might as well
4
+ # test it in shell.
5
+
6
+ ./test/roundup test/*.sh
7
+
8
+ git checkout test/examples
metadata CHANGED
@@ -1,109 +1,84 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: boom
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 4
10
- version: 0.2.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Zach Holman
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-03-15 00:00:00 -07:00
19
- default_executable: boom
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: multi_json
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yajl-ruby
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
18
+ requirements:
27
19
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 17
30
- segments:
31
- - 1
32
- - 0
33
- - 3
34
- version: 1.0.3
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: json_pure
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
41
25
  none: false
42
- requirements:
26
+ requirements:
43
27
  - - ~>
44
- - !ruby/object:Gem::Version
45
- hash: 5
46
- segments:
47
- - 1
48
- - 5
49
- - 3
50
- version: 1.5.3
51
- type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.0
30
+ - !ruby/object:Gem::Dependency
54
31
  name: mocha
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
57
33
  none: false
58
- requirements:
34
+ requirements:
59
35
  - - ~>
60
- - !ruby/object:Gem::Version
61
- hash: 41
62
- segments:
63
- - 0
64
- - 9
65
- - 9
36
+ - !ruby/object:Gem::Version
66
37
  version: 0.9.9
67
38
  type: :development
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
39
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.9
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
73
49
  none: false
74
- requirements:
50
+ requirements:
75
51
  - - ~>
76
- - !ruby/object:Gem::Version
77
- hash: 63
78
- segments:
79
- - 0
80
- - 9
81
- - 2
52
+ - !ruby/object:Gem::Version
82
53
  version: 0.9.2
83
54
  type: :development
84
- version_requirements: *id004
85
- description: |-
86
- God it's about every day where I think to myself, gadzooks,
87
- I keep typing *REPETITIVE_BORING_TASK* over and over. Wouldn't it be great if
88
- I had something like boom to store all these commonly-used text snippets for
89
- me? Then I realized that was a worthless idea since boom hadn't been created
90
- yet and I had no idea what that statement meant. At some point I found the
91
- code for boom in a dark alleyway and released it under my own name because I
92
- wanted to look smart.
93
- email: github.com@zachholman.com
94
- executables:
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.2
62
+ description: ! "God it's about every day where I think to myself, gadzooks,\n I keep
63
+ typing *REPETITIVE_BORING_TASK* over and over. Wouldn't it be great if\n I had
64
+ something like boom to store all these commonly-used text snippets for\n me? Then
65
+ I realized that was a worthless idea since boom hadn't been created\n yet and I
66
+ had no idea what that statement meant. At some point I found the\n code for boom
67
+ in a dark alleyway and released it under my own name because I\n wanted to look
68
+ smart."
69
+ email: zach@zachholman.com
70
+ executables:
95
71
  - boom
96
72
  extensions: []
97
-
98
- extra_rdoc_files:
99
- - README.markdown
100
- - LICENSE.markdown
101
- files:
102
- - CHANGELOG.markdown
73
+ extra_rdoc_files:
74
+ - README.md
75
+ - LICENSE.md
76
+ files:
77
+ - CHANGELOG.md
103
78
  - Gemfile
104
79
  - Gemfile.lock
105
- - LICENSE.markdown
106
- - README.markdown
80
+ - LICENSE.md
81
+ - README.md
107
82
  - Rakefile
108
83
  - bin/boom
109
84
  - boom.gemspec
@@ -113,66 +88,40 @@ files:
113
88
  - lib/boom.rb
114
89
  - lib/boom/color.rb
115
90
  - lib/boom/command.rb
116
- - lib/boom/config.rb
117
91
  - lib/boom/core_ext/symbol.rb
118
92
  - lib/boom/item.rb
119
93
  - lib/boom/list.rb
120
94
  - lib/boom/platform.rb
121
95
  - lib/boom/storage.rb
122
- - lib/boom/storage/base.rb
123
- - lib/boom/storage/gist.rb
124
- - lib/boom/storage/json.rb
125
- - lib/boom/storage/keychain.rb
126
- - lib/boom/storage/mongodb.rb
127
- - lib/boom/storage/redis.rb
128
- - test/examples/config_json.json
129
- - test/examples/test_json.json
130
- - test/examples/urls.json
131
- - test/helper.rb
132
- - test/test_color.rb
133
- - test/test_command.rb
134
- - test/test_config.rb
135
- - test/test_item.rb
136
- - test/test_list.rb
137
- - test/test_platform.rb
138
- has_rdoc: true
96
+ - test/cli.sh
97
+ - test/examples/data.json
98
+ - test/item.sh
99
+ - test/list.sh
100
+ - test/roundup
101
+ - test/run
139
102
  homepage: https://github.com/holman/boom
140
103
  licenses: []
141
-
142
104
  post_install_message:
143
- rdoc_options:
105
+ rdoc_options:
144
106
  - --charset=UTF-8
145
- require_paths:
107
+ require_paths:
146
108
  - lib
147
- required_ruby_version: !ruby/object:Gem::Requirement
109
+ required_ruby_version: !ruby/object:Gem::Requirement
148
110
  none: false
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- hash: 3
153
- segments:
154
- - 0
155
- version: "0"
156
- required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
116
  none: false
158
- requirements:
159
- - - ">="
160
- - !ruby/object:Gem::Version
161
- hash: 3
162
- segments:
163
- - 0
164
- version: "0"
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
165
121
  requirements: []
166
-
167
122
  rubyforge_project: boom
168
- rubygems_version: 1.6.2
123
+ rubygems_version: 1.8.23
169
124
  signing_key:
170
125
  specification_version: 2
171
126
  summary: boom lets you access text snippets over your command line.
172
- test_files:
173
- - test/test_color.rb
174
- - test/test_command.rb
175
- - test/test_config.rb
176
- - test/test_item.rb
177
- - test/test_list.rb
178
- - test/test_platform.rb
127
+ test_files: []
data/lib/boom/config.rb DELETED
@@ -1,89 +0,0 @@
1
- # coding: utf-8
2
-
3
- #
4
- # Config manages all the config information for boom and its backends. It's a
5
- # simple JSON Hash that gets persisted to `~/.boom` on-disk. You may access it
6
- # as a Hash:
7
- #
8
- # config.attributes = { :backend => "JSON" }
9
- # config.attributes[:backend]
10
- # # => "json"
11
- #
12
- # config.attributes[:backend] = "Redis"
13
- # config.attributes[:backend]
14
- # # => "redis"
15
- #
16
- module Boom
17
- class Config
18
-
19
- # The main config file for boom
20
- FILE = "#{ENV['HOME']}/.boom.conf"
21
-
22
- # Public: The attributes Hash for configuration options. The attributes
23
- # needed are dictated by each backend, but the `backend` option must be
24
- # present.
25
- attr_reader :attributes
26
-
27
- # Public: creates a new instance of Config.
28
- #
29
- # This will load the attributes from boom's config file, or bootstrap it
30
- # if this is a new install. Bootstrapping defaults to the JSON backend.
31
- #
32
- # Returns nothing.
33
- def initialize
34
- bootstrap unless File.exist?(file)
35
- load_attributes
36
- end
37
-
38
- # Public: accessor for the configuration file.
39
- #
40
- # Returns the String file path.
41
- def file
42
- FILE
43
- end
44
-
45
- # Public: saves an empty, barebones hash to @attributes for the purpose of
46
- # new user setup.
47
- #
48
- # Returns whether the attributes were saved.
49
- def bootstrap
50
- @attributes = {
51
- :backend => 'json'
52
- }
53
- save
54
- end
55
-
56
- # Public: assigns a hash to the configuration attributes object. The
57
- # contents of the attributes hash depends on what the backend needs. A
58
- # `backend` key MUST be present, however.
59
- #
60
- # attrs - the Hash representation of attributes to persist to disk.
61
- #
62
- # Examples
63
- #
64
- # config.attributes = {"backend" => "json"}
65
- #
66
- # Returns whether the attributes were saved.
67
- def attributes=(attrs)
68
- @attributes = attrs
69
- save
70
- end
71
-
72
- # Public: loads and parses the JSON tree from disk into memory and stores
73
- # it in the attributes Hash.
74
- #
75
- # Returns nothing.
76
- def load_attributes
77
- @attributes = MultiJson.decode(File.new(file, 'r').read)
78
- end
79
-
80
- # Public: writes the in-memory JSON Hash to disk.
81
- #
82
- # Returns nothing.
83
- def save
84
- json = MultiJson.encode(attributes)
85
- File.open(file, 'w') {|f| f.write(json) }
86
- end
87
-
88
- end
89
- end