s4t-utils 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +34 -0
- data/Manifest.txt +52 -0
- data/NOTES.txt +7 -0
- data/README.txt +2 -0
- data/Rakefile +13 -0
- data/Rakefile.hoe +22 -0
- data/bin/make-s4t-project.rb +159 -0
- data/bin/s4t-script-location-file +1 -0
- data/data/make-s4t-project/README-skeleton +30 -0
- data/data/make-s4t-project/Rakefile.example +32 -0
- data/data/make-s4t-project/bin-skeleton +23 -0
- data/data/make-s4t-project/main-lib-skeleton +14 -0
- data/data/make-s4t-project/set-standalone-test-paths.rb +5 -0
- data/data/make-s4t-project/setup.rb +1585 -0
- data/data/make-s4t-project/sub-lib-skeleton +3 -0
- data/data/make-s4t-project/test-skeleton +28 -0
- data/data/make-s4t-project/version-skeleton +3 -0
- data/lib/s4t-utils.rb +23 -0
- data/lib/s4t-utils/capturing-globals.rb +93 -0
- data/lib/s4t-utils/claims.rb +20 -0
- data/lib/s4t-utils/command-line.rb +18 -0
- data/lib/s4t-utils/error-handling.rb +26 -0
- data/lib/s4t-utils/friendly-format.rb +35 -0
- data/lib/s4t-utils/hacks.rb +55 -0
- data/lib/s4t-utils/load-path-auto-adjuster.rb +120 -0
- data/lib/s4t-utils/more-assertions.rb +35 -0
- data/lib/s4t-utils/os.rb +28 -0
- data/lib/s4t-utils/rake-task-helpers.rb +75 -0
- data/lib/s4t-utils/rakefile-common.rb +112 -0
- data/lib/s4t-utils/svn-file-movement.rb +104 -0
- data/lib/s4t-utils/test-util.rb +19 -0
- data/lib/s4t-utils/version.rb +3 -0
- data/setup.rb +1585 -0
- data/test/capturing-globals-tests.rb +42 -0
- data/test/data/make-s4t-project/README-skeleton +30 -0
- data/test/data/make-s4t-project/Rakefile.example +32 -0
- data/test/data/make-s4t-project/bin-skeleton +23 -0
- data/test/data/make-s4t-project/main-lib-skeleton +14 -0
- data/test/data/make-s4t-project/set-standalone-test-paths.rb +5 -0
- data/test/data/make-s4t-project/setup.rb +1585 -0
- data/test/data/make-s4t-project/sub-lib-skeleton +3 -0
- data/test/data/make-s4t-project/test-skeleton +28 -0
- data/test/data/make-s4t-project/version-skeleton +3 -0
- data/test/data/test-data-location-file +1 -0
- data/test/error-handling-tests.rb +43 -0
- data/test/friendly-format-tests.rb +15 -0
- data/test/hacks-tests.rb +42 -0
- data/test/load-path-auto-adjuster-tests.rb +88 -0
- data/test/rake-task-helper-tests.rb +62 -0
- data/test/set-standalone-test-paths.rb +5 -0
- data/test/test-location-file +1 -0
- data/test/test-util-tests.rb +45 -0
- metadata +116 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# This file should be copied into a test ending in 'tests.rb' so that
|
2
|
+
# the Rakefile knows it's a test.
|
3
|
+
|
4
|
+
require "set-standalone-test-paths.rb" unless $started_from_rakefile
|
5
|
+
require 'test/unit'
|
6
|
+
require 's4t-utils'
|
7
|
+
include S4tUtils
|
8
|
+
|
9
|
+
## Require either the particular file under test like this:
|
10
|
+
# require '!REPLACE_ME_FILE!/my-file'
|
11
|
+
## or the entire package:
|
12
|
+
# require '!REPLACE_ME_FILE!'
|
13
|
+
|
14
|
+
class TestName < Test::Unit::TestCase
|
15
|
+
## You probably want to include your library so that you don't have
|
16
|
+
## to tack !REPLACE_ME_MODULE!:: onto every name, but I won't assume
|
17
|
+
## that.
|
18
|
+
# include !REPLACE_ME_MODULE!
|
19
|
+
|
20
|
+
def setup
|
21
|
+
end
|
22
|
+
|
23
|
+
def teardown
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_something
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
test_data found me
|
@@ -0,0 +1,43 @@
|
|
1
|
+
$:.unshift("../lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 's4t-utils'
|
4
|
+
|
5
|
+
|
6
|
+
class ErrorHandlingTests < Test::Unit::TestCase
|
7
|
+
include S4tUtils
|
8
|
+
|
9
|
+
def test_with_pleasant_exceptions_and_no_error
|
10
|
+
result = with_pleasant_exceptions {
|
11
|
+
"result"
|
12
|
+
}
|
13
|
+
assert_equal("result", result)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_with_pleasant_exceptions_prints_errors_to_stderr
|
17
|
+
result = capturing_stderr {
|
18
|
+
with_pleasant_exceptions {
|
19
|
+
raise Exception.new("this is the message")
|
20
|
+
}
|
21
|
+
}
|
22
|
+
assert_equal("this is the message\n", result)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_with_pleasant_exceptions_does_not_interfere_with_exit
|
26
|
+
assert_wants_to_exit {
|
27
|
+
with_pleasant_exceptions {
|
28
|
+
exit
|
29
|
+
}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
def test_without_pleasant_exceptions_prints_warning
|
35
|
+
warning = capturing_stderr {
|
36
|
+
assert_raises(Exception) {
|
37
|
+
without_pleasant_exceptions { raise Exception.new }
|
38
|
+
}
|
39
|
+
}
|
40
|
+
assert_match(/Note: exception handling turned off/, warning)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.unshift("../lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 's4t-utils'
|
4
|
+
|
5
|
+
|
6
|
+
class FriendlyFormatTests < Test::Unit::TestCase
|
7
|
+
include S4tUtils
|
8
|
+
|
9
|
+
def test_friendly_list
|
10
|
+
assert_equal('', friendly_list('and', []))
|
11
|
+
assert_equal("'a'", friendly_list('and', ['a']))
|
12
|
+
assert_equal("'zed' + 'alpha'", friendly_list('+', [:zed, :alpha]))
|
13
|
+
assert_equal("'1', '2', or '20'", friendly_list('or', [1, 2, 20]))
|
14
|
+
end
|
15
|
+
end
|
data/test/hacks-tests.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
$:.unshift("../lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 's4t-utils'
|
4
|
+
|
5
|
+
|
6
|
+
class ClaimsTests < Test::Unit::TestCase
|
7
|
+
include S4tUtils
|
8
|
+
|
9
|
+
# The name 'prog1' comes from Lisp. Couldn't think of a better one.
|
10
|
+
def test_prog1_returns_argument_after_executing_block
|
11
|
+
block_result = nil
|
12
|
+
prog1_result = prog1(1) {
|
13
|
+
block_result = 2
|
14
|
+
}
|
15
|
+
assert_equal(1, prog1_result)
|
16
|
+
assert_equal(2, block_result)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_prog1_is_also_a_module_method
|
20
|
+
block_result = nil
|
21
|
+
prog1_result = S4tUtils.prog1(1) {
|
22
|
+
block_result = 2
|
23
|
+
}
|
24
|
+
assert_equal(1, prog1_result)
|
25
|
+
assert_equal(2, block_result)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_arg_forwarder_forwards_one_arg
|
29
|
+
array = []
|
30
|
+
forwarder = ArgForwarder.new(array, 5)
|
31
|
+
forwarder.push
|
32
|
+
assert_equal([5], array)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_arg_forwarder_forwards_multiple_args
|
36
|
+
hash = { 1 => 'one', 2 => 'two', 3 => 'three' }
|
37
|
+
forwarder = ArgForwarder.new(hash, 1, 2)
|
38
|
+
forwarder.values_at
|
39
|
+
assert_equal(["one", "two", "three"], forwarder.values_at(3))
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
$:.unshift("../lib")
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
|
5
|
+
class AutoAdjusterTests < Test::Unit::TestCase
|
6
|
+
class FakePath
|
7
|
+
attr_reader :parent
|
8
|
+
def initialize(name, parent=nil)
|
9
|
+
@name = name
|
10
|
+
@parent = parent
|
11
|
+
end
|
12
|
+
|
13
|
+
def +(string)
|
14
|
+
FakePath.new(self.to_s + '/' + string, self)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s; @name; end
|
18
|
+
|
19
|
+
def self.ordinary_structure_returning_third_party
|
20
|
+
root = FakePath.new('root')
|
21
|
+
lib = FakePath.new('lib', root)
|
22
|
+
project = FakePath.new('project', lib)
|
23
|
+
FakePath.new('third-party', project)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
module PathHandling
|
28
|
+
module_function
|
29
|
+
def replace_path(path)
|
30
|
+
$:.clear
|
31
|
+
path.each { | element |
|
32
|
+
$: << element
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def with_path(path)
|
37
|
+
old = $:.dup
|
38
|
+
replace_path(path)
|
39
|
+
yield
|
40
|
+
ensure
|
41
|
+
replace_path(old)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
include PathHandling
|
46
|
+
PathHandling.with_path($:.dup) {
|
47
|
+
require 's4t-utils/load-path-auto-adjuster'
|
48
|
+
}
|
49
|
+
include S4tUtils
|
50
|
+
|
51
|
+
def setup
|
52
|
+
@std_third_party = FakePath.ordinary_structure_returning_third_party
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_notices_when_library_already_in_path
|
56
|
+
with_path(%w{ root lib project third-party}) {
|
57
|
+
assert(Hidden::Arranger.new(@std_third_party).project_lib_already_in_path?)
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
# The checks that the Gem path is correct are commented out below
|
62
|
+
# because checking the Gem path causes subdirectories to be created,
|
63
|
+
# thus leaving little "/gem/" droppings all over the test directory
|
64
|
+
# or wherever the test is run from.
|
65
|
+
|
66
|
+
def test_adds_third_party_if_lib_already_in_path
|
67
|
+
with_path(%w{ local lib something-later}) {
|
68
|
+
Hidden::Arranger.new(@std_third_party).arrange
|
69
|
+
assert_equal(%w{local lib third-party something-later},
|
70
|
+
$:)
|
71
|
+
}
|
72
|
+
|
73
|
+
# assert(Gem.path.include?("#{@std_third_party.to_s}/gems"))
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def test_adds_everything_if_lib_not_already_in_path
|
78
|
+
with_path(%w{ /bin /usr/local/bin }) {
|
79
|
+
Hidden::Arranger.new(@std_third_party).arrange
|
80
|
+
assert_equal(%w{lib third-party root /bin /usr/local/bin},
|
81
|
+
$:)
|
82
|
+
}
|
83
|
+
|
84
|
+
# assert(Gem.path.include?("#{@std_third_party.to_s}/gems"))
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
$:.unshift("../lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 's4t-utils'
|
4
|
+
|
5
|
+
|
6
|
+
class RakeHelperTests < Test::Unit::TestCase
|
7
|
+
include S4tUtils
|
8
|
+
|
9
|
+
def test_generated_taskname
|
10
|
+
assert_equal('__generated__foo', generated_taskname('foo'))
|
11
|
+
assert_equal('__generated__foo', generated_taskname(:foo))
|
12
|
+
assert_equal('__generated__foo_barness',
|
13
|
+
generated_taskname("! foo_bar-ness"))
|
14
|
+
assert_equal('prefix_orp', generated_taskname('orp', 'prefix_'))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_update_peer_subtask_name
|
18
|
+
assert_equal('__update_peers_s4tutils',
|
19
|
+
update_peer_subtask_name('s4t-utils'))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_singular_test_targets_allow_plurals
|
23
|
+
assert_equal("{dbtest,dbtests}", broaden_test_name('dbtest'))
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_plural_test_targets_allow_singular
|
27
|
+
assert_equal("{dbtest,dbtests}", broaden_test_name('dbtests'))
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_desired_subset_can_include_pending_tests
|
31
|
+
local_pending_test = "pending.test.rb"
|
32
|
+
local_finished_test = "finished.test.html"
|
33
|
+
remote_pending_test = "dir/pending.x.rb"
|
34
|
+
remote_finished_test = "dir/fini.rb"
|
35
|
+
|
36
|
+
assert_true(pending?(local_pending_test))
|
37
|
+
assert_true(pending?(remote_pending_test))
|
38
|
+
assert_false(pending?(local_finished_test))
|
39
|
+
assert_false(pending?(remote_finished_test))
|
40
|
+
|
41
|
+
tests = [
|
42
|
+
local_pending_test, local_finished_test,
|
43
|
+
remote_pending_test, remote_finished_test
|
44
|
+
]
|
45
|
+
assert_equal([local_finished_test, remote_finished_test],
|
46
|
+
desired_subset(tests, false))
|
47
|
+
assert_equal(tests,
|
48
|
+
desired_subset(tests, true))
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_pending_has_an_exact_boundary
|
52
|
+
assert_false(pending?('pendingx.rb'))
|
53
|
+
assert_false(pending?('xpending.rb'))
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_pending_can_use_dashes_or_dots
|
57
|
+
assert_true(pending?('pending-test.rb'))
|
58
|
+
assert_true(pending?('pending.test.rb'))
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
test found me
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# This file should be copied into a test ending in 'tests.rb' so that
|
2
|
+
# the Rakefile knows it's a test.
|
3
|
+
|
4
|
+
require "set-standalone-test-paths.rb" unless $started_from_rakefile
|
5
|
+
require 'test/unit'
|
6
|
+
require 's4t-utils'
|
7
|
+
include S4tUtils
|
8
|
+
|
9
|
+
|
10
|
+
class TestUtilTestsNoInclude < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def test_test_method_finds_test_directory
|
13
|
+
assert_equal(["test found me\n"],
|
14
|
+
IO.readlines(TestUtil.test("test-location-file")))
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_test_data_method_finds_test_data_directory
|
18
|
+
assert_equal(["test_data found me\n"],
|
19
|
+
IO.readlines(TestUtil.test_data("test-data-location-file")))
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_script_method_finds_test_data_directory
|
23
|
+
assert_equal("script found me\n",
|
24
|
+
`ruby #{TestUtil.script("s4t-script-location-file")}`)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class TestUtilTestsWithInclude < Test::Unit::TestCase
|
29
|
+
include S4tUtils::TestUtil
|
30
|
+
|
31
|
+
def test_test_method_finds_test_directory
|
32
|
+
assert_equal(["test found me\n"],
|
33
|
+
IO.readlines(test("test-location-file")))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_test_data_method_finds_test_data_directory
|
37
|
+
assert_equal(["test_data found me\n"],
|
38
|
+
IO.readlines(test_data("test-data-location-file")))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_script_method_finds_test_data_directory
|
42
|
+
assert_equal("script found me\n",
|
43
|
+
`ruby #{script("s4t-script-location-file")}`)
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: s4t-utils
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2007-07-11 00:00:00 -05:00
|
8
|
+
summary: _Everyday Scripting with Ruby_ utilities.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: marick@exampler.com
|
12
|
+
homepage: http://s4t-utils.rubyforge.org
|
13
|
+
rubyforge_project: s4t-utils
|
14
|
+
description: _Everyday Scripting with Ruby_ utilities.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Brian Marick
|
31
|
+
files:
|
32
|
+
- LICENSE.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- NOTES.txt
|
35
|
+
- README.txt
|
36
|
+
- Rakefile
|
37
|
+
- Rakefile.hoe
|
38
|
+
- bin/make-s4t-project.rb
|
39
|
+
- bin/s4t-script-location-file
|
40
|
+
- data/make-s4t-project/README-skeleton
|
41
|
+
- data/make-s4t-project/Rakefile.example
|
42
|
+
- data/make-s4t-project/bin-skeleton
|
43
|
+
- data/make-s4t-project/main-lib-skeleton
|
44
|
+
- data/make-s4t-project/set-standalone-test-paths.rb
|
45
|
+
- data/make-s4t-project/setup.rb
|
46
|
+
- data/make-s4t-project/sub-lib-skeleton
|
47
|
+
- data/make-s4t-project/test-skeleton
|
48
|
+
- data/make-s4t-project/version-skeleton
|
49
|
+
- lib/s4t-utils.rb
|
50
|
+
- lib/s4t-utils/capturing-globals.rb
|
51
|
+
- lib/s4t-utils/claims.rb
|
52
|
+
- lib/s4t-utils/command-line.rb
|
53
|
+
- lib/s4t-utils/error-handling.rb
|
54
|
+
- lib/s4t-utils/friendly-format.rb
|
55
|
+
- lib/s4t-utils/hacks.rb
|
56
|
+
- lib/s4t-utils/load-path-auto-adjuster.rb
|
57
|
+
- lib/s4t-utils/more-assertions.rb
|
58
|
+
- lib/s4t-utils/os.rb
|
59
|
+
- lib/s4t-utils/rake-task-helpers.rb
|
60
|
+
- lib/s4t-utils/rakefile-common.rb
|
61
|
+
- lib/s4t-utils/svn-file-movement.rb
|
62
|
+
- lib/s4t-utils/test-util.rb
|
63
|
+
- lib/s4t-utils/version.rb
|
64
|
+
- setup.rb
|
65
|
+
- test/capturing-globals-tests.rb
|
66
|
+
- test/data/make-s4t-project/README-skeleton
|
67
|
+
- test/data/make-s4t-project/Rakefile.example
|
68
|
+
- test/data/make-s4t-project/bin-skeleton
|
69
|
+
- test/data/make-s4t-project/main-lib-skeleton
|
70
|
+
- test/data/make-s4t-project/set-standalone-test-paths.rb
|
71
|
+
- test/data/make-s4t-project/setup.rb
|
72
|
+
- test/data/make-s4t-project/sub-lib-skeleton
|
73
|
+
- test/data/make-s4t-project/test-skeleton
|
74
|
+
- test/data/make-s4t-project/version-skeleton
|
75
|
+
- test/data/test-data-location-file
|
76
|
+
- test/error-handling-tests.rb
|
77
|
+
- test/friendly-format-tests.rb
|
78
|
+
- test/hacks-tests.rb
|
79
|
+
- test/load-path-auto-adjuster-tests.rb
|
80
|
+
- test/rake-task-helper-tests.rb
|
81
|
+
- test/set-standalone-test-paths.rb
|
82
|
+
- test/test-location-file
|
83
|
+
- test/test-util-tests.rb
|
84
|
+
test_files:
|
85
|
+
- test/capturing-globals-tests.rb
|
86
|
+
- test/error-handling-tests.rb
|
87
|
+
- test/friendly-format-tests.rb
|
88
|
+
- test/hacks-tests.rb
|
89
|
+
- test/load-path-auto-adjuster-tests.rb
|
90
|
+
- test/rake-task-helper-tests.rb
|
91
|
+
- test/test-util-tests.rb
|
92
|
+
rdoc_options:
|
93
|
+
- --main
|
94
|
+
- README.txt
|
95
|
+
extra_rdoc_files:
|
96
|
+
- LICENSE.txt
|
97
|
+
- Manifest.txt
|
98
|
+
- NOTES.txt
|
99
|
+
- README.txt
|
100
|
+
executables:
|
101
|
+
- make-s4t-project.rb
|
102
|
+
- s4t-script-location-file
|
103
|
+
extensions: []
|
104
|
+
|
105
|
+
requirements: []
|
106
|
+
|
107
|
+
dependencies:
|
108
|
+
- !ruby/object:Gem::Dependency
|
109
|
+
name: hoe
|
110
|
+
version_requirement:
|
111
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 1.2.1
|
116
|
+
version:
|