lizarb 1.0.0 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.tool-versions +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +14 -3
- data/README.md +23 -64
- data/README_SYSTEMS.md +80 -0
- data/Rakefile +3 -1
- data/app/dev/benches/app_bench.rb +5 -0
- data/app/dev/benches/app_bench_test.rb +7 -0
- data/app/dev/benches/loops_bench.rb +183 -0
- data/app/dev/benches/loops_bench_test.rb +11 -0
- data/app/dev/commands/calculator_command.rb +69 -0
- data/app/dev/commands/calculator_command_test.rb +58 -0
- data/app/dev/commands/circle_command.rb +70 -0
- data/app/dev/commands/circle_command_test.rb +76 -0
- data/app/dev/commands/narrative_method_command.rb +60 -0
- data/app/dev/commands/narrative_method_command_test.rb +36 -0
- data/app/dev/commands/new_command.rb +1 -61
- data/app/dev/commands/quadratic_command.rb +66 -0
- data/app/dev/commands/quadratic_command_test.rb +47 -0
- data/app/dev/generators/bench_generator/bench.rb.erb +24 -0
- data/app/dev/generators/bench_generator/bench_test.rb.erb +12 -0
- data/app/dev/generators/bench_generator.rb +18 -0
- data/app/dev/generators/bench_generator_test.rb +12 -0
- data/app/dev/generators/command_generator/command.rb.erb +26 -0
- data/app/dev/generators/command_generator/command_test.rb.erb +12 -0
- data/app/dev/generators/command_generator.rb +18 -0
- data/app/dev/generators/command_generator_test.rb +12 -0
- data/app/dev/generators/record_generator.rb +46 -0
- data/app/dev/generators/record_generator_test.rb +12 -0
- data/app/dev/generators/request_generator.rb +63 -0
- data/app/dev/generators/request_generator_test.rb +12 -0
- data/app/net/databases/redis_db_test.rb +2 -2
- data/app/net/databases/sqlite_db_test.rb +2 -2
- data/app/net/{models/app_model.rb → records/app_record.rb} +2 -1
- data/app/net/{models/post_model_test.rb → records/app_record_test.rb} +2 -2
- data/app/net/records/post_record.rb +4 -0
- data/app/net/{models/app_model_test.rb → records/post_record_test.rb} +2 -2
- data/app/net/records/user_record.rb +4 -0
- data/app/net/{models/user_model_test.rb → records/user_record_test.rb} +2 -2
- data/app/net_box.rb +2 -2
- data/app/web/requests/api_request.rb +8 -7
- data/app/web/requests/assets_request.rb +12 -13
- data/app/web/requests/root_request.rb +6 -7
- data/app/web/requests/root_request_test.rb +1 -1
- data/app/web_box.rb +8 -0
- data/app_new/Procfile +1 -1
- data/exe/lrb +3 -0
- data/lib/app.rb +18 -14
- data/lib/dev_system/dev/controllers/bench/not_found_bench.rb +29 -0
- data/lib/dev_system/dev/controllers/bench/not_found_bench_test.rb +14 -0
- data/lib/dev_system/dev/controllers/bench.rb +11 -0
- data/lib/dev_system/dev/controllers/bench_dsl_main_part.rb +60 -0
- data/lib/dev_system/dev/controllers/{command/dev_command_test.rb → bench_test.rb} +2 -2
- data/lib/dev_system/dev/controllers/command/bench_command.rb +34 -0
- data/lib/dev_system/dev/controllers/command/bench_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/generate_command.rb +35 -0
- data/lib/dev_system/dev/controllers/command/generate_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/not_found_command.rb +29 -0
- data/lib/dev_system/dev/controllers/command/not_found_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/terminal_command.rb +24 -0
- data/lib/dev_system/dev/controllers/command/terminal_command_test.rb +14 -0
- data/lib/dev_system/dev/controllers/command/test_command.rb +6 -2
- data/lib/dev_system/dev/controllers/generator.rb +11 -0
- data/lib/dev_system/dev/controllers/generator_dsl_main_part.rb +54 -0
- data/lib/dev_system/dev/controllers/generator_test.rb +14 -0
- data/lib/dev_system/dev/controllers/generators/app_generator.rb +96 -0
- data/lib/dev_system/dev/controllers/generators/app_generator_test.rb +14 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator/generator.rb.erb +18 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator/generator_test.rb.erb +12 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator/template.rb.erb +9 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator/template_test.rb.erb +12 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator.rb +30 -0
- data/lib/dev_system/dev/controllers/generators/generator_generator_test.rb +12 -0
- data/lib/dev_system/dev/controllers/generators/not_found_generator.rb +29 -0
- data/lib/dev_system/dev/controllers/generators/not_found_generator_test.rb +14 -0
- data/lib/dev_system/dev/controllers/shell/bin_shell.rb +22 -0
- data/lib/dev_system/dev/controllers/shell/bin_shell_test.rb +87 -0
- data/lib/dev_system/dev/controllers/shell/dir_shell.rb +27 -0
- data/lib/dev_system/dev/controllers/shell/dir_shell_test.rb +73 -0
- data/lib/dev_system/dev/controllers/shell/file_shell.rb +59 -0
- data/lib/dev_system/dev/controllers/shell/file_shell_test.rb +150 -0
- data/lib/dev_system/dev/controllers/shell/text_shell.rb +23 -0
- data/lib/dev_system/dev/controllers/shell/text_shell_test.rb +84 -0
- data/lib/dev_system/dev/controllers/shell.rb +31 -0
- data/lib/dev_system/dev/controllers/shell_test.rb +46 -0
- data/lib/dev_system/dev/controllers/{command/dev_command.rb → terminal/irb_terminal.rb} +2 -2
- data/lib/dev_system/dev/controllers/terminal/irb_terminal_test.rb +14 -0
- data/lib/dev_system/dev/controllers/terminal/pry_terminal.rb +12 -0
- data/lib/dev_system/dev/controllers/terminal/pry_terminal_test.rb +14 -0
- data/lib/dev_system/dev/controllers/terminal.rb +19 -0
- data/lib/dev_system/dev/controllers/terminal_test.rb +14 -0
- data/lib/dev_system/dev/dev_box.rb +3 -0
- data/lib/dev_system/dev/panels/command_panel.rb +21 -1
- data/lib/dev_system/dev/panels/log_panel.rb +1 -1
- data/lib/lerb.rb +106 -0
- data/lib/liza/base/controller.rb +2 -0
- data/lib/liza/base/panel.rb +6 -5
- data/lib/liza/base_parts/controller_renderer_part.rb +140 -0
- data/lib/liza/base_parts/controller_renderer_part_test.rb +16 -0
- data/lib/liza/meta/part_extension.rb +6 -1
- data/lib/liza/ruby_test.rb +9 -0
- data/lib/liza/ruby_tests/module_test.rb +21 -0
- data/lib/liza/ruby_tests/string_test.rb +59 -0
- data/lib/liza/test/test.rb +3 -1
- data/lib/liza/test/test_test.rb +108 -15
- data/lib/liza/test_parts/test_assertions_advanced_part.rb +127 -0
- data/lib/liza/test_parts/test_assertions_part.rb +7 -6
- data/lib/liza/test_parts/test_dsl_part.rb +37 -89
- data/lib/liza/test_parts/test_log_part.rb +124 -0
- data/lib/liza/test_parts/test_subject_part.rb +6 -1
- data/lib/liza/test_parts/test_tree_part.rb +139 -0
- data/lib/liza/unit.rb +2 -0
- data/lib/liza/unit_parts/unit_procedure_part.rb +17 -0
- data/lib/liza/unit_parts/unit_procedure_part_test.rb +65 -0
- data/lib/liza.rb +40 -7
- data/lib/lizarb/ruby/class.rb +2 -0
- data/lib/lizarb/ruby/module.rb +17 -0
- data/lib/lizarb/ruby/proc.rb +12 -0
- data/lib/lizarb/ruby/string.rb +26 -2
- data/lib/lizarb/version.rb +1 -1
- data/lib/lizarb.rb +24 -2
- data/lib/net_system/net/controllers/{adapter/redis_adapter.rb → client/redis_client.rb} +2 -2
- data/lib/net_system/net/controllers/{adapter/redis_adapter_test.rb → client/redis_client_test.rb} +2 -2
- data/lib/net_system/net/controllers/{adapter/sqlite_adapter.rb → client/sqlite_client.rb} +2 -2
- data/lib/net_system/net/controllers/{adapter/sqlite_adapter_test.rb → client/sqlite_client_test.rb} +2 -2
- data/lib/net_system/net/controllers/client.rb +5 -0
- data/lib/net_system/net/controllers/{model_test.rb → client_test.rb} +2 -2
- data/lib/net_system/net/controllers/database/redis_db.rb +2 -2
- data/lib/net_system/net/controllers/database/redis_db_test.rb +1 -1
- data/lib/net_system/net/controllers/database/sqlite_db.rb +2 -2
- data/lib/net_system/net/controllers/database/sqlite_db_test.rb +1 -1
- data/lib/net_system/net/controllers/database.rb +6 -6
- data/lib/net_system/net/controllers/record.rb +31 -0
- data/lib/net_system/net/controllers/{adapter_test.rb → record_test.rb} +2 -2
- data/lib/net_system/net/net_box.rb +5 -5
- data/lib/net_system/net/net_box_test.rb +1 -1
- data/lib/net_system/net/panels/client_panel.rb +5 -0
- data/lib/net_system/net/panels/{adapter_panel_test.rb → client_panel_test.rb} +2 -2
- data/lib/web_system/dev/rack_command.rb +26 -0
- data/lib/web_system/dev/request_command.rb +143 -0
- data/lib/web_system/dev/web_command.rb +3 -34
- data/lib/web_system/web/controllers/rack.rb +8 -0
- data/lib/web_system/web/controllers/rack_test.rb +18 -0
- data/lib/web_system/web/controllers/request/client_error_request.rb +0 -1
- data/lib/web_system/web/controllers/request/not_found_request.rb +0 -1
- data/lib/web_system/web/controllers/request/server_error_request.rb +0 -1
- data/lib/web_system/web/panels/rack_panel.rb +44 -0
- data/lib/web_system/web/panels/rack_panel_test.rb +14 -0
- data/lib/web_system/web/panels/request_panel.rb +51 -32
- data/lib/web_system/web/panels/request_panel_test.rb +28 -9
- data/lib/web_system/web/web_box.rb +12 -0
- data/lizarb.gemspec +2 -2
- data/tmp/.gitkeep +0 -0
- metadata +110 -31
- data/app/dev/commands/example_command.rb +0 -57
- data/app/dev/commands/example_command_test.rb +0 -43
- data/app/dev/commands/macro_child_command.rb +0 -32
- data/app/dev/commands/macro_child_command_test.rb +0 -7
- data/app/dev/commands/macro_parent_command.rb +0 -70
- data/app/dev/commands/macro_parent_command_test.rb +0 -7
- data/app/dev/commands/my_command.rb +0 -7
- data/app/dev/commands/my_command_test.rb +0 -7
- data/app/net/models/post_model.rb +0 -4
- data/app/net/models/user_model.rb +0 -4
- data/lib/liza/test_parts/test_context_part.rb +0 -81
- data/lib/net_system/net/controllers/adapter.rb +0 -5
- data/lib/net_system/net/controllers/model.rb +0 -31
- data/lib/net_system/net/panels/adapter_panel.rb +0 -5
@@ -1,122 +1,70 @@
|
|
1
1
|
module Liza
|
2
2
|
class TestDslPart < Part
|
3
3
|
insertion do
|
4
|
-
def self.test *words, &block
|
5
|
-
Liza.log "#{inspect}.test #{words}, &block"
|
6
|
-
block_given? || raise(ArgumentError, "No block given")
|
7
|
-
|
8
|
-
key = [
|
9
|
-
block.source_location,
|
10
|
-
'b',
|
11
|
-
context.befores.flatten.map(&:source_location),
|
12
|
-
'a',
|
13
|
-
context.afters.flatten.map(&:source_location),
|
14
|
-
].flatten.join("-")
|
15
|
-
|
16
|
-
key.gsub! Lizarb::CUR_DIR, ""
|
17
|
-
|
18
|
-
instances[key] ||= new words,
|
19
|
-
context.befores.flatten.uniq,
|
20
|
-
context.afters.flatten.uniq,
|
21
|
-
&block
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.instances
|
25
|
-
@instances ||= {}
|
26
|
-
end
|
27
4
|
|
28
5
|
def self.call class_index, class_count
|
29
6
|
counter_class = "#{class_index.to_s.rjust 3, "0"}/#{class_count.to_s.rjust 3, "0"}"
|
30
7
|
|
31
|
-
|
8
|
+
log "+ #{counter_class} #{self} class".bold.white
|
9
|
+
|
10
|
+
array = [test_tree]
|
11
|
+
while array.any?
|
12
|
+
node = array.pop
|
13
|
+
i = 0
|
32
14
|
|
33
|
-
|
34
|
-
|
35
|
-
|
15
|
+
node.tests.each do |test_words, test_block|
|
16
|
+
counter_instance = "#{(i+=1).to_s.rjust 2, '0'}/#{node.tests.size.to_s.rjust 2, '0'}"
|
17
|
+
label = test_words.to_a.flatten.join(" ")[0..25]
|
36
18
|
|
37
|
-
|
19
|
+
log " #{ counter_class } #{ counter_instance } #{ label.ljust(27)} #{_log_test_block test_block}"
|
38
20
|
|
39
|
-
|
21
|
+
log_test_building node, test_block if log_test_building?
|
22
|
+
|
23
|
+
instance = new test_words, node.before_stack, node.after_stack, &test_block
|
24
|
+
instance.call
|
25
|
+
end
|
26
|
+
|
27
|
+
array.concat node.children
|
40
28
|
end
|
41
|
-
end
|
42
29
|
|
43
|
-
|
30
|
+
end
|
44
31
|
|
45
|
-
attr_reader :
|
32
|
+
attr_reader :test_words
|
46
33
|
|
47
|
-
def initialize
|
48
|
-
@
|
34
|
+
def initialize test_words, before_stack, after_stack, &test_block
|
35
|
+
@test_words, @before_stack, @after_stack, @test_block = test_words, before_stack, after_stack, test_block
|
49
36
|
end
|
50
37
|
|
51
38
|
def call
|
52
39
|
catch :critical do
|
53
|
-
@
|
54
|
-
|
55
|
-
|
40
|
+
@before_stack.each do |stack|
|
41
|
+
log " calling stacked before blocks #{stack.map { |bl| _log_test_block bl }}".magenta if log_test_building?
|
42
|
+
stack.each do |bl|
|
43
|
+
log_test_call "B&", &bl if log_test_call_block?
|
44
|
+
instance_exec &bl
|
45
|
+
end
|
56
46
|
end
|
57
47
|
|
58
|
-
bl = @
|
59
|
-
|
48
|
+
bl = @test_block
|
49
|
+
log " calling test block #{_log_test_block bl}".magenta if log_test_building?
|
50
|
+
log_test_call "T&", &bl if log_test_call_block?
|
60
51
|
instance_exec &bl
|
61
52
|
|
62
|
-
@
|
63
|
-
|
64
|
-
|
53
|
+
@after_stack.each do |stack|
|
54
|
+
log " calling stacked after blocks #{stack.map { |bl| _log_test_block bl }}".magenta if log_test_building?
|
55
|
+
stack.each do |bl|
|
56
|
+
log_test_call "A&", &bl if log_test_call_block?
|
57
|
+
instance_exec &bl
|
58
|
+
end
|
65
59
|
end
|
66
60
|
end
|
67
61
|
rescue Exception => e
|
68
62
|
self.class._assertion_errored e
|
69
|
-
|
63
|
+
log_test_call_rescue e
|
70
64
|
ensure
|
71
65
|
puts
|
72
66
|
end
|
73
67
|
|
74
|
-
def words_as_label
|
75
|
-
label = words.to_s
|
76
|
-
label = label[1..-2] if label.start_with? "["
|
77
|
-
label = label[1..-2] if label.start_with? "{"
|
78
|
-
label
|
79
|
-
end
|
80
|
-
|
81
|
-
def _rescue_log e
|
82
|
-
prefix = "error"
|
83
|
-
|
84
|
-
kaller = e.backtrace
|
85
|
-
|
86
|
-
source_location = _caller_line_split(kaller[0])[0]
|
87
|
-
source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
|
88
|
-
|
89
|
-
log " #{prefix} #{source_location}"
|
90
|
-
|
91
|
-
puts "Exception!".red
|
92
|
-
puts e.class.to_s.red
|
93
|
-
puts e.message.red
|
94
|
-
puts
|
95
|
-
puts e.backtrace.join("\n").red
|
96
|
-
end
|
97
|
-
|
98
|
-
def _call_log prefix, &block
|
99
|
-
source_location = block.source_location.join(":").gsub("#{Lizarb::CUR_DIR}/", "")
|
100
|
-
source_location = source_location[0..-1]
|
101
|
-
log " #{prefix} #{source_location}"
|
102
|
-
end
|
103
|
-
|
104
|
-
def _assertion_log method_name, kaller
|
105
|
-
_inc_assertions
|
106
|
-
method_name = method_name.to_s.ljust 6
|
107
|
-
prefix = "#{assertions} #{method_name} #{@last_result}"
|
108
|
-
|
109
|
-
source_location = _caller_line_split(kaller[0])[0]
|
110
|
-
source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
|
111
|
-
|
112
|
-
log " #{prefix} #{source_location}"
|
113
|
-
end
|
114
|
-
|
115
|
-
def _caller_line_split s
|
116
|
-
x = s.split ":in `"
|
117
|
-
x[1] = x[1][0..-2]
|
118
|
-
x
|
119
|
-
end
|
120
68
|
end
|
121
69
|
end
|
122
70
|
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Liza
|
2
|
+
class TestLogPart < Part
|
3
|
+
|
4
|
+
insertion do
|
5
|
+
|
6
|
+
LOG_BUILDING = false
|
7
|
+
LOG_ASSERTION = true
|
8
|
+
LOG_ASSERTION_MESSAGE = true
|
9
|
+
LOG_CALL_BLOCK = true
|
10
|
+
|
11
|
+
def self.log_test_building?
|
12
|
+
LOG_BUILDING
|
13
|
+
end
|
14
|
+
|
15
|
+
def log_test_building?
|
16
|
+
self.class.log_test_building?
|
17
|
+
end
|
18
|
+
|
19
|
+
def log_test_assertion?
|
20
|
+
LOG_ASSERTION
|
21
|
+
end
|
22
|
+
|
23
|
+
def log_test_assertion_message?
|
24
|
+
LOG_ASSERTION_MESSAGE
|
25
|
+
end
|
26
|
+
|
27
|
+
def log_test_call_block?
|
28
|
+
LOG_CALL_BLOCK
|
29
|
+
end
|
30
|
+
|
31
|
+
def log_test_call_rescue e
|
32
|
+
prefix = "error".yellow
|
33
|
+
|
34
|
+
kaller = e.backtrace
|
35
|
+
|
36
|
+
source_location = _caller_line_split(kaller[0])[0]
|
37
|
+
source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
|
38
|
+
|
39
|
+
log " #{prefix} #{e.class.to_s.ljust 20} #{source_location}"
|
40
|
+
|
41
|
+
puts "Exception!".red
|
42
|
+
puts e.class.to_s.red
|
43
|
+
puts e.message.red
|
44
|
+
puts
|
45
|
+
puts e.backtrace.join("\n").red
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.log_test_building node, test_block
|
49
|
+
log " the building blocks are".magenta
|
50
|
+
|
51
|
+
node.before_stack.each do |stack|
|
52
|
+
stack.each do |bl|
|
53
|
+
log " before block #{_log_test_block bl}".magenta
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
log " test block #{_log_test_block test_block}".magenta
|
58
|
+
|
59
|
+
node.after_stack.each do |stack|
|
60
|
+
stack.each do |bl|
|
61
|
+
log " after block #{_log_test_block bl}".magenta
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def log_test_call prefix, &block
|
67
|
+
source_location = block.source_location.join(":").gsub("#{Lizarb::CUR_DIR}/", "")
|
68
|
+
source_location = source_location[0..-1]
|
69
|
+
log " #{prefix} #{source_location}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def log_test_assertion method_name, kaller
|
73
|
+
_inc_assertions
|
74
|
+
prefix = "#{assertions.to_s.rjust 2, "0"} #{_log_test_assertion_tag method_name}"
|
75
|
+
|
76
|
+
source_location = _caller_line_split(kaller[0])[0]
|
77
|
+
source_location = source_location.gsub("#{Lizarb::CUR_DIR}/", "")
|
78
|
+
|
79
|
+
log " #{prefix} #{source_location}" if log_test_assertion?
|
80
|
+
end
|
81
|
+
|
82
|
+
def _log_test_assertion_tag method_name
|
83
|
+
"#{log_test_assertion_result} #{method_name.to_s.ljust(20).bold.white}"
|
84
|
+
end
|
85
|
+
|
86
|
+
def self._log_test_block test_block
|
87
|
+
test_block.source_location.join(":").gsub("#{Lizarb::CUR_DIR}/", "")
|
88
|
+
end
|
89
|
+
|
90
|
+
def _log_test_block test_block
|
91
|
+
self.class._log_test_block test_block
|
92
|
+
end
|
93
|
+
|
94
|
+
def log_test_assertion_result
|
95
|
+
case @last_result
|
96
|
+
when :todo
|
97
|
+
" todo".blue
|
98
|
+
when :passed
|
99
|
+
"passed".green
|
100
|
+
when :failed
|
101
|
+
"failed".red
|
102
|
+
else
|
103
|
+
raise "Unknown result: #{@last_result}"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def log_test_assertion_message b, msg
|
108
|
+
if b
|
109
|
+
log " passed #{msg}".green
|
110
|
+
else
|
111
|
+
log " failed #{msg}".red
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def _caller_line_split s
|
116
|
+
x = s.split ":in `"
|
117
|
+
x[1] = x[1][0..-2]
|
118
|
+
x
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
@@ -3,7 +3,12 @@ module Liza
|
|
3
3
|
|
4
4
|
insertion do
|
5
5
|
def self.subject_class
|
6
|
-
@subject_class ||=
|
6
|
+
@subject_class ||=
|
7
|
+
if first_namespace == "Liza"
|
8
|
+
Liza.const_get last_namespace[0..-5]
|
9
|
+
else
|
10
|
+
Object.const_get name[0..-5]
|
11
|
+
end
|
7
12
|
end
|
8
13
|
|
9
14
|
def subject_class
|
@@ -0,0 +1,139 @@
|
|
1
|
+
module Liza
|
2
|
+
class TestTreePart < Part
|
3
|
+
|
4
|
+
insertion do
|
5
|
+
|
6
|
+
@before_stack = []
|
7
|
+
@after_stack = []
|
8
|
+
|
9
|
+
def self.before_stack; @before_stack ||= superclass.before_stack.dup end
|
10
|
+
def self.after_stack; @after_stack ||= superclass.after_stack.dup end
|
11
|
+
|
12
|
+
def self.test_node; @test_node ||= test_tree end
|
13
|
+
def self.test_tree; @test_tree ||= Liza::TestTreePart::Extension.new nil, before_stack, after_stack end
|
14
|
+
|
15
|
+
#
|
16
|
+
|
17
|
+
def self.group *words, &block
|
18
|
+
raise ArgumentError, "No block given" unless block_given?
|
19
|
+
previous = test_node
|
20
|
+
@test_node = test_node.branch_out words
|
21
|
+
instance_exec &block
|
22
|
+
@test_node = previous
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.test *words, &block
|
26
|
+
raise ArgumentError, "No block given" unless block_given?
|
27
|
+
test_node.add_test words, &block
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.before &block
|
31
|
+
raise ArgumentError, "No block given" unless block_given?
|
32
|
+
test_node.add_before &block
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.after &block
|
36
|
+
raise ArgumentError, "No block given" unless block_given?
|
37
|
+
test_node.add_after &block
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
extension do
|
43
|
+
|
44
|
+
def log *args
|
45
|
+
self.class.solder.log *args
|
46
|
+
end
|
47
|
+
|
48
|
+
def log_test_building?
|
49
|
+
Liza::Test.log_test_building?
|
50
|
+
end
|
51
|
+
|
52
|
+
attr_reader :tests, :parent, :children, :before_stack, :after_stack
|
53
|
+
|
54
|
+
def initialize parent, before_stack, after_stack
|
55
|
+
@parent = parent || self
|
56
|
+
|
57
|
+
@children, @tests = [], []
|
58
|
+
@before_top, @after_top = [], []
|
59
|
+
|
60
|
+
@before_stack = before_stack.push @before_top
|
61
|
+
@after_stack = after_stack.unshift @after_top
|
62
|
+
|
63
|
+
@parent.children << self if @parent != self
|
64
|
+
end
|
65
|
+
|
66
|
+
def initialize parent, before_stack, after_stack
|
67
|
+
@parent = parent || self
|
68
|
+
|
69
|
+
@children, @tests, @before_top, @after_top = [], [], [], []
|
70
|
+
|
71
|
+
@before_stack = before_stack.push @before_top
|
72
|
+
@after_stack = after_stack.unshift @after_top
|
73
|
+
|
74
|
+
@parent.children << self if @parent != self
|
75
|
+
end
|
76
|
+
|
77
|
+
def initialize parent, before_stack, after_stack
|
78
|
+
@parent = parent || self
|
79
|
+
@children, @tests = [], []
|
80
|
+
@parent.children << self if @parent != self
|
81
|
+
|
82
|
+
@before_top, @after_top = [], []
|
83
|
+
@before_stack = before_stack.push @before_top
|
84
|
+
@after_stack = after_stack.unshift @after_top
|
85
|
+
end
|
86
|
+
|
87
|
+
def initialize parent, before_stack, after_stack
|
88
|
+
@tests = []
|
89
|
+
|
90
|
+
@parent = parent || self
|
91
|
+
@children = []
|
92
|
+
@parent.children << self if @parent != self
|
93
|
+
|
94
|
+
@before_top, @after_top = [], []
|
95
|
+
@before_stack = before_stack.push @before_top
|
96
|
+
@after_stack = after_stack.unshift @after_top
|
97
|
+
end
|
98
|
+
|
99
|
+
def initialize parent, before_stack, after_stack
|
100
|
+
@tests = []
|
101
|
+
initialize_parenting parent
|
102
|
+
initialize_filters before_stack, after_stack
|
103
|
+
end
|
104
|
+
|
105
|
+
def initialize_parenting parent
|
106
|
+
@parent = parent || self
|
107
|
+
@children = []
|
108
|
+
@parent.children << self if @parent != self
|
109
|
+
end
|
110
|
+
|
111
|
+
def initialize_filters before_stack, after_stack
|
112
|
+
@before_top, @after_top = [], []
|
113
|
+
@before_stack = before_stack.push @before_top
|
114
|
+
@after_stack = after_stack.unshift @after_top
|
115
|
+
end
|
116
|
+
|
117
|
+
def add_before &block
|
118
|
+
log "add_before to ##{object_id} #{block}" if log_test_building?
|
119
|
+
@before_top.push block
|
120
|
+
end
|
121
|
+
|
122
|
+
def add_test words, &block
|
123
|
+
log "add_test to ##{object_id} #{words} #{block}" if log_test_building?
|
124
|
+
tests << [words, block]
|
125
|
+
end
|
126
|
+
|
127
|
+
def add_after &block
|
128
|
+
log "add_after to ##{object_id} #{block}" if log_test_building?
|
129
|
+
@after_top.push block
|
130
|
+
end
|
131
|
+
|
132
|
+
def branch_out words, &block
|
133
|
+
self.class.new self, before_stack.dup, after_stack.dup
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
end
|
data/lib/liza/unit.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
class Liza::UnitProcedurePart < Liza::Part
|
2
|
+
|
3
|
+
insertion do
|
4
|
+
def self.procedure _label, &block
|
5
|
+
catch :procedure, &block
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.proceed val = nil, &block
|
9
|
+
val = yield if val.nil? && block_given?
|
10
|
+
throw :procedure, val
|
11
|
+
end
|
12
|
+
|
13
|
+
def procedure(_label, &block)= self.class.procedure _label, &block
|
14
|
+
def proceed(...)= self.class.proceed(...)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Liza::UnitProcedurePartTest < Liza::UnitTest
|
2
|
+
|
3
|
+
test :procedure_scopes_and_returns do
|
4
|
+
b = nil
|
5
|
+
|
6
|
+
w =
|
7
|
+
procedure "creates a new scope" do
|
8
|
+
@a = 1
|
9
|
+
b = 2
|
10
|
+
c = 3
|
11
|
+
assert true
|
12
|
+
|
13
|
+
proceed if true
|
14
|
+
raise "did not get here"
|
15
|
+
end
|
16
|
+
|
17
|
+
assert assertions > 0
|
18
|
+
assert w.nil?
|
19
|
+
|
20
|
+
x =
|
21
|
+
procedure "asserts old scope is not accessible" do
|
22
|
+
assert instance_variables.include? :@a
|
23
|
+
assert local_variables.include? :b
|
24
|
+
refute local_variables.include? :c
|
25
|
+
|
26
|
+
assert @a == 1
|
27
|
+
assert b == 2
|
28
|
+
|
29
|
+
proceed 100 if true
|
30
|
+
raise "did not get here"
|
31
|
+
end
|
32
|
+
|
33
|
+
assert x == 100
|
34
|
+
|
35
|
+
y =
|
36
|
+
procedure "asserts proceed calls can be lazy" do
|
37
|
+
proceed { "slow operation"; 200 } if true
|
38
|
+
raise "did not get here"
|
39
|
+
end
|
40
|
+
|
41
|
+
assert y == 200
|
42
|
+
end
|
43
|
+
|
44
|
+
test :procedure_rescue_and_ensure do
|
45
|
+
procedure "assert ensure works" do
|
46
|
+
@a = 1
|
47
|
+
ensure
|
48
|
+
@a = 2
|
49
|
+
end
|
50
|
+
|
51
|
+
assert @a == 2
|
52
|
+
|
53
|
+
procedure "assert rescue works" do
|
54
|
+
@a = [1]
|
55
|
+
raise "a runtime error!"
|
56
|
+
rescue RuntimeError
|
57
|
+
@a << 2
|
58
|
+
ensure
|
59
|
+
@a << 3
|
60
|
+
end
|
61
|
+
|
62
|
+
assert @a == [1, 2, 3]
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
data/lib/liza.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
module Liza
|
4
4
|
class Error < StandardError; end
|
5
|
+
class ConstNotFound < Error; end
|
5
6
|
|
6
7
|
#
|
7
8
|
|
@@ -13,22 +14,54 @@ module Liza
|
|
13
14
|
|
14
15
|
#
|
15
16
|
|
16
|
-
#
|
17
|
+
# Checks Object, each system, then Liza for Liza::Unit classes
|
17
18
|
def const name
|
18
|
-
name = name.to_s.camelize
|
19
|
+
name = name.to_s.camelize.to_sym
|
19
20
|
|
20
|
-
|
21
|
+
k = const_check_object name
|
22
|
+
return k if k
|
21
23
|
|
22
|
-
|
24
|
+
k = const_check_systems name
|
25
|
+
return k if k
|
26
|
+
|
27
|
+
k = const_get name
|
28
|
+
return k if k
|
29
|
+
|
30
|
+
nil
|
31
|
+
rescue NameError
|
32
|
+
raise ConstNotFound, name
|
23
33
|
end
|
24
34
|
|
25
|
-
#
|
35
|
+
# Checks each system, then Liza for Liza::Unit classes
|
26
36
|
def const_missing name
|
37
|
+
k = const_check_systems name
|
38
|
+
return k if k
|
39
|
+
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def const_check_object name
|
44
|
+
return if not Object.const_defined? name
|
45
|
+
kk = Object.const_get name
|
46
|
+
return kk if is_unit? kk
|
47
|
+
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def const_check_systems name
|
52
|
+
App.systems.frozen? or return nil
|
53
|
+
|
27
54
|
for k in App.systems.values.reverse
|
28
|
-
|
55
|
+
next if not k.const_defined? name.to_sym
|
56
|
+
kk = k.const(name) if k.constants.include? name
|
57
|
+
return kk if is_unit? kk
|
29
58
|
end
|
30
59
|
|
31
|
-
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def is_unit? kk
|
64
|
+
kk && kk < Liza::Unit
|
32
65
|
end
|
33
66
|
|
34
67
|
end
|
data/lib/lizarb/ruby/class.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Module
|
4
|
+
|
5
|
+
# /path/to/liza.rb
|
6
|
+
def source_location
|
7
|
+
Object.const_source_location name
|
8
|
+
end
|
9
|
+
|
10
|
+
# /path/to/liza
|
11
|
+
def source_location_radical
|
12
|
+
source_location[0][0..-4]
|
13
|
+
rescue
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/lizarb/ruby/string.rb
CHANGED
@@ -3,7 +3,31 @@
|
|
3
3
|
class String
|
4
4
|
alias lpartition partition
|
5
5
|
|
6
|
-
def
|
7
|
-
split("_").map { |s| "#{s[0].upcase}#{s[1..-1]}" }.join("")
|
6
|
+
def camelcase
|
7
|
+
split("_").map { |s| "#{s[0].to_s.upcase}#{s[1..-1]}" }.join("")
|
8
|
+
end
|
9
|
+
|
10
|
+
alias camelize camelcase
|
11
|
+
|
12
|
+
def snakecase
|
13
|
+
gsub(/[A-Z\s-]/) { |s, t| "_#{s}" }[1..-1].to_s.downcase
|
14
|
+
end
|
15
|
+
|
16
|
+
alias snakefy snakecase
|
17
|
+
|
18
|
+
def rjust_blanks length
|
19
|
+
rjust length, " "
|
20
|
+
end
|
21
|
+
|
22
|
+
def rjust_zeroes length
|
23
|
+
rjust length, "0"
|
24
|
+
end
|
25
|
+
|
26
|
+
def ljust_blanks length
|
27
|
+
ljust length, " "
|
28
|
+
end
|
29
|
+
|
30
|
+
def ljust_zeroes length
|
31
|
+
ljust length, "0"
|
8
32
|
end
|
9
33
|
end
|
data/lib/lizarb/version.rb
CHANGED