teuton 2.1.8 → 2.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -8
  3. data/bin/check_teuton +43 -0
  4. data/docs/changelog/contributions.md +32 -0
  5. data/docs/changelog/v2.1.md +22 -0
  6. data/docs/changelog/v2.2.md +29 -0
  7. data/docs/commands/README.md +105 -7
  8. data/docs/commands/example_check.md +54 -0
  9. data/docs/commands/example_run.md +112 -0
  10. data/docs/dsl/README.md +11 -9
  11. data/docs/dsl/definition/expect.md +25 -21
  12. data/docs/dsl/definition/group.md +5 -1
  13. data/docs/dsl/definition/result.md +45 -34
  14. data/docs/dsl/definition/run_local.md +34 -0
  15. data/docs/dsl/definition/run_remote.md +119 -0
  16. data/docs/dsl/definition/target.md +6 -0
  17. data/docs/dsl/execution/export.md +27 -19
  18. data/docs/dsl/execution/play.md +4 -0
  19. data/docs/dsl/execution/send.md +21 -2
  20. data/docs/dsl/execution/show.md +13 -8
  21. data/docs/dsl/setting/get.md +24 -8
  22. data/docs/dsl/setting/set.md +8 -3
  23. data/docs/install/README.md +19 -26
  24. data/docs/install/modes_of_use.md +27 -26
  25. data/docs/install/scripts.md +53 -36
  26. data/docs/install/vagrant_docker.md +56 -0
  27. data/docs/learn/README.md +13 -6
  28. data/docs/learn/example-01-target.md +78 -61
  29. data/docs/learn/example-02-config.md +152 -0
  30. data/docs/learn/example-03-remote-hosts.md +31 -25
  31. data/docs/learn/example-04-use.md +23 -17
  32. data/docs/learn/example-05-debug.md +24 -17
  33. data/docs/learn/example-06-log.md +70 -0
  34. data/lib/teuton/application.rb +7 -4
  35. data/lib/teuton/case_manager/case/case.rb +4 -1
  36. data/lib/teuton/case_manager/case/dsl/expect.rb +3 -1
  37. data/lib/teuton/case_manager/case/dsl/goto.rb +12 -7
  38. data/lib/teuton/case_manager/case/dsl/macro.rb +38 -0
  39. data/lib/teuton/case_manager/case/dsl/main.rb +1 -2
  40. data/lib/teuton/case_manager/case/dsl/target.rb +1 -1
  41. data/lib/teuton/case_manager/case/runner.rb +7 -7
  42. data/lib/teuton/case_manager/case_manager.rb +1 -20
  43. data/lib/teuton/case_manager/check_cases.rb +12 -2
  44. data/lib/teuton/case_manager/dsl.rb +4 -6
  45. data/lib/teuton/case_manager/export_manager.rb +29 -3
  46. data/lib/teuton/case_manager/report.rb +29 -8
  47. data/lib/teuton/case_manager/show.rb +8 -4
  48. data/lib/teuton/cli.rb +1 -0
  49. data/lib/teuton/cli/play.rb +1 -0
  50. data/lib/teuton/cli/version.rb +1 -4
  51. data/lib/teuton/files/config.yaml +0 -1
  52. data/lib/teuton/files/start.rb +1 -1
  53. data/lib/teuton/files/template/case.html +135 -0
  54. data/lib/teuton/files/template/resume.html +115 -0
  55. data/lib/teuton/project/laboratory/builtin.rb +2 -1
  56. data/lib/teuton/project/laboratory/dsl.rb +13 -15
  57. data/lib/teuton/project/laboratory/laboratory.rb +5 -1
  58. data/lib/teuton/project/laboratory/show.rb +21 -13
  59. data/lib/teuton/project/name_file_finder.rb +6 -1
  60. data/lib/teuton/project/project.rb +7 -3
  61. data/lib/teuton/project/readme/dsl.rb +3 -1
  62. data/lib/teuton/project/readme/readme.rb +37 -26
  63. data/lib/teuton/project/skeleton.rb +20 -4
  64. data/lib/teuton/report/close.rb +15 -11
  65. data/lib/teuton/report/formatter/formatter_factory.rb +10 -6
  66. data/lib/teuton/report/formatter/html_formatter.rb +16 -79
  67. data/lib/teuton/report/formatter/resume_html_formatter.rb +39 -0
  68. data/lib/teuton/report/formatter/resume_yaml_formatter.rb +7 -1
  69. data/lib/teuton/report/report.rb +5 -4
  70. data/lib/teuton/report/show.rb +55 -26
  71. metadata +26 -39
  72. data/docs/changelog/todo.md +0 -46
  73. data/docs/commands/create_skeleton.md +0 -31
  74. data/docs/commands/help.md +0 -13
  75. data/docs/commands/revise_test.md +0 -46
  76. data/docs/commands/run_test_unit.md +0 -78
  77. data/docs/commands/show_version.md +0 -9
  78. data/docs/developers/01-telnet.md +0 -121
  79. data/docs/developers/02-ssh.md +0 -93
  80. data/docs/developers/03-encoding.md +0 -153
  81. data/docs/developers/comparative.md +0 -17
  82. data/docs/dsl/_Sidebar.md +0 -30
  83. data/docs/dsl/definition/goto.md +0 -112
  84. data/docs/dsl/definition/run.md +0 -23
  85. data/docs/install/tested_os.md +0 -25
  86. data/docs/install/vagrant.md +0 -9
  87. data/docs/learn/example-02-configfile.md +0 -174
  88. data/docs/learn/quick-demo.md +0 -170
  89. data/lib/teuton/case_manager/case/dsl/check.rb +0 -24
  90. data/lib/teuton/case_manager/case/dsl/missing.rb +0 -12
  91. data/lib/teuton/files/gitignore +0 -2
@@ -1,4 +1,5 @@
1
-
1
+ #
2
+ # EXPERIMENTAL class
2
3
  class Builtin
3
4
  attr_accessor :param
4
5
 
@@ -11,7 +11,7 @@
11
11
  # * set
12
12
  class Laboratory
13
13
  def readme(_text)
14
- # Usefull for "teuton reamde" action.
14
+ # Usefull for "teuton readme" command action.
15
15
  end
16
16
 
17
17
  def target(desc, args = {})
@@ -23,37 +23,35 @@ class Laboratory
23
23
  end
24
24
  alias goal target
25
25
 
26
- def request(text)
27
- @requests << text.to_s
28
- end
26
+ # def request(text)
27
+ # @requests << text.to_s
28
+ # end
29
29
 
30
30
  def tempfile(_tempfile = nil)
31
31
  'tempfile'
32
32
  end
33
33
 
34
+ def run(command, args = {})
35
+ args[:exec] = command
36
+ host = :localhost
37
+ host = args[:on] if args[:on]
38
+ goto(host, args)
39
+ end
40
+
34
41
  def goto(host = :localhost, args = {})
35
42
  result.reset
43
+ args[:on] = host unless args[:on]
36
44
 
37
45
  if @hosts[host]
38
46
  @hosts[host] += 1
39
47
  else
40
48
  @hosts[host] = 1
41
49
  end
42
- verboseln " goto #{host} and #{args}"
43
- end
44
-
45
- def run(command, args = {})
46
- args[:exec] = command
47
- goto(:localhost, args)
50
+ verboseln " run '#{args[:exec]}' on #{args[:on]}"
48
51
  end
49
52
 
50
53
  def expect(_cond, args = {})
51
- #unless [ String, Array, Regexp].include? _cond.class
52
- # verboseln "[ERROR] expect #{_cond} (#{_cond.class})"
53
- # return
54
- #end
55
54
  verboseln " alter #{result.alterations}" unless result.alterations.empty?
56
- #verboseln " expect #{result.expected} (#{result.expected.class})"
57
55
  verboseln " expect #{_cond} (#{_cond.class})"
58
56
  verboseln ''
59
57
  end
@@ -43,6 +43,8 @@ alias play start
43
43
  class Laboratory
44
44
  attr_reader :result
45
45
 
46
+ ##
47
+ # Initialize instance
46
48
  def initialize(script_path, config_path)
47
49
  @path = {}
48
50
  @path[:script] = script_path
@@ -52,6 +54,8 @@ class Laboratory
52
54
  reset
53
55
  end
54
56
 
57
+ ##
58
+ # Set attibutes to default values
55
59
  def reset
56
60
  @result = Result.new
57
61
  @targetid = 0
@@ -59,7 +63,7 @@ class Laboratory
59
63
  @gets = {}
60
64
  @sets = {}
61
65
  @hosts = {}
62
- @requests = []
66
+ @requests = [] # REVISE this
63
67
  @verbose = Application.instance.verbose
64
68
  end
65
69
  end
@@ -9,6 +9,8 @@ require_relative '../configfile_reader'
9
9
  # * show_stats
10
10
  # * show_config
11
11
  class Laboratory
12
+ ##
13
+ # Display DSL on screen
12
14
  def show_dsl
13
15
  @verbose = true
14
16
  process_content
@@ -16,6 +18,8 @@ class Laboratory
16
18
  show_config
17
19
  end
18
20
 
21
+ ##
22
+ # Display stats on screen
19
23
  def show_stats
20
24
  @stats[:hosts] = 0
21
25
  @hosts.each_pair { |_k, v| @stats[:hosts] += v }
@@ -45,6 +49,8 @@ class Laboratory
45
49
  verboseln my_screen_table.to_s + "\n"
46
50
  end
47
51
 
52
+ ##
53
+ # Display config on screen
48
54
  def show_config
49
55
  @verbose = false
50
56
  process_content
@@ -52,19 +58,19 @@ class Laboratory
52
58
  revise_config_content
53
59
  end
54
60
 
55
- def show_requests
56
- @verbose = false
57
- process_content
58
- @verbose = true
59
- my_screen_table = Terminal::Table.new do |st|
60
- st.add_row ['Lines', 'REQUEST description']
61
- st.add_separator
62
- @requests.each_with_index do |line, index|
63
- st.add_row ['%03d' % index, line]
64
- end
65
- end
66
- verboseln my_screen_table
67
- end
61
+ # def show_requests
62
+ # @verbose = false
63
+ # process_content
64
+ # @verbose = true
65
+ # my_screen_table = Terminal::Table.new do |st|
66
+ # st.add_row ['Lines', 'REQUEST description']
67
+ # st.add_separator
68
+ # @requests.each_with_index do |line, index|
69
+ # st.add_row ['%03d' % index, line]
70
+ # end
71
+ # end
72
+ # verboseln my_screen_table
73
+ # end
68
74
 
69
75
  private
70
76
 
@@ -121,6 +127,8 @@ class Laboratory
121
127
  verboseln YAML.dump(output)
122
128
  end
123
129
 
130
+ ##
131
+ # Revive and check config content
124
132
  def revise_config_content
125
133
  @verbose = true
126
134
  my_screen_table = Terminal::Table.new do |st|
@@ -116,6 +116,8 @@ module NameFileFinder
116
116
  verboseln Rainbow(trim(app.script_path)).blue.bright
117
117
  verbose Rainbow('[INFO] ConfigPath => ').blue
118
118
  verboseln Rainbow(trim(app.config_path)).blue.bright
119
+ verbose Rainbow('[INFO] Pwd => ').blue
120
+ verboseln Rainbow(app.running_basedir).blue.bright
119
121
  verbose Rainbow('[INFO] TestName => ').blue
120
122
  verboseln Rainbow(trim(app.test_name)).blue.bright
121
123
  end
@@ -125,8 +127,11 @@ module NameFileFinder
125
127
  # @param input (String)
126
128
  # @return String
127
129
  def self.trim(input)
130
+ return input unless input.to_s.start_with? Dir.pwd.to_s
131
+
128
132
  output = input.to_s
129
- output = "...#{input[input.size - 50, input.size]}" if output.size > 65
133
+ offset = (Dir.pwd).length + 1
134
+ output = "#{input[offset, input.size]}"
130
135
  output.to_s
131
136
  end
132
137
 
@@ -33,16 +33,20 @@ module Project ##
33
33
  # @param options (Array) Array of input options
34
34
  def self.play(projectpath, options)
35
35
  Application.instance.options.merge! options
36
- process_input_case_option
36
+ process_input_options
37
37
  NameFileFinder.find_filenames_for(projectpath)
38
38
  NameFileFinder.puts_input_info_on_screen
39
39
  require_dsl_and_script('../case_manager/dsl') # Define DSL keywords
40
40
  end
41
41
 
42
42
  ##
43
- # Convert input case options String to an Array of integers
44
- def self.process_input_case_option
43
+ # Preprocess input options:
44
+ # * Convert input case options String to an Array of integers
45
+ # * Read color input option
46
+ def self.process_input_options
45
47
  options = Application.instance.options
48
+ options['color'] = true if options['color'].nil?
49
+ Rainbow.enabled = options['color']
46
50
  return if options['case'].nil?
47
51
 
48
52
  a = options['case'].split(',')
@@ -59,7 +59,9 @@ class Readme
59
59
 
60
60
  def run(command, args = {})
61
61
  args[:exec] = command
62
- goto(:localhost, args)
62
+ host = :localhost
63
+ host = args[:on] if args[:on]
64
+ goto(host, args)
63
65
  end
64
66
 
65
67
  def expect(_cond, _args = {})
@@ -31,6 +31,10 @@ class Readme
31
31
  attr_reader :result
32
32
  attr_reader :data
33
33
 
34
+ ##
35
+ # Initialize Readme instance
36
+ # @param script_path (String) Path to main rb file (start.rb)
37
+ # @param config_path (String) Path to main config file (config.yaml)
34
38
  def initialize(script_path, config_path)
35
39
  @path = {}
36
40
  @path[:script] = script_path
@@ -76,30 +80,8 @@ class Readme
76
80
  show_tail
77
81
  end
78
82
 
79
- def show_content
80
- @data[:groups].each do |group|
81
- next if group[:actions].empty?
82
-
83
- puts "\n## #{group[:name]}\n\n"
84
- group[:readme].each { |line| puts "#{line}\n" }
85
- previous_host = nil
86
- group[:actions].each_with_index do |item, index|
87
- if item[:host].nil? && index.positive?
88
- item[:host] = group[:actions][0][:host]
89
- end
90
- if previous_host.nil? || item[:host] != previous_host
91
- previous_host = item[:host] || 'null'
92
- puts format(Lang::get(:goto), previous_host.upcase)
93
- end
94
-
95
- weight = ''
96
- weight = "(x#{item[:weight]}) " if item[:weight] != 1.0
97
- puts "* #{weight}#{item[:target]}"
98
- item[:readme].each { |line| puts " * #{line}\n" }
99
- end
100
- end
101
- end
102
-
83
+ ##
84
+ # Show README head
103
85
  def show_head
104
86
  app = Application.instance
105
87
  puts '```'
@@ -107,8 +89,8 @@ class Readme
107
89
  puts format(Lang::get(:date), Time.now)
108
90
  puts format(Lang::get(:version), Application::VERSION)
109
91
  puts '```'
110
- puts "\n---\n"
111
- puts "# README.md\n"
92
+ puts "\n"
93
+ puts "# #{app.test_name}\n"
112
94
 
113
95
  i = 1
114
96
  unless @required_hosts.empty?
@@ -135,6 +117,35 @@ class Readme
135
117
  end
136
118
  end
137
119
 
120
+ ##
121
+ # Show README content
122
+ def show_content
123
+ @data[:groups].each do |group|
124
+ next if group[:actions].empty?
125
+
126
+ puts "\n## #{group[:name].capitalize}\n\n"
127
+ group[:readme].each { |line| puts "#{line}\n" }
128
+ previous_host = nil
129
+ group[:actions].each_with_index do |item, index|
130
+ if item[:host].nil? && index.positive?
131
+ item[:host] = group[:actions][0][:host]
132
+ end
133
+ if previous_host.nil? || item[:host] != previous_host
134
+ previous_host = item[:host] || 'null'
135
+ puts format(Lang::get(:goto), previous_host.upcase)
136
+ end
137
+
138
+ weight = ''
139
+ weight = "(x#{item[:weight]}) " if item[:weight] != 1.0
140
+ last = (item[:target].end_with?('.') ? '' : '.')
141
+ puts "* #{weight}#{item[:target]}#{last}"
142
+ item[:readme].each { |line| puts " * #{line}\n" }
143
+ end
144
+ end
145
+ end
146
+
147
+ ##
148
+ # Show README tail
138
149
  def show_tail
139
150
  return if @global_params.empty?
140
151
 
@@ -11,6 +11,9 @@ require 'rainbow'
11
11
  # * create_dirs
12
12
  # * copyfile
13
13
  module Skeleton
14
+ ##
15
+ # Create teuton project skeleton
16
+ # @param project_dir (String)
14
17
  def self.create(project_dir)
15
18
  project_name = File.basename(project_dir)
16
19
  puts "\n[INFO] Creating #{Rainbow(project_name).bright} project skeleton"
@@ -19,12 +22,15 @@ module Skeleton
19
22
  create_main_dir_and_files(project_dir, source_basedir)
20
23
  end
21
24
 
25
+ ##
26
+ # Create main dir and files
27
+ # @param project_dir (String)
28
+ # @param source_basedir (String)
22
29
  def self.create_main_dir_and_files(project_dir, source_basedir)
23
30
  # Directory and files: Ruby script, Configfile, gitignore
24
31
  items = [
25
32
  { source: 'files/config.yaml', target: 'config.yaml' },
26
33
  { source: 'files/start.rb', target: 'start.rb' },
27
- # { source: 'files/README.md', target: 'README.md' },
28
34
  { source: 'files/gitignore', target: '.gitignore' }
29
35
  ]
30
36
  items.each do |item|
@@ -34,6 +40,9 @@ module Skeleton
34
40
  end
35
41
  end
36
42
 
43
+ ##
44
+ # Create dir
45
+ # @param dirpath (String)
37
46
  def self.create_dir(dirpath)
38
47
  if Dir.exist? dirpath
39
48
  puts "* Exists dir! => #{Rainbow(dirpath).yellow}"
@@ -47,17 +56,24 @@ module Skeleton
47
56
  end
48
57
  end
49
58
 
59
+ ##
60
+ # Create dirs
61
+ # @param args (Array)
50
62
  def self.create_dirs(*args)
51
63
  args.each { |arg| create_dir arg }
52
64
  end
53
65
 
54
- def self.copyfile(target, dest)
66
+ ##
67
+ # Copy file
68
+ # @param source (String) Source file
69
+ # @param dest (String) Dest file
70
+ def self.copyfile(source, dest)
55
71
  if File.exist? dest
56
72
  puts "* Exists file! => #{Rainbow(dest).yellow}"
57
73
  else
58
- puts "* File not found! => #{Rainbow(target).yellow}" unless File.exist? target
74
+ puts "* File not found! => #{Rainbow(source).yellow}" unless File.exist? source
59
75
  begin
60
- FileUtils.cp(target, dest)
76
+ FileUtils.cp(source, dest)
61
77
  puts "* Create file => #{Rainbow(dest).green}"
62
78
  rescue StandardError
63
79
  puts "* Create file ERROR => #{Rainbow(dest).red}"
@@ -9,6 +9,8 @@ class Report
9
9
  # * good_weight,d
10
10
  # * fail_weight
11
11
  # * fail_counter
12
+ # rubocop:disable Metrics/AbcSize
13
+ # rubocop:disable Metrics/MethodLength
12
14
  def close
13
15
  app = Application.instance
14
16
  max = 0.0
@@ -16,16 +18,16 @@ class Report
16
18
  fail = 0.0
17
19
  fail_counter = 0
18
20
  @lines.each do |i|
19
- if i.class.to_s == 'Hash'
20
- max += i[:weight] if i[:weight].positive?
21
- if i[:check]
22
- good += i[:weight]
23
- @history += app.letter[:good]
24
- else
25
- fail += i[:weight]
26
- fail_counter += 1
27
- @history += app.letter[:bad]
28
- end
21
+ next unless i.class.to_s == 'Hash'
22
+
23
+ max += i[:weight] if i[:weight].positive?
24
+ if i[:check]
25
+ good += i[:weight]
26
+ @history += app.letter[:good]
27
+ else
28
+ fail += i[:weight]
29
+ fail_counter += 1
30
+ @history += app.letter[:bad]
29
31
  end
30
32
  end
31
33
  @tail[:max_weight] = max
@@ -33,9 +35,11 @@ class Report
33
35
  @tail[:fail_weight] = fail
34
36
  @tail[:fail_counter] = fail_counter
35
37
 
36
- i = good.to_f / max.to_f
38
+ i = good.to_f / max
37
39
  i = 0 if i.nan?
38
40
  @tail[:grade] = (100.0 * i).round
39
41
  @tail[:grade] = 0 if @tail[:unique_fault].positive?
40
42
  end
43
+ # rubocop:enable Metrics/AbcSize
44
+ # rubocop:enable Metrics/MethodLength
41
45
  end
@@ -2,16 +2,17 @@
2
2
 
3
3
  require 'rainbow'
4
4
  require_relative 'json_formatter'
5
+ require_relative 'html_formatter'
5
6
  require_relative 'list_formatter'
6
7
  require_relative 'txt_formatter'
7
8
  require_relative 'yaml_formatter'
8
9
  require_relative 'resume_json_formatter'
10
+ require_relative 'resume_html_formatter'
9
11
  require_relative 'resume_list_formatter'
10
12
  require_relative 'resume_yaml_formatter'
11
13
  require_relative 'resume_txt_formatter'
12
14
  require_relative 'moodle_csv_formatter'
13
15
  require_relative 'csv_formatter'
14
- #require_relative 'html_formatter'
15
16
  require_relative 'xml_formatter'
16
17
 
17
18
  # FormaterFactory module
@@ -23,7 +24,7 @@ module FormatterFactory
23
24
  when :csv
24
25
  f = CSVFormatter.new(report)
25
26
  when :html
26
- # f = HTMLFormatter.new(report)
27
+ f = HTMLFormatter.new(report)
27
28
  when :json
28
29
  f = JSONFormatter.new(report)
29
30
  when :list
@@ -42,12 +43,14 @@ module FormatterFactory
42
43
  f = ResumeTXTFormatter.new(report, true)
43
44
  when :resume_json
44
45
  f = ResumeJSONFormatter.new(report)
46
+ when :resume_html
47
+ f = ResumeHTMLFormatter.new(report)
45
48
  when :resume_list
46
49
  f = ResumeListFormatter.new(report)
47
50
  when :resume_yaml
48
51
  f = ResumeYAMLFormatter.new(report)
49
52
  else
50
- raise Rainbow("[ERROR] FormaterFactory #{format} unkown!").red.bright
53
+ raise "[ERROR] FormaterFactory #{format} unkown!"
51
54
  end
52
55
  f.init(filename)
53
56
  f
@@ -58,14 +61,15 @@ module FormatterFactory
58
61
  colored_text: 'txt',
59
62
  json: 'json',
60
63
  list: 'txt',
64
+ txt: 'txt',
65
+ yaml: 'yaml',
61
66
  resume_colored_text: 'txt',
62
67
  resume_csv: 'csv',
63
68
  resume_json: 'json',
69
+ resume_html: 'html',
64
70
  resume_list: 'txt',
65
71
  resume_txt: 'txt',
66
- resume_yaml: 'yaml',
67
- txt: 'txt',
68
- yaml: 'yaml' }
72
+ resume_yaml: 'yaml' }
69
73
  return format.to_s if data[format].nil?
70
74
 
71
75
  data[format]