roku_builder_generator 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7f0d265e0536b2d232071db29b4b0f148955692f39da78480f2bbdf92d30009
4
- data.tar.gz: 1d281de39f61957d8429c4b23d91ec10fc450a6f70daceba7df8e5dc27d05493
3
+ metadata.gz: 50d50e79d829314444a02c6dfea8082c609185b2efdd0951c33f754daa6fcbda
4
+ data.tar.gz: 4ecb281d387c3eb92fa9dd345a75670ba2596d98dc831748a4cbe4842122cb69
5
5
  SHA512:
6
- metadata.gz: 17d09c2b8848a142fe8e8455d2161a3ad85dc352348e02146b8859dc35b8c3c1fe08e1e8e694fc6fe52336f4507a081fb2c8614ed2c700e1c6843683ab1a4280
7
- data.tar.gz: 213a0704e67dca3de6103f8924b6053111f3e272d574001748ec52c124923975b68ffb62c65ad1838767515509b5d09b92d79a0e31725b7f49267823659e7f22
6
+ metadata.gz: 226244599f730ae30f767a8473c48e9d416e0579b1e4ba643db134afd1fc2cd942210bb6dd80434735618f4fbd82f549314a9273bd789761bd501b9f8afded2c
7
+ data.tar.gz: 8e0a6d16062f870f60107977ad63a43e71945ede45d6d6aa7db5dd643d8efe4a3290b71efab6c1eac057799eaeda4dbc28755c040798ea1caab26e5e9dd8bab7
data/README.md CHANGED
@@ -31,6 +31,10 @@ Options:
31
31
  --base-dir Base directory for generated brs/xml code (eg.: 'brands/core/components/<type>s')
32
32
  --with-config Add empty config JSON
33
33
  --config-dir Use custom directory for config json (eg.: 'brands/core/region/US/configs/<type>s')
34
+ --with-tests Add unit tests
35
+ --only-tests Only unit tests
36
+ --tests-dir Use custom directory for unit tests
37
+
34
38
  ```
35
39
 
36
40
  ### Examples
@@ -43,6 +47,10 @@ Generate a task ("Bar"), but just display the output on screen:
43
47
 
44
48
  `roku --generate task --name bar --dry-run -V`
45
49
 
50
+ Generate a module ("Buz"), and also generate config and unit tests
51
+
52
+ `roku --generate module --name buz --with-config --with-tests`
53
+
46
54
  ### Config
47
55
 
48
56
  You can supplement the default configuration using a local file `.roku_builder_generator.json`
@@ -7,6 +7,7 @@ def default_config()
7
7
  return {
8
8
  :component_dir => "brands/%brand%/components",
9
9
  :config_dir => "brands/%brand%/region/US/configs",
10
+ :unitTests_dir => "brands/unit-tests/components/tests",
10
11
  :template_dir => "roku_builder_generator"
11
12
  }
12
13
  end
@@ -23,6 +24,11 @@ def default_config_dir(component_type, brand = 'core', base_dir = nil)
23
24
  return "#{base_dir}/#{component_type.capitalize()}s"
24
25
  end
25
26
 
27
+ def default_unitTests_dir(component_type, base_dir = nil)
28
+ base_dir = base_dir || default_config[:unitTests_dir]
29
+ return "#{base_dir}/#{component_type.capitalize()}s"
30
+ end
31
+
26
32
 
27
33
  def replace_brand(directory, newBrand = 'core')
28
34
  directory["%brand%"]=newBrand
@@ -65,6 +71,11 @@ module RokuBuilder
65
71
  return "./#{base_dir}"
66
72
  end
67
73
 
74
+ def get_unitTests_output_dir(component_type, custom_dir = nil )
75
+ base_dir = !custom_dir.nil? ? custom_dir : default_unitTests_dir(component_type)
76
+ return "./#{base_dir}"
77
+ end
78
+
68
79
  # Hook to add options to the parser
69
80
  # The keys set in options for commands must match the keys in the commands
70
81
  # hash
@@ -93,6 +104,16 @@ module RokuBuilder
93
104
  parser.on("--config-dir", "Use custom directory for config json (eg.: '#{default_config_dir('<type>')}')") do |d|
94
105
  options[:config_dir] = d
95
106
  end
107
+ parser.on("--with-tests", "Add unit tests") do |d|
108
+ options[:with_tests] = true
109
+ end
110
+ parser.on("--only-tests", "Only unit tests") do |d|
111
+ options[:only_tests] = true
112
+ options[:with_tests] = true
113
+ end
114
+ parser.on("--tests-dir", "Use custom directory for unit tests (eg.: '#{default_unitTests_dir('<type>')}')") do |d|
115
+ options[:tests_dir] = d
116
+ end
96
117
  parser.on("--dry-run", "Do not write files, just output") do |d|
97
118
  options[:dry_run] = true
98
119
  end
@@ -130,7 +151,6 @@ module RokuBuilder
130
151
 
131
152
  def component_has_config_json(component_type)
132
153
  ['module', 'screen', 'manager'].include? component_type
133
-
134
154
  end
135
155
 
136
156
  def generate(options:)
@@ -153,27 +173,52 @@ module RokuBuilder
153
173
  brs_text = component.render("brs")
154
174
  json_text = options[:with_config] && component_has_config_json(component_type) ? component.render("json") : nil
155
175
 
176
+ test_xml_text = options[:with_tests] ? component.renderTest("xml") : nil
177
+ test_brs_text = options[:with_tests] ? component.renderTest("brs") : nil
178
+ testSetup_brs_text = options[:with_tests] ? component.renderTestSetup() : nil
179
+
156
180
  output_dir = get_output_dir(component_type, component_name, brand, component_parent_dir, options[:custom_dir], config[:component_dir])
157
181
  output_config_dir = get_config_output_dir(component_type, brand, options[:config_dir])
158
182
  output_file_name = File.join(output_dir, component_name)
159
183
  output_config_file_name = File.join(output_config_dir, component_proper_name)
160
184
 
185
+ output_unitTests_dir = get_unitTests_output_dir(component_type, options[:config_dir])
186
+
187
+ test_component_name= "Test_"+component_proper_name
188
+
189
+ output_test_file_name = File.join(output_unitTests_dir, test_component_name)
190
+ output_test_setup_file_name= File.join(output_unitTests_dir, test_component_name+".setup")
191
+
161
192
  if(options[:dry_run])
162
193
  @logger.unknown "Dry Run, not writing files"
163
194
  show_line()
164
- display_file(output_file_name+".xml", xml_text)
165
- display_file(output_file_name+".brs", brs_text)
166
- display_file(output_config_file_name+".json", json_text)
195
+ unless options[:only_tests]
196
+ display_file(output_file_name+".xml", xml_text)
197
+ display_file(output_file_name+".brs", brs_text)
198
+ display_file(output_config_file_name+".json", json_text)
199
+ end
200
+
201
+ display_file(output_test_file_name+".xml", test_xml_text)
202
+ display_file(output_test_file_name+".brs", test_brs_text)
203
+ display_file(output_test_setup_file_name+".brs", testSetup_brs_text)
167
204
  else
168
205
  @logger.unknown "Writing files"
169
206
  show_line()
170
- FileUtils.mkdir_p output_dir
171
- unless json_text.nil?
172
- FileUtils.mkdir_p output_config_dir
207
+ unless options[:only_tests]
208
+ FileUtils.mkdir_p output_dir
209
+ unless json_text.nil?
210
+ FileUtils.mkdir_p output_config_dir
211
+ end
212
+ write_file(output_file_name+".xml", xml_text)
213
+ write_file(output_file_name+".brs", brs_text)
214
+ write_file(output_config_file_name+".json", json_text)
215
+ end
216
+ unless test_xml_text.nil?
217
+ FileUtils.mkdir_p output_unitTests_dir
173
218
  end
174
- write_file(output_file_name+".xml", xml_text)
175
- write_file(output_file_name+".brs", brs_text)
176
- write_file(output_config_file_name+".json", json_text)
219
+ write_file(output_test_file_name+".xml", test_xml_text)
220
+ write_file(output_test_file_name+".brs", test_brs_text)
221
+ write_file(output_test_setup_file_name+".brs", testSetup_brs_text)
177
222
  end
178
223
  end
179
224
 
@@ -27,6 +27,26 @@ module RokuBuilderGenerator
27
27
  return nil
28
28
  end
29
29
 
30
+ def renderTest(file_type)
31
+ file_name = get_template_name("test", file_type)
32
+
33
+ unless file_name.nil?
34
+ template = File.read(file_name)
35
+ return render_template(template)
36
+ end
37
+ return nil
38
+ end
39
+
40
+ def renderTestSetup()
41
+ file_name = get_template_name("test.setup", "brs")
42
+
43
+ unless file_name.nil?
44
+ template = File.read(file_name)
45
+ return render_template(template)
46
+ end
47
+ return nil
48
+ end
49
+
30
50
  def log(message)
31
51
  unless @logger.nil?
32
52
  @logger.info message
@@ -0,0 +1,6 @@
1
+ sub init()
2
+ Runner = TestRunner()
3
+ Runner.SetFunctions([
4
+ TestSuite_<%= name %>_Setup
5
+ ])
6
+ end sub
@@ -0,0 +1,20 @@
1
+ function TestSuite_<%= name %>_Setup()
2
+ ' Inherit your test suite from BaseTestSuite
3
+ this = BaseTestSuite()
4
+
5
+ ' Test suite name for log statistics
6
+ this.Name = "TestSuite_<%= name %>_Setup"
7
+
8
+ ' Add tests to suite's tests collection
9
+ this.addTest("TestCase_Config_Exists", TestCase_Config_Exists)
10
+
11
+ return this
12
+ end function
13
+
14
+ function TestCase_Example()
15
+ config = getGlobalAA().channelConfig
16
+ codebox = getGlobalAA().codebox
17
+
18
+ m.assertNotInvalid(config)
19
+ m.assertNotInvalid(codebox)
20
+ end function
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <!-- ##COPYRIGHT HEADER## -->
3
+
4
+ <component name="Test_<%= name %>" extends="<%= name %>">
5
+ <!-- Function, used by framework, to run tests. Should not be called manually! -->
6
+ <interface>
7
+ <function name="TestFramework__RunNodeTests"/>
8
+ </interface>
9
+
10
+ <!-- Import test suites. -->
11
+ <script type="text/brightscript" uri="Test_<%= name %>.brs" />
12
+ <script type="text/brightscript" uri="Test_<%= name %>.setup.brs" />
13
+
14
+ <!-- Import test framework. -->
15
+ <script type="text/brightscript" uri="pkg:/source/UnitTestFramework.brs"/>
16
+ </component>
@@ -1,4 +1,4 @@
1
1
  module RokuBuilderGenerator
2
2
  NAME = "roku_builder_generator"
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roku_builder_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Pearce
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-15 00:00:00.000000000 Z
11
+ date: 2022-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roku_builder
@@ -58,13 +58,16 @@ files:
58
58
  - lib/roku_builder_generator/templates/manager.brs.erb
59
59
  - lib/roku_builder_generator/templates/module.xml.erb
60
60
  - lib/roku_builder_generator/templates/screen.xml.erb
61
+ - lib/roku_builder_generator/templates/test.brs.erb
62
+ - lib/roku_builder_generator/templates/test.setup.brs.erb
63
+ - lib/roku_builder_generator/templates/test.xml.erb
61
64
  - lib/roku_builder_generator/utils.rb
62
65
  - lib/roku_builder_generator/version.rb
63
66
  - roku_builder_generator.gemspec
64
67
  homepage: ''
65
68
  licenses: []
66
69
  metadata: {}
67
- post_install_message:
70
+ post_install_message:
68
71
  rdoc_options: []
69
72
  require_paths:
70
73
  - lib
@@ -79,8 +82,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
82
  - !ruby/object:Gem::Version
80
83
  version: '0'
81
84
  requirements: []
82
- rubygems_version: 3.0.8
83
- signing_key:
85
+ rubygems_version: 3.2.32
86
+ signing_key:
84
87
  specification_version: 4
85
88
  summary: RokuBuilder Generator Plugin
86
89
  test_files: []