teuton 2.3.5 → 2.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/bin/teuton +1 -1
- data/docs/CHANGELOG.md +8 -0
- data/docs/changelog/v2.4.md +16 -0
- data/docs/dsl/definition/expect.md +11 -7
- data/docs/dsl/definition/result.md +7 -6
- data/docs/dsl/definition/run_local.md +0 -1
- data/docs/dsl/definition/target.md +1 -1
- data/docs/dsl/execution/export.md +14 -16
- data/docs/dsl/execution/send.md +12 -12
- data/docs/dsl/setting/get.md +5 -5
- data/docs/es/exit_code.md +59 -0
- data/docs/es/guess_os.md +28 -0
- data/docs/{Challenge-Server-Project.md → ideas/Challenge-Server-Project.md} +0 -0
- data/docs/{changelog → ideas}/contributions.md +0 -0
- data/docs/{changelog → ideas}/ideas.md +0 -0
- data/docs/{changelog → ideas}/servidor-de-retos.md +0 -0
- data/docs/learn/{example-01-target.md → 01-target.md} +1 -3
- data/docs/learn/{example-02-config.md → 02-config.md} +1 -3
- data/docs/learn/{example-03-remote-hosts.md → 03-remote_hosts.md} +10 -10
- data/docs/learn/{example-04-new-test.md → 04-new_test.md} +8 -16
- data/docs/learn/{example-05-use.md → 05-use.md} +1 -3
- data/docs/learn/{example-06-debug.md → 06-debug.md} +1 -3
- data/docs/learn/{example-07-log.md → 07-log.md} +1 -3
- data/docs/learn/{example-08-readme.md → 08-readme.md} +1 -3
- data/docs/learn/{example-09-preserve.md → 09-preserve.md} +7 -4
- data/docs/learn/10-result.md +36 -0
- data/docs/learn/11-moodle_id.md +19 -0
- data/docs/learn/12-get_vars.md +37 -0
- data/docs/learn/13-include.md +59 -0
- data/docs/learn/16-exit_codes.md +24 -0
- data/docs/learn/README.md +19 -17
- data/lib/teuton/application.rb +24 -17
- data/lib/teuton/case_manager/case/builtin/main.rb +2 -3
- data/lib/teuton/case_manager/case/builtin/package.rb +2 -3
- data/lib/teuton/case_manager/case/builtin/service.rb +4 -5
- data/lib/teuton/case_manager/case/builtin/teuton_file.rb +3 -4
- data/lib/teuton/case_manager/case/builtin/teuton_host.rb +5 -6
- data/lib/teuton/case_manager/case/builtin/user.rb +1 -2
- data/lib/teuton/case_manager/case/case.rb +27 -27
- data/lib/teuton/case_manager/case/close.rb +2 -2
- data/lib/teuton/case_manager/case/config.rb +14 -14
- data/lib/teuton/case_manager/case/dsl/expect.rb +46 -39
- data/lib/teuton/case_manager/case/dsl/goto.rb +2 -2
- data/lib/teuton/case_manager/case/dsl/log.rb +5 -6
- data/lib/teuton/case_manager/case/dsl/macro.rb +11 -7
- data/lib/teuton/case_manager/case/dsl/main.rb +8 -8
- data/lib/teuton/case_manager/case/dsl/send.rb +12 -14
- data/lib/teuton/case_manager/case/dsl/unique.rb +1 -3
- data/lib/teuton/case_manager/case/main.rb +5 -5
- data/lib/teuton/case_manager/case/play.rb +1 -1
- data/lib/teuton/case_manager/case/result/ext_array.rb +9 -9
- data/lib/teuton/case_manager/case/result/ext_compare.rb +44 -58
- data/lib/teuton/case_manager/case/result/ext_filter.rb +20 -8
- data/lib/teuton/case_manager/case/result/result.rb +19 -18
- data/lib/teuton/case_manager/case/runner.rb +53 -60
- data/lib/teuton/case_manager/case_manager.rb +15 -15
- data/lib/teuton/case_manager/check_cases.rb +1 -4
- data/lib/teuton/case_manager/dsl.rb +5 -5
- data/lib/teuton/case_manager/export_manager.rb +8 -19
- data/lib/teuton/case_manager/hall_of_fame.rb +4 -6
- data/lib/teuton/case_manager/main.rb +4 -5
- data/lib/teuton/case_manager/report.rb +21 -16
- data/lib/teuton/case_manager/show.rb +2 -2
- data/lib/teuton/case_manager/utils.rb +13 -14
- data/lib/teuton/check/builtin.rb +5 -1
- data/lib/teuton/check/dsl.rb +10 -11
- data/lib/teuton/check/laboratory.rb +13 -15
- data/lib/teuton/check/show.rb +33 -35
- data/lib/teuton/cli.rb +31 -35
- data/lib/teuton/files/start.rb +3 -6
- data/lib/teuton/readme/dsl.rb +12 -6
- data/lib/teuton/readme/lang.rb +20 -21
- data/lib/teuton/readme/readme.rb +40 -42
- data/lib/teuton/report/close.rb +1 -8
- data/lib/teuton/report/formatter/array_formatter.rb +28 -39
- data/lib/teuton/report/formatter/base_formatter.rb +2 -13
- data/lib/teuton/report/formatter/csv_formatter.rb +12 -18
- data/lib/teuton/report/formatter/formatter_factory.rb +31 -29
- data/lib/teuton/report/formatter/html_formatter.rb +37 -21
- data/lib/teuton/report/formatter/json_formatter.rb +2 -8
- data/lib/teuton/report/formatter/list_formatter.rb +6 -12
- data/lib/teuton/report/formatter/moodle_csv_formatter.rb +3 -6
- data/lib/teuton/report/formatter/resume_array_formatter.rb +1 -1
- data/lib/teuton/report/formatter/resume_html_formatter.rb +29 -19
- data/lib/teuton/report/formatter/resume_json_formatter.rb +2 -3
- data/lib/teuton/report/formatter/resume_list_formatter.rb +4 -4
- data/lib/teuton/report/formatter/resume_txt_formatter.rb +14 -18
- data/lib/teuton/report/formatter/resume_yaml_formatter.rb +1 -9
- data/lib/teuton/report/formatter/txt_formatter.rb +19 -22
- data/lib/teuton/report/formatter/xml_formatter.rb +29 -37
- data/lib/teuton/report/formatter/yaml_formatter.rb +2 -12
- data/lib/teuton/report/report.rb +10 -10
- data/lib/teuton/report/show.rb +14 -33
- data/lib/teuton/skeleton.rb +6 -14
- data/lib/teuton/utils/configfile_reader.rb +22 -21
- data/lib/teuton/utils/name_file_finder.rb +21 -26
- data/lib/teuton/utils/verbose.rb +1 -2
- data/lib/teuton/version.rb +3 -4
- data/lib/teuton.rb +5 -6
- metadata +60 -86
- data/bin/check_teuton +0 -41
@@ -1,50 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "colorize"
|
4
4
|
|
5
|
-
# DSL module:
|
6
|
-
# * expect_none
|
7
|
-
# * expect_one
|
8
|
-
# * expect_any
|
9
|
-
# * expect
|
10
|
-
# * expect2
|
11
|
-
# * weight
|
12
5
|
module DSL
|
13
|
-
def expect_none(input)
|
14
|
-
if input.class == Array
|
15
|
-
input.each { |i| result.find(i) }
|
16
|
-
else
|
17
|
-
result.find(input)
|
18
|
-
end
|
19
|
-
expect2 result.count.eq(0)
|
20
|
-
end
|
21
|
-
|
22
|
-
def expect_one(input)
|
23
|
-
if input.class == Array
|
24
|
-
input.each { |i| result.find(i) }
|
25
|
-
else
|
26
|
-
result.find(input)
|
27
|
-
end
|
28
|
-
expect2 result.count.eq(1)
|
29
|
-
end
|
30
|
-
|
31
|
-
def expect_any(input)
|
32
|
-
if input.class == Array
|
33
|
-
input.each { |i| result.find(i) }
|
34
|
-
else
|
35
|
-
result.find(input)
|
36
|
-
end
|
37
|
-
expect2 result.count.gt(0)
|
38
|
-
end
|
39
|
-
|
40
6
|
# expect <condition>, :weight => <value>
|
41
7
|
def expect(input, args = {})
|
42
|
-
if input.
|
8
|
+
if input.instance_of?(TrueClass) || input.instance_of?(FalseClass)
|
43
9
|
expect2(input, args)
|
44
|
-
elsif input.
|
10
|
+
elsif input.instance_of?(String) || input.instance_of?(Regexp) || input.instance_of?(Array)
|
45
11
|
expect_any input
|
46
12
|
else
|
47
|
-
puts "[
|
13
|
+
puts "[TypeError] expect #{input} (#{input.class})"
|
48
14
|
end
|
49
15
|
end
|
50
16
|
|
@@ -64,7 +30,48 @@ module DSL
|
|
64
30
|
app = Application.instance
|
65
31
|
c = app.letter[:bad]
|
66
32
|
c = app.letter[:good] if cond
|
67
|
-
verbose
|
33
|
+
verbose c.colorize(:green)
|
34
|
+
end
|
35
|
+
|
36
|
+
def expect_any(input, args = {})
|
37
|
+
if input.instance_of? Array
|
38
|
+
input.each { |i| result.find(i) }
|
39
|
+
else
|
40
|
+
result.find(input)
|
41
|
+
end
|
42
|
+
expect2 result.count.gt(0), args
|
43
|
+
end
|
44
|
+
|
45
|
+
def expect_first(input, args = {})
|
46
|
+
@result.first
|
47
|
+
output = input
|
48
|
+
output = args[:expected] if args[:expected]
|
49
|
+
expect2 input, expected: output
|
50
|
+
end
|
51
|
+
|
52
|
+
def expect_last(input, args = {})
|
53
|
+
@result.last
|
54
|
+
output = input
|
55
|
+
output = args[:expected] if args[:expected]
|
56
|
+
expect2 input, expected: output
|
57
|
+
end
|
58
|
+
|
59
|
+
def expect_none(input, args = {})
|
60
|
+
if input.instance_of? Array
|
61
|
+
input.each { |i| result.find(i) }
|
62
|
+
else
|
63
|
+
result.find(input)
|
64
|
+
end
|
65
|
+
expect2 result.count.eq(0), args
|
66
|
+
end
|
67
|
+
|
68
|
+
def expect_one(input, args = {})
|
69
|
+
if input.instance_of? Array
|
70
|
+
input.each { |i| result.find(i) }
|
71
|
+
else
|
72
|
+
result.find(input)
|
73
|
+
end
|
74
|
+
expect2 result.count.eq(1), args
|
68
75
|
end
|
69
76
|
|
70
77
|
# Set weight value for the action
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../runner"
|
4
4
|
|
5
5
|
# Case class -> DSL module:
|
6
6
|
# * goto
|
@@ -25,7 +25,7 @@ module DSL
|
|
25
25
|
@action[:command] = args[:execute].to_s if args[:execute]
|
26
26
|
@action[:command] = args[:exec].to_s if args[:exec]
|
27
27
|
tempfile(args[:tempfile]) if args[:tempfile]
|
28
|
-
@action[:encoding] = args[:encoding] ||
|
28
|
+
@action[:encoding] = args[:encoding] || "UTF-8"
|
29
29
|
|
30
30
|
start_time = Time.now
|
31
31
|
run_cmd_on(host)
|
@@ -7,13 +7,12 @@ module DSL
|
|
7
7
|
# Record log message
|
8
8
|
# @param text (String)
|
9
9
|
# @param type (Symbol) Values :info, :warn or :error
|
10
|
-
def log(text =
|
11
|
-
s =
|
12
|
-
s = Rainbow(
|
13
|
-
s = Rainbow(
|
10
|
+
def log(text = "", type = :info)
|
11
|
+
s = ""
|
12
|
+
s = Rainbow("WARN!").color(:yellow) if type == :warn
|
13
|
+
s = Rainbow("ERROR").bg(:red) if type == :error
|
14
14
|
t = Time.now
|
15
|
-
f = format(
|
16
|
-
{ hour: t.hour, min: t.min, sec: t.sec })
|
15
|
+
f = format("%<hour>02d:%<min>02d:%<sec>02d", {hour: t.hour, min: t.min, sec: t.sec})
|
17
16
|
@report.lines << "[#{f}] #{s}: #{text}"
|
18
17
|
end
|
19
18
|
alias msg log
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
|
2
|
+
|
3
|
+
require_relative "../../../application"
|
4
4
|
|
5
5
|
# DSL module methods: assert, missing_method
|
6
6
|
module DSL
|
@@ -17,10 +17,10 @@ module DSL
|
|
17
17
|
input.each_pair { |k, v| set(k, v) }
|
18
18
|
errors = []
|
19
19
|
macros[name][:args].each do |i|
|
20
|
-
errors << i if get(i) ==
|
20
|
+
errors << i if get(i) == "NODATA"
|
21
21
|
end
|
22
22
|
if errors.count > 0
|
23
|
-
log("Macro #{name} => required params #{errors.join(
|
23
|
+
log("Macro #{name} => required params #{errors.join(",")}", :error)
|
24
24
|
else
|
25
25
|
instance_eval(¯os[name][:block])
|
26
26
|
end
|
@@ -32,10 +32,14 @@ module DSL
|
|
32
32
|
# * Invoke macro (assert)
|
33
33
|
def method_missing(method, args = {})
|
34
34
|
a = method.to_s
|
35
|
-
if a.start_with?(
|
36
|
-
return instance_eval("get(:#{a[1, a.size - 2]})")
|
35
|
+
if a.start_with?("_") && a.end_with?("_")
|
36
|
+
return instance_eval("get(:#{a[1, a.size - 2]})", __FILE__, __LINE__)
|
37
37
|
end
|
38
|
-
return macro a[6, a.size], args if a[0,6]==
|
38
|
+
return macro a[6, a.size], args if a[0, 6] == "macro_"
|
39
39
|
macro a, args
|
40
40
|
end
|
41
|
+
|
42
|
+
def respond_to_missing?(method, *)
|
43
|
+
true
|
44
|
+
end
|
41
45
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
3
|
+
require_relative "expect"
|
4
|
+
require_relative "getset"
|
5
|
+
require_relative "goto"
|
6
|
+
require_relative "log"
|
7
|
+
require_relative "macro"
|
8
|
+
require_relative "send"
|
9
|
+
require_relative "target"
|
10
|
+
require_relative "unique"
|
@@ -15,21 +15,21 @@ module DSL
|
|
15
15
|
host = args[:copy_to].to_s
|
16
16
|
return unless @conn_status[host].nil?
|
17
17
|
|
18
|
-
ip = get((host +
|
19
|
-
username = get((host +
|
20
|
-
password = get((host +
|
21
|
-
port = get((host +
|
18
|
+
ip = get((host + "_ip").to_sym)
|
19
|
+
username = get((host + "_username").to_sym).to_s
|
20
|
+
password = get((host + "_password").to_sym).to_s
|
21
|
+
port = get((host + "_port").to_sym).to_i
|
22
22
|
port = 22 if port.zero?
|
23
23
|
|
24
|
-
filename = @report.filename
|
24
|
+
filename = "#{@report.filename}.#{@report.format}"
|
25
|
+
filename = "#{@report.filename}.txt" if @report.format == :colored_text
|
25
26
|
localfilepath = File.join(@report.output_dir, filename)
|
26
27
|
filename = args[:prefix].to_s + filename if args[:prefix]
|
27
28
|
|
28
|
-
if args[:remote_dir]
|
29
|
-
|
29
|
+
remotefilepath = if args[:remote_dir]
|
30
|
+
File.join(args[:remote_dir], filename)
|
30
31
|
else
|
31
|
-
|
32
|
-
remotefilepath = File.join('.', filename)
|
32
|
+
File.join(".", filename)
|
33
33
|
end
|
34
34
|
|
35
35
|
# Upload a file or directory to the remote host
|
@@ -37,9 +37,9 @@ module DSL
|
|
37
37
|
Net::SFTP.start(ip, username, password: password, port: port) do |sftp|
|
38
38
|
sftp.upload!(localfilepath, remotefilepath)
|
39
39
|
end
|
40
|
-
verboseln("=> [ OK ] #{(get(:tt_members)[0,15]).ljust(16)} : #{remotefilepath}")
|
40
|
+
verboseln("=> [ OK ] #{(get(:tt_members)[0, 15]).ljust(16)} : #{remotefilepath}")
|
41
41
|
rescue
|
42
|
-
verboseln("=> [ERROR] #{(get(:tt_members)[0,15]).ljust(16)} : scp #{localfilepath} => #{remotefilepath}")
|
42
|
+
verboseln("=> [ERROR] #{(get(:tt_members)[0, 15]).ljust(16)} : scp #{localfilepath} => #{remotefilepath}")
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -47,7 +47,7 @@ module DSL
|
|
47
47
|
return @action[:tempfile] if input.nil?
|
48
48
|
|
49
49
|
name = input
|
50
|
-
name =
|
50
|
+
name = "teuton.tmp" if input == :default
|
51
51
|
|
52
52
|
@action[:tempfile] = File.join(@tmpdir, name)
|
53
53
|
@action[:remote_tempfile] = File.join(@remote_tmpdir, name)
|
@@ -56,12 +56,10 @@ module DSL
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def tempdir
|
59
|
-
# puts '[WARN] Using DSL.tempdir'
|
60
59
|
@tmpdir
|
61
60
|
end
|
62
61
|
|
63
62
|
def remote_tempfile
|
64
|
-
# puts '[WARN] Using DSL.tempfile'
|
65
63
|
@action[:remote_tempfile]
|
66
64
|
end
|
67
65
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
3
|
+
require_relative "dsl/main"
|
4
|
+
require_relative "config"
|
5
|
+
require_relative "close"
|
6
|
+
require_relative "play"
|
7
|
+
require_relative "runner"
|
@@ -3,12 +3,12 @@
|
|
3
3
|
# This is an extension of Result class
|
4
4
|
class Result
|
5
5
|
def count
|
6
|
-
@alterations <<
|
7
|
-
if @content.
|
6
|
+
@alterations << "count"
|
7
|
+
if @content.instance_of? Array
|
8
8
|
@content = [@content.count]
|
9
9
|
self
|
10
10
|
elsif @content.nil?
|
11
|
-
@content = [
|
11
|
+
@content = ["0"]
|
12
12
|
else
|
13
13
|
@content = [@content.to_i.to_s]
|
14
14
|
end
|
@@ -31,13 +31,13 @@ class Result
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def empty
|
34
|
-
@expected =
|
34
|
+
@expected = "Empty!"
|
35
35
|
@content.empty
|
36
36
|
end
|
37
37
|
|
38
|
-
alias count!
|
39
|
-
alias length
|
40
|
-
alias len
|
41
|
-
alias size
|
42
|
-
alias empty?
|
38
|
+
alias count! count
|
39
|
+
alias length count
|
40
|
+
alias len count
|
41
|
+
alias size count
|
42
|
+
alias empty? empty
|
43
43
|
end
|
@@ -1,104 +1,93 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# This is an extension of Result class
|
4
|
-
# rubocop:disable Metrics/ClassLength
|
5
4
|
class Result
|
6
|
-
# rubocop:disable Metrics/MethodLength
|
7
|
-
# Return true when content is equal than input
|
8
|
-
# @param input (Object)
|
9
5
|
def eq(input)
|
6
|
+
# Return true when content is equal than input
|
10
7
|
@expected = input
|
11
8
|
|
12
9
|
case input.class.to_s
|
13
|
-
when
|
10
|
+
when "Fixnum"
|
14
11
|
value = @content[0].to_i
|
15
|
-
puts
|
16
|
-
puts
|
17
|
-
when
|
12
|
+
puts "[WARN] Fixnum is a Ruby deprecated class!"
|
13
|
+
puts " (Upgrade your Ruby version)"
|
14
|
+
when "Float"
|
18
15
|
value = @content[0].to_f
|
19
|
-
when
|
16
|
+
when "Integer"
|
20
17
|
value = @content[0].to_i
|
21
|
-
when
|
18
|
+
when "String"
|
22
19
|
value = @content[0].to_s
|
23
20
|
else
|
24
21
|
value = @content[0]
|
25
22
|
end
|
26
23
|
value == input
|
27
24
|
end
|
28
|
-
|
29
|
-
alias eq
|
30
|
-
alias equal
|
31
|
-
alias
|
32
|
-
alias is_equal? eq
|
25
|
+
alias eq? eq
|
26
|
+
alias equal eq
|
27
|
+
alias equal? eq
|
28
|
+
alias is_equal? eq
|
33
29
|
|
34
|
-
# rubocop:disable Metrics/MethodLength
|
35
30
|
def neq(external)
|
36
31
|
@expected = "Not equal to #{external}"
|
37
32
|
|
38
33
|
case external.class.to_s
|
39
|
-
when
|
34
|
+
when "Fixnum"
|
40
35
|
internal = @content[0].to_i
|
41
|
-
puts
|
42
|
-
puts
|
43
|
-
when
|
36
|
+
puts "[WARN] Fixnum class is deprecated!"
|
37
|
+
puts " Upgrade your Ruby version."
|
38
|
+
when "Float"
|
44
39
|
internal = @content[0].to_f
|
45
|
-
when
|
40
|
+
when "Integer"
|
46
41
|
internal = @content[0].to_i
|
47
42
|
else
|
48
43
|
internal = @content[0]
|
49
44
|
end
|
50
45
|
internal != external
|
51
46
|
end
|
52
|
-
|
53
|
-
alias neq
|
54
|
-
alias not_equal neq
|
47
|
+
alias neq? neq
|
48
|
+
alias not_equal neq
|
55
49
|
alias not_equal? neq
|
56
50
|
|
57
|
-
# rubocop:disable Metrics/MethodLength
|
58
51
|
def ge(input)
|
59
52
|
@expected = "Greater or equal to #{input}"
|
60
53
|
return false if @content.nil? || @content[0].nil?
|
61
54
|
|
62
55
|
value = @content[0]
|
63
56
|
case input.class.to_s
|
64
|
-
when
|
57
|
+
when "Fixnum"
|
65
58
|
value = @content[0].to_i
|
66
|
-
puts
|
67
|
-
puts
|
68
|
-
when
|
59
|
+
puts "[WARN] Fixnum class is deprecated!"
|
60
|
+
puts " Upgrade your Ruby version."
|
61
|
+
when "Float"
|
69
62
|
value = @content[0].to_f
|
70
|
-
when
|
63
|
+
when "Integer"
|
71
64
|
value = @content[0].to_i
|
72
65
|
end
|
73
66
|
value >= input
|
74
67
|
end
|
75
|
-
|
76
|
-
alias greater_or_equal ge
|
68
|
+
alias greater_or_equal ge
|
77
69
|
alias greater_or_equal? ge
|
78
70
|
|
79
|
-
# rubocop:disable Metrics/MethodLength
|
80
71
|
def gt(input)
|
81
72
|
@expected = "Greater than #{input}"
|
82
73
|
return false if @content.nil? || @content[0].nil?
|
83
74
|
|
84
75
|
value = @content[0]
|
85
76
|
case input.class.to_s
|
86
|
-
when
|
77
|
+
when "Fixnum"
|
87
78
|
value = @content[0].to_i
|
88
|
-
puts
|
89
|
-
puts
|
90
|
-
when
|
79
|
+
puts "[WARN] Fixnum class is deprecated!"
|
80
|
+
puts " Upgrade your Ruby version."
|
81
|
+
when "Float"
|
91
82
|
value = @content[0].to_f
|
92
|
-
when
|
83
|
+
when "Integer"
|
93
84
|
value = @content[0].to_i
|
94
85
|
end
|
95
86
|
value > input
|
96
87
|
end
|
97
|
-
|
98
|
-
alias
|
99
|
-
alias greater_than gt
|
88
|
+
alias greater gt
|
89
|
+
alias greater_than gt
|
100
90
|
|
101
|
-
# rubocop:disable Metrics/MethodLength
|
102
91
|
def le(input)
|
103
92
|
@expected = "Lesser or equal to #{input}"
|
104
93
|
|
@@ -106,41 +95,38 @@ class Result
|
|
106
95
|
|
107
96
|
value = @content[0]
|
108
97
|
case input.class.to_s
|
109
|
-
when
|
98
|
+
when "Fixnum"
|
110
99
|
value = @content[0].to_i
|
111
|
-
puts
|
112
|
-
puts
|
113
|
-
when
|
100
|
+
puts "[WARN] Fixnum class is deprecated!"
|
101
|
+
puts " Upgrade your Ruby version."
|
102
|
+
when "Float"
|
114
103
|
value = @content[0].to_f
|
115
|
-
when
|
104
|
+
when "Integer"
|
116
105
|
value = @content[0].to_i
|
117
106
|
end
|
118
107
|
value <= input
|
119
108
|
end
|
120
|
-
|
121
|
-
alias lesser_or_equal le
|
109
|
+
alias lesser_or_equal le
|
122
110
|
alias lesser_or_equal? le
|
123
111
|
|
124
|
-
# rubocop:disable Metrics/MethodLength
|
125
112
|
def lt(input)
|
126
113
|
@expected = "Lesser than #{input}"
|
127
114
|
return false if @content.nil? || @content[0].nil?
|
128
115
|
|
129
116
|
value = @content[0]
|
130
117
|
case input.class.to_s
|
131
|
-
when
|
118
|
+
when "Fixnum"
|
132
119
|
value = @content[0].to_i
|
133
|
-
puts
|
134
|
-
puts
|
135
|
-
when
|
120
|
+
puts "[WARN] Fixnum class is deprecated!"
|
121
|
+
puts " Upgrade your Ruby version."
|
122
|
+
when "Float"
|
136
123
|
value = @content[0].to_f
|
137
|
-
when
|
124
|
+
when "Integer"
|
138
125
|
value = @content[0].to_i
|
139
126
|
end
|
140
127
|
value < input
|
141
128
|
end
|
142
|
-
|
143
|
-
alias lesser lt
|
129
|
+
alias lesser lt
|
144
130
|
alias smaller lt
|
145
131
|
alias lesser_than lt
|
146
132
|
|
@@ -151,7 +137,7 @@ class Result
|
|
151
137
|
return false if @content.nil?
|
152
138
|
|
153
139
|
target = @content[0].to_f
|
154
|
-
desv
|
140
|
+
desv = (target * 10.0) / 100.0
|
155
141
|
return true if (target - input.to_f).abs.to_f <= desv
|
156
142
|
|
157
143
|
false
|
@@ -6,18 +6,24 @@ class Result
|
|
6
6
|
def find(filter)
|
7
7
|
@alterations << "find(#{filter})"
|
8
8
|
case filter.class.to_s
|
9
|
-
when
|
9
|
+
when "Array"
|
10
10
|
find_when_array(filter)
|
11
|
-
when
|
11
|
+
when "String" || "Integer"
|
12
12
|
@content.select! { |i| i.include?(filter.to_s) }
|
13
|
-
when
|
13
|
+
when "Regexp"
|
14
14
|
@content.select! { |i| filter.match(i) }
|
15
15
|
end
|
16
16
|
self
|
17
17
|
end
|
18
|
-
alias grep
|
19
|
-
alias grep!
|
20
|
-
alias find!
|
18
|
+
alias grep find
|
19
|
+
alias grep! find
|
20
|
+
alias find! find
|
21
|
+
|
22
|
+
def first
|
23
|
+
@alterations << "first"
|
24
|
+
@content = [@content.first]
|
25
|
+
self
|
26
|
+
end
|
21
27
|
|
22
28
|
def not_find(p_filter)
|
23
29
|
@alterations << "not_find(#{p_filter})"
|
@@ -32,7 +38,7 @@ class Result
|
|
32
38
|
@alterations << "since(#{filter})"
|
33
39
|
return self if @content.size.zero?
|
34
40
|
|
35
|
-
if filter.
|
41
|
+
if filter.instance_of? String
|
36
42
|
flag = false
|
37
43
|
@content.select! do |i|
|
38
44
|
flag = true if i.include?(filter.to_s)
|
@@ -42,11 +48,17 @@ class Result
|
|
42
48
|
self
|
43
49
|
end
|
44
50
|
|
51
|
+
def last
|
52
|
+
@alterations << "last"
|
53
|
+
@content = [@content.last]
|
54
|
+
self
|
55
|
+
end
|
56
|
+
|
45
57
|
def until(filter)
|
46
58
|
@alterations << "until(#{filter})"
|
47
59
|
return self if @content.size.zero?
|
48
60
|
|
49
|
-
if filter.
|
61
|
+
if filter.instance_of? String
|
50
62
|
flag = true
|
51
63
|
@content.select! do |i|
|
52
64
|
flag = false if i.include?(filter.to_s)
|
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
3
|
+
require_relative "ext_array"
|
4
|
+
require_relative "ext_compare"
|
5
|
+
require_relative "ext_filter"
|
6
6
|
|
7
7
|
# This object contains data returned by remote/local execution
|
8
8
|
# * initialize
|
@@ -22,7 +22,7 @@ class Result
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def alterations
|
25
|
-
@alterations.join(
|
25
|
+
@alterations.join(" & ")
|
26
26
|
end
|
27
27
|
|
28
28
|
def content=(content)
|
@@ -30,30 +30,31 @@ class Result
|
|
30
30
|
@content = content.clone
|
31
31
|
end
|
32
32
|
|
33
|
-
def reset
|
34
|
-
@content_backup = []
|
35
|
-
@content = []
|
36
|
-
@exitstatus = nil
|
37
|
-
@value = nil
|
38
|
-
@expected = nil
|
39
|
-
@alterations = []
|
40
|
-
end
|
41
|
-
|
42
33
|
def debug
|
43
|
-
print "\n" +
|
34
|
+
print "\n" + "*" * 20
|
44
35
|
print " [DEBUG] count=#{@content.count} "
|
45
|
-
puts
|
36
|
+
puts "*" * 20
|
46
37
|
@content.each_with_index do |item, index|
|
47
|
-
puts format(
|
38
|
+
puts format("%<index>2d: %<item>s", {index: index, item: item})
|
48
39
|
end
|
49
|
-
puts
|
40
|
+
puts "*" * 57
|
50
41
|
end
|
51
42
|
|
52
43
|
def expected
|
53
44
|
@expected.to_s
|
54
45
|
end
|
55
46
|
|
47
|
+
def reset
|
48
|
+
@content_backup = []
|
49
|
+
@content = []
|
50
|
+
@exitstatus = nil
|
51
|
+
@value = nil
|
52
|
+
@expected = nil
|
53
|
+
@alterations = []
|
54
|
+
end
|
55
|
+
|
56
56
|
def ok?
|
57
|
+
# REVISE THIS
|
57
58
|
return false if @exitstatus.nil?
|
58
59
|
|
59
60
|
@exitstatus.zero?
|
@@ -63,7 +64,7 @@ class Result
|
|
63
64
|
temp = @content_backup.clone
|
64
65
|
reset
|
65
66
|
@content_backup = temp
|
66
|
-
@content
|
67
|
+
@content = temp.clone
|
67
68
|
end
|
68
69
|
alias restore! restore
|
69
70
|
|