flok 0.0.40 → 0.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/app/drivers/chrome/src/dispatch.js +7 -2
  3. data/app/kern/dispatch.js +10 -1
  4. data/app/kern/mod/event.js +9 -0
  5. data/app/kern/pagers/pg_mem.js +21 -0
  6. data/app/kern/pagers/pg_net_sim.js +44 -0
  7. data/app/kern/pagers/pg_spec.js +23 -0
  8. data/app/kern/services/vm.rb +60 -64
  9. data/bin/flok +44 -23
  10. data/docs/callout.md +1 -1
  11. data/docs/client_api.md +5 -2
  12. data/docs/config_yml.md +41 -0
  13. data/docs/controllers.md +4 -0
  14. data/docs/datatypes.md +5 -2
  15. data/docs/debug_server.md +2 -0
  16. data/docs/dispatch.md +8 -3
  17. data/docs/known_issues.md +6 -0
  18. data/docs/mod/event.md +25 -20
  19. data/docs/mod/persist.md +1 -1
  20. data/docs/mod/speech.md +12 -0
  21. data/docs/project.md +2 -2
  22. data/docs/services/vm.md +46 -17
  23. data/docs/services/vm/pagers.md +22 -2
  24. data/lib/flok/build.rb +0 -4
  25. data/lib/flok/user_compiler.rb +123 -47
  26. data/lib/flok/user_compiler_templates/ctable.js.erb +39 -1
  27. data/lib/flok/version.rb +1 -1
  28. data/spec/env/global.rb +1 -0
  29. data/spec/env/kern.rb +5 -1
  30. data/spec/etc/cli_spec.rb +337 -322
  31. data/spec/etc/service_compiler/config0.rb +1 -1
  32. data/spec/etc/service_compiler/config0b.rb +1 -0
  33. data/spec/etc/services_compiler_spec.rb +29 -29
  34. data/spec/etc/user_compiler/controller0b.rb +9 -0
  35. data/spec/etc/user_compiler/controller0timer.rb +16 -0
  36. data/spec/etc/user_compiler_spec.rb +24 -1
  37. data/spec/iface/driver/dispatch_spec.rb +8 -2
  38. data/spec/iface/driver/persist_spec.rb +11 -0
  39. data/spec/kern/assets/controller0defer.rb +18 -0
  40. data/spec/kern/assets/controller0defer0.rb +13 -0
  41. data/spec/kern/assets/controller0defer2.rb +17 -0
  42. data/spec/kern/assets/global_on_entry.rb +8 -0
  43. data/spec/kern/assets/global_on_entry2.rb +16 -0
  44. data/spec/kern/assets/global_on_entry3.rb +17 -0
  45. data/spec/kern/assets/global_on_entry4.rb +12 -0
  46. data/spec/kern/assets/interval.rb +29 -0
  47. data/spec/kern/assets/interval2.rb +33 -0
  48. data/spec/kern/assets/interval3.rb +39 -0
  49. data/spec/kern/assets/service1.rb +4 -1
  50. data/spec/kern/assets/service_controller1.rb +11 -0
  51. data/spec/kern/assets/specimin/controller0.rb +74 -0
  52. data/spec/kern/assets/vm/config5.rb +20 -0
  53. data/spec/kern/assets/vm/config6.rb +20 -0
  54. data/spec/kern/assets/vm/controller10.rb +1 -1
  55. data/spec/kern/assets/vm/controller11.rb +1 -1
  56. data/spec/kern/assets/vm/controller12.rb +1 -1
  57. data/spec/kern/assets/vm/controller13.rb +1 -1
  58. data/spec/kern/assets/vm/controller16b.rb +28 -0
  59. data/spec/kern/assets/vm/controller18.rb +1 -1
  60. data/spec/kern/assets/vm/controller21.rb +1 -1
  61. data/spec/kern/assets/vm/controller22.rb +8 -0
  62. data/spec/kern/assets/vm/controller_exc_ewatch.rb +1 -0
  63. data/spec/kern/assets/vm/controller_exc_ewatch2.rb +30 -0
  64. data/spec/kern/assets/vm/controller_exc_ewatch3.rb +16 -0
  65. data/spec/kern/assets/vm/controller_exc_ewatch4.rb +16 -0
  66. data/spec/kern/assets/vm/macros/copy_page_c.rb +1 -0
  67. data/spec/kern/assets/vm/macros/copy_page_ch.rb +25 -0
  68. data/spec/kern/assets/vm/macros/entry_del_c.rb +1 -0
  69. data/spec/kern/assets/vm/macros/entry_del_ch.rb +20 -0
  70. data/spec/kern/assets/vm/macros/entry_insert_c.rb +1 -0
  71. data/spec/kern/assets/vm/macros/entry_insert_ch.rb +23 -0
  72. data/spec/kern/assets/vm/macros/entry_mutable_c.rb +8 -7
  73. data/spec/kern/assets/vm/macros/entry_mutable_ch.rb +34 -0
  74. data/spec/kern/assets/vm/macros/new_page_c.rb +1 -1
  75. data/spec/kern/assets/vm/macros/new_page_c2.rb +1 -1
  76. data/spec/kern/assets/vm/macros/new_page_ch.rb +7 -0
  77. data/spec/kern/assets/vm/pg_mem/config.rb +10 -0
  78. data/spec/kern/assets/vm/pg_mem/config1.rb +10 -0
  79. data/spec/kern/assets/vm/pg_mem/config2.rb +10 -0
  80. data/spec/kern/assets/vm/pg_mem/config3.rb +15 -0
  81. data/spec/kern/assets/vm/pg_mem/write.rb +23 -0
  82. data/spec/kern/assets/vm/pg_mem/write2.rb +38 -0
  83. data/spec/kern/assets/vm/pg_net_sim/config.rb +10 -0
  84. data/spec/kern/assets/vm/pg_net_sim/nothing.rb +12 -0
  85. data/spec/kern/assets/vm/pg_net_sim/pages.json +1 -0
  86. data/spec/kern/assets/vm/pg_net_sim/watch.rb +18 -0
  87. data/spec/kern/callout_spec.rb +1 -1
  88. data/spec/kern/controller_macro_spec.rb +153 -20
  89. data/spec/kern/controller_spec.rb +232 -1
  90. data/spec/kern/debug_ui_spec.rb +235 -235
  91. data/spec/kern/event_spec.rb +112 -0
  92. data/spec/kern/service_controller_spec.rb +14 -2
  93. data/spec/kern/vm_service_mem_pagers_spec.rb +117 -0
  94. data/spec/kern/vm_service_net_sim_pager_spec.rb +97 -0
  95. data/spec/kern/vm_service_spec.rb +304 -17
  96. data/spec/kern/vm_service_spec2.rb +39 -0
  97. metadata +88 -6
  98. data/app/kern/pagers/mem_pager.js +0 -2
  99. data/app/kern/pagers/pg_spec0.js +0 -20
  100. data/lib/flok/project_template/Guardfile +0 -7
  101. data/lib/flok/project_template/config/config.yml +0 -1
@@ -5,11 +5,40 @@ ctable = {
5
5
  <% c._services.each do |s| %>
6
6
  <%= s %>_on_connect(__base__);
7
7
  <% end %>
8
+
9
+ //Register this controller for every single interval timer *now*
10
+ <% actions_for_controller(c.name).each do |a| %>
11
+ <% a.every_handlers.each do |e| %>
12
+ reg_interval(__base__, "<%= e[:name] %>", <%= e[:ticks] %>);
13
+ <% end %>
14
+ <% end %>
15
+
16
+
17
+ //Controller information, includes action, etc. (controller_info)
18
+ var __info__ = tel_deref(__base__);
19
+
20
+ //The 'context' which is user-defined
21
+ var context = __info__.context;
22
+
23
+ //Call global on entry
24
+ <%= c._on_entry %>
8
25
  },
9
26
  __dealloc__: function(__base__) {
27
+ var __info__ = tel_deref(__base__);
28
+
29
+ //Recursively call dealloc
30
+ for (var i = 0; i < __info__.embeds.length; ++i) {
31
+ for (var x = 0; x < __info__.embeds[i].length; ++x) {
32
+ tel_deref(__info__.embeds[i][x]).cte.__dealloc__(__info__.embeds[i][x]);
33
+ }
34
+ }
35
+
10
36
  <% c._services.each do |s| %>
11
37
  <%= s %>_on_disconnect(__base__);
12
38
  <% end %>
39
+
40
+ dereg_evt(__base__);
41
+ tel_del(__base__);
13
42
  },
14
43
  name: '<%= c.name %>',
15
44
  root_view: '<%= c.name %>',
@@ -23,6 +52,7 @@ ctable = {
23
52
 
24
53
  //The 'context' which is user-defined
25
54
  var context = __info__.context;
55
+
26
56
  <%= a.on_entry_src.strip %>
27
57
  },
28
58
  handlers: {
@@ -34,7 +64,15 @@ ctable = {
34
64
  <%= e[:src] %>
35
65
  },
36
66
  <% end %>
37
- }
67
+ <% a.every_handlers.each do |e| %>
68
+ "<%= e[:name] %>": function(__base__, ename, info) {
69
+ var __info__ = tel_deref(__base__);
70
+ var context = __info__.context;
71
+
72
+ <%= e[:src] %>
73
+ },
74
+ <% end %>
75
+ },
38
76
  },
39
77
  <% end %>
40
78
  },
@@ -1,3 +1,3 @@
1
1
  module Flok
2
- VERSION = "0.0.40"
2
+ VERSION = "0.0.41"
3
3
  end
@@ -1,2 +1,3 @@
1
1
  bin_path = File.join(File.dirname(__FILE__), "../../bin/")
2
+ $flok_bin_path = File.join(File.dirname(__FILE__), "../../bin/flok")
2
3
  ENV['PATH'] = "#{bin_path}:#{ENV['PATH']}"
@@ -121,7 +121,7 @@ shared_context "kern" do
121
121
  #There may be a lot going on and you're only interested in a part.
122
122
  #If priority is nil, it won't matter what the priority is, useful for checking exceptions
123
123
  #for non-existant messages
124
- def ignore_up_to msg_name, priority=nil
124
+ def ignore_up_to msg_name, priority=nil, &block
125
125
  @did_get = []
126
126
 
127
127
  loop do
@@ -150,6 +150,10 @@ shared_context "kern" do
150
150
  raise "Found the message #{msg_name.inspect} while calling ignore_up_to... but it's the wrong priority: #{@cp}, should be #{priority}" if @cp != priority
151
151
  end
152
152
 
153
+ if block
154
+ next unless block.call(args)
155
+ end
156
+
153
157
  #Unshift everything in reverse order, we are only peeking here...
154
158
  args.reverse.each do |a|
155
159
  @cq.unshift a
@@ -12,9 +12,7 @@ require 'securerandom'
12
12
  #Execute flok binary
13
13
  def flok args
14
14
  #Execute
15
- ENV['BUNDLE_GEMFILE'] = File.join(Dir.pwd, "Gemfile")
16
- ENV['RUBYOPT'] = ""
17
- res = system("bundle exec flok #{args}")
15
+ res = system("bundle exec #{$flok_bin_path} #{args}")
18
16
  raise "Could not execute bundle exec flok #{args.inspect}" unless res
19
17
  end
20
18
 
@@ -25,126 +23,165 @@ def flok_new
25
23
  #This isn't done with flok() because we don't have a project yet, ergo, no Gemfile
26
24
  #But it's ok because it's *this* development version because we installed a copy of
27
25
  #it before this spec ran in before(:each)
28
- system("flok new test")
26
+ system("#{$flok_bin_path} new test")
29
27
 
30
28
  Dir.chdir "test" do
31
- system('bundle install')
29
+ #We need to modify the gemfile to include a path to this gem project
30
+ #so that bundler will set everything up for us as if this was a real gem
31
+ File.write "Gemfile", %{
32
+ #This gemfile uses this project's path
33
+ source 'https://rubygems.org'
34
+
35
+ gem 'flok', :path => "#{File.join(File.dirname(__FILE__), "../../")}"
36
+ }
32
37
  yield
33
38
  end
34
39
  end
35
40
  end
36
41
 
37
42
  RSpec.describe "CLI" do
38
- before(:all) do
39
- #Uninstall old gems and install the current development gem
40
- system("rake gem:install")
43
+ it "Can be executed via bundle exec" do flok_new do
44
+ flok "build"
45
+ end
46
+ end
47
+
48
+ #When this sets FLOK_CONFIG, the defines is added to the project config.yml
49
+ #to show spec_helper_defines_spec_test. This text should show up in the final
50
+ #source code
51
+ it "Does set the FLOK_CONFIG to the correct file based on PLATFORM" do
52
+ flok_new do
53
+ #Set spec_test in project configuration
54
+ config_yml = YAML.load_file("./config/platforms/#{ENV['PLATFORM']}/config.yml")
55
+ config_yml["DEBUG"]["defines"] = ["spec_test"]
56
+ File.write("./config/platforms/#{ENV['PLATFORM']}/config.yml", config_yml.to_yaml)
57
+
58
+ #Now commit a build
59
+ flok "build"
60
+
61
+ #Now read the application_user file, it should contain the string located in `./app/kern/spec_helper.js`
62
+ #that will only show if the correct defines is set
63
+ application_user = File.read("./products/#{ENV['PLATFORM']}/application_user.js")
64
+ expect(application_user).to include("spec_helper_defines_spec_test")
65
+ end
66
+ end
67
+
68
+ it "Can create a new project with correct directories" do
69
+ flok_new do
70
+ #Should include all entities in the project template with the exception
71
+ #of erb extenseded entities (which will still be included, but they each
72
+ #will not have the erb ending
73
+ template_nodes = nil
74
+ Dir.chdir File.join(File.dirname(__FILE__), "../../lib/flok/project_template") do
75
+ template_nodes = Dir["**/*"].map{|e| e.gsub(/\.erb$/i, "")}
76
+ end
77
+ new_proj_nodes = Dir["**/*"]
78
+ expect(new_proj_nodes.sort).to eq(template_nodes.sort)
79
+
80
+ expect(files).to include("Gemfile")
81
+ end
82
+ end
83
+
84
+ it "Can build a project with every type of platform" do
85
+ platform = ENV['PLATFORM']
86
+ flok_new do
87
+ #Build a new project
88
+ flok "build"
89
+
90
+ #Check it's products directory
91
+ expect(dirs).to include "products"
92
+ Dir.chdir "products" do
93
+ #Has a platform folder
94
+ expect(dirs).to include platform
95
+ Dir.chdir platform do
96
+ #Has an application_user.js file
97
+ expect(files).to include "application_user.js"
98
+
99
+ #The application_user.js contains both the glob/application.js and the glob/user_compiler.js
100
+ glob_application_js = File.read('glob/application.js')
101
+ glob_user_compiler_js = File.read('glob/user_compiler.js')
102
+ application_user_js = File.read('application_user.js')
103
+ expect(application_user_js).to include(glob_application_js)
104
+ expect(application_user_js).to include(glob_user_compiler_js)
105
+
106
+ #Contains the same files as the kernel in the drivers directory
107
+ expect(dirs).to include "drivers"
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+ it "Can build a project with a controller file for each platform" do
114
+ #Compile and then return the length of the application_user.js file
115
+ def compile_with_file path=nil
116
+ #Custom controller to test source with
117
+ controller_src = File.read(path) if path
118
+ flok_new do
119
+ File.write "./app/controllers/controller0.rb", controller_src if path
120
+
121
+ #Build a new project
122
+ flok "build"
123
+
124
+ #Check it's products directory
125
+ Dir.chdir "products" do
126
+ #Has a platform folder
127
+ Dir.chdir @platform do
128
+ glob_application_js = File.read('glob/application.js')
129
+ glob_user_compiler_js = File.read('glob/user_compiler.js')
130
+ application_user_js = File.read('application_user.js')
131
+
132
+ return application_user_js.split("\n").count
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ platform = ENV['PLATFORM']
139
+ @platform = platform
140
+ controller_rb = File.read('./spec/etc/user_compiler/controller0.rb')
141
+
142
+ #The file with content should be longer when compiled into the flat application_user.js
143
+ len_with_content = compile_with_file "./spec/etc/user_compiler/controller0.rb"
144
+ len_no_content = compile_with_file
145
+
146
+ expect(len_no_content).to be < len_with_content
41
147
  end
42
148
 
43
- #it "Can be executed via bundle exec" do flok_new do
44
- #flok "build"
45
- #end
46
- #end
47
-
48
- ##When this sets FLOK_CONFIG, the defines is added to the project config.yml
49
- ##to show spec_helper_defines_spec_test. This text should show up in the final
50
- ##source code
51
- #it "Does set the FLOK_CONFIG to the correct file based on PLATFORM" do
52
- #flok_new do
53
- ##Set spec_test in project configuration
54
- #config_yml = YAML.load_file("./config/platforms/#{ENV['PLATFORM']}/config.yml")
55
- #config_yml["DEBUG"]["defines"] = ["spec_test"]
56
- #File.write("./config/platforms/#{ENV['PLATFORM']}/config.yml", config_yml.to_yaml)
57
-
58
- ##Now commit a build
59
- #flok "build"
60
-
61
- ##Now read the application_user file, it should contain the string located in `./app/kern/spec_helper.js`
62
- ##that will only show if the correct defines is set
63
- #application_user = File.read("./products/#{ENV['PLATFORM']}/application_user.js")
64
- #expect(application_user).to include("spec_helper_defines_spec_test")
65
- #end
66
- #end
67
-
68
- #it "Can create a new project with correct directories" do
69
- #flok_new do
70
- ##Should include all entities in the project template with the exception
71
- ##of erb extenseded entities (which will still be included, but they each
72
- ##will not have the erb ending
73
- #template_nodes = nil
74
- #Dir.chdir File.join(File.dirname(__FILE__), "../../lib/flok/project_template") do
75
- #template_nodes = Dir["**/*"].map{|e| e.gsub(/\.erb$/i, "")}
76
- #end
77
- #new_proj_nodes = Dir["**/*"]
78
- #expect(new_proj_nodes.sort).to eq(template_nodes.sort)
79
-
80
- #expect(files).to include("Gemfile")
81
- #end
82
- #end
83
-
84
- #it "Can build a project with every type of platform" do
85
- #platform = ENV['PLATFORM']
86
- #flok_new do
87
- ##Build a new project
88
- #flok "build"
89
-
90
- ##Check it's products directory
91
- #expect(dirs).to include "products"
92
- #Dir.chdir "products" do
93
- ##Has a platform folder
94
- #expect(dirs).to include platform
95
- #Dir.chdir platform do
96
- ##Has an application_user.js file
97
- #expect(files).to include "application_user.js"
98
-
99
- ##The application_user.js contains both the glob/application.js and the glob/user_compiler.js
100
- #glob_application_js = File.read('glob/application.js')
101
- #glob_user_compiler_js = File.read('glob/user_compiler.js')
102
- #application_user_js = File.read('application_user.js')
103
- #expect(application_user_js).to include(glob_application_js)
104
- #expect(application_user_js).to include(glob_user_compiler_js)
105
-
106
- ##Contains the same files as the kernel in the drivers directory
107
- #expect(dirs).to include "drivers"
108
- #end
109
- #end
110
- #end
111
- #end
112
-
113
- #it "Can build a project with a controller file for each platform" do
114
- ##Compile and then return the length of the application_user.js file
115
- #def compile_with_file path=nil
116
- ##Custom controller to test source with
117
- #controller_src = File.read(path) if path
118
- #flok_new do
119
- #File.write "./app/controllers/controller0.rb", controller_src if path
120
-
121
- ##Build a new project
122
- #flok "build"
123
-
124
- ##Check it's products directory
125
- #Dir.chdir "products" do
126
- ##Has a platform folder
127
- #Dir.chdir @platform do
128
- #glob_application_js = File.read('glob/application.js')
129
- #glob_user_compiler_js = File.read('glob/user_compiler.js')
130
- #application_user_js = File.read('application_user.js')
131
-
132
- #return application_user_js.split("\n").count
133
- #end
134
- #end
135
- #end
136
- #end
137
-
138
- #platform = ENV['PLATFORM']
139
- #@platform = platform
140
- #controller_rb = File.read('./spec/etc/user_compiler/controller0.rb')
141
-
142
- ##The file with content should be longer when compiled into the flat application_user.js
143
- #len_with_content = compile_with_file "./spec/etc/user_compiler/controller0.rb"
144
- #len_no_content = compile_with_file
145
-
146
- #expect(len_no_content).to be < len_with_content
147
- #end
149
+ it "Can build a project with a file in ./app/controllers/**/.rb" do
150
+ #Compile and then return the length of the application_user.js file
151
+ def compile_with_file path=nil
152
+ #Custom controller to test source with
153
+ controller_src = File.read(path) if path
154
+ flok_new do
155
+ FileUtils.mkdir_p "./app/controllers/sub"
156
+ File.write "./app/controllers/sub/controller0.rb", controller_src if path
157
+
158
+ #Build a new project
159
+ flok "build"
160
+
161
+ #Check it's products directory
162
+ Dir.chdir "products" do
163
+ #Has a platform folder
164
+ Dir.chdir @platform do
165
+ glob_application_js = File.read('glob/application.js')
166
+ glob_user_compiler_js = File.read('glob/user_compiler.js')
167
+ application_user_js = File.read('application_user.js')
168
+
169
+ return application_user_js.split("\n").count
170
+ end
171
+ end
172
+ end
173
+ end
174
+
175
+ platform = ENV['PLATFORM']
176
+ @platform = platform
177
+ controller_rb = File.read('./spec/etc/user_compiler/controller0.rb')
178
+
179
+ #The file with content should be longer when compiled into the flat application_user.js
180
+ len_with_content = compile_with_file "./spec/etc/user_compiler/controller0.rb"
181
+ len_no_content = compile_with_file
182
+
183
+ expect(len_no_content).to be < len_with_content
184
+ end
148
185
 
149
186
  it "Can build a project with a javascript file for each platform" do
150
187
  #Compile and then return the length of the application_user.js file
@@ -178,213 +215,191 @@ RSpec.describe "CLI" do
178
215
  expect(len_no_content).to be < len_with_content
179
216
  end
180
217
 
181
- #it "Can build a project with an instantized service from the kernel ./app/kern/services folder" do
182
- ##Compiled to config/services.rb
183
- #def compile_with_file path=nil
184
- #config_src = File.read(path) if path
185
- #flok_new do
186
- #File.write "./config/services.rb", config_src if path
187
-
188
- ##Build a new project
189
- #flok "build"
190
-
191
- ##Check it's products directory
192
- #Dir.chdir "products" do
193
- ##Has a platform folder
194
- #Dir.chdir @platform do
195
- #application_user_js = File.read('application_user.js')
196
-
197
- #return application_user_js.split("\n").count
198
- #end
199
- #end
200
- #end
201
- #end
202
-
203
- #platform = ENV['PLATFORM']
204
- #@platform = platform
205
- #config_rb = File.read('./spec/etc/service_compiler/config0.rb')
206
-
207
- ##The file with content should be longer when compiled into the flat application_user.js
208
- #len_with_content = compile_with_file "./spec/etc/service_compiler/config0.rb"
209
- #len_no_content = compile_with_file
210
-
211
- #expect(len_no_content).to be < len_with_content
212
- #end
213
-
214
- #it "Can build a project with an instantized service from the user ./app/services folder" do
215
- ##Compiled to config/services.rb
216
- #def compile_with_file config_path=nil, src_path=nil
217
- #config_src = File.read(config_path) if config_path
218
- #src = File.read(src_path) if src_path
219
- #flok_new do
220
- #File.write "./config/services.rb", config_src if config_path
221
- #File.write "./app/services/service0.rb", src if src_path
222
-
223
- ##Build a new project
224
- #flok "build"
225
-
226
- ##Check it's products directory
227
- #Dir.chdir "products" do
228
- ##Has a platform folder
229
- #Dir.chdir @platform do
230
- #application_user_js = File.read('application_user.js')
231
-
232
- #return application_user_js.split("\n").count
233
- #end
234
- #end
235
- #end
236
- #end
237
-
238
- #platform = ENV['PLATFORM']
239
- #@platform = platform
240
- #config_rb = File.read('./spec/etc/service_compiler/config1.rb')
241
- #service_rb = File.read('./spec/etc/service_compiler/service0.rb')
242
-
243
- ##The file with content should be longer when compiled into the flat application_user.js
244
- #len_with_content = compile_with_file "./spec/etc/service_compiler/config1.rb", "./spec/etc/service_compiler/service0.rb"
245
- #len_no_content = compile_with_file
246
-
247
- #expect(len_no_content).to be < len_with_content
248
- #end
249
-
250
- #it "Can build a project with an instantized service from the user ./app/services folder and this has a function of the service" do
251
- ##Compiled to config/services.rb
252
- #def compile_with_file config_path=nil, src_path=nil
253
- #config_src = File.read(config_path) if config_path
254
- #src = File.read(src_path) if src_path
255
- #flok_new do
256
- #File.write "./config/services.rb", config_src if config_path
257
- #File.write "./app/services/service0.rb", src if src_path
258
-
259
- ##Build a new project
260
- #flok "build"
261
-
262
- ##Check it's products directory
263
- #Dir.chdir "products" do
264
- ##Has a platform folder
265
- #Dir.chdir @platform do
266
- #application_user_js = File.read('application_user.js')
267
-
268
- #return application_user_js
269
- #end
270
- #end
271
- #end
272
- #end
273
-
274
- #platform = ENV['PLATFORM']
275
- #@platform = platform
276
- #config_rb = File.read('./spec/etc/service_compiler/config1.rb')
277
- #service_rb = File.read('./spec/etc/service_compiler/service0.rb')
278
-
279
- ##The file with content should be longer when compiled into the flat application_user.js
280
- #res = compile_with_file "./spec/etc/service_compiler/config1.rb", "./spec/etc/service_compiler/service0.rb"
281
- #expect(res).to include("function blah_on_wakeup()")
282
- #end
283
-
284
- #include SpecHelpers
285
- #it "server does build project when first run" do
286
- #platform = ENV['PLATFORM']
287
- #flok_new do
288
- ##Now execute the command with a set of arguments
289
- #sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
290
- ##The server should always trigger a build on it's first run
291
- #expect(dirs).to include "products"
292
- #Dir.chdir "products" do
293
- ##Has a platform folder
294
- #expect(dirs).to include platform
295
- #Dir.chdir platform do
296
- ##Has an application_user.js file
297
- #expect(files).to include "application_user.js"
298
-
299
- ##The application_user.js contains both the glob/application.js and the glob/user_compiler.js
300
- #glob_application_js = File.read('glob/application.js')
301
- #glob_user_compiler_js = File.read('glob/user_compiler.js')
302
- #application_user_js = File.read('application_user.js')
303
- #expect(application_user_js).to include(glob_application_js)
304
- #expect(application_user_js).to include(glob_user_compiler_js)
305
-
306
- ##Contains the same files as the kernel in the drivers directory
307
- #expect(dirs).to include "drivers"
308
- #end
309
- #end
310
- #end
311
- #end
312
- #end
313
-
314
- #it "server does rebuild project when a file is added" do
315
- #platform = ENV['PLATFORM']
316
- #flok_new do
317
- ##Now execute the command with a set of arguments
318
- #sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
319
- ##Get the original build
320
- #application_user_js = File.read("products/#{platform}/application_user.js")
321
-
322
- ##Now add a file
323
- #File.write "./app/controllers/test2.rb", %{
324
- #controller "my_controller" do
325
- #action "my_action" do
326
- #on_entry %{
327
- #}
328
- #end
329
- #end
330
- #}
331
-
332
- ##Wait for a rebuild
333
- #expect(out).to readline_and_equal_x_within_y_seconds("BUILD RAN", 5.seconds)
334
-
335
- ##Get updated version
336
- #application_user_js2 = File.read("products/#{platform}/application_user.js")
337
-
338
- ##Make sure the compiled file is different and it's somewhat valid (length > 30)
339
- #expect(application_user_js2).not_to eq(application_user_js)
340
- #expect(application_user_js2.length).to be > 30 #Magic 30 to avoid any problems
341
- #end
342
- #end
343
- #end
344
-
345
- #it "server does host products on localhost:9992" do
346
- #platform = ENV['PLATFORM']
347
- #flok_new do
348
- ##Now execute the command with a set of arguments
349
- #sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
350
- #real_application_user_js = File.read("products/#{platform}/application_user.js")
351
-
352
- ##Grab the application_user.js file
353
- #res = wget "http://localhost:9992/application_user.js"
354
- #expect(res).not_to eq(nil)
355
- #expect(res.length).not_to eq(0)
356
- #expect(res).to eq(real_application_user_js)
357
- #end
358
- #end
359
- #end
360
-
361
- #it "server does host products on localhost:9992 and changes the products when the files change" do
362
- #platform = ENV['PLATFORM']
363
- #flok_new do
364
- ##Now execute the command with a set of arguments
365
- #sh2("bundle exec flok server", /BUILD RAN/) do |inp, out|
366
- ##Get the original
367
- #application_user_js = wget "http://localhost:9992/application_user.js"
368
-
369
- ##Now add a file
370
- #File.write "./app/controllers/test2.rb", %{
371
- #controller "my_controller" do
372
- #action "my_action" do
373
- #on_entry %{
374
- #}
375
- #end
376
- #end
377
- #}
378
- ##Wait for a rebuild
379
- #expect(out).to readline_and_equal_x_within_y_seconds("BUILD RAN", 5.seconds)
380
-
381
- ##Grab new version
382
- #application_user_js2 = wget "http://localhost:9992/application_user.js"
383
-
384
- ##Make sure the compiled file is different and it's longer
385
- #expect(application_user_js2.length).to be > application_user_js.length
386
- #expect(application_user_js2.length).to be > 30 #Make sure it's at least something
387
- #end
388
- #end
389
- #end
218
+ it "Can build a project with an instantized service from the kernel ./app/kern/services folder" do
219
+ #Compiled to config/services.rb
220
+ def compile_with_file path=nil
221
+ config_src = File.read(path) if path
222
+ flok_new do
223
+ File.write "./config/services.rb", config_src if path
224
+
225
+ #Build a new project
226
+ flok "build"
227
+
228
+ #Check it's products directory
229
+ Dir.chdir "products" do
230
+ #Has a platform folder
231
+ Dir.chdir @platform do
232
+ application_user_js = File.read('application_user.js')
233
+
234
+ return application_user_js.split("\n").count
235
+ end
236
+ end
237
+ end
238
+ end
239
+
240
+ platform = ENV['PLATFORM']
241
+ @platform = platform
242
+ config_rb = File.read('./spec/etc/service_compiler/config0.rb')
243
+
244
+ #The file with content should be longer when compiled into the flat application_user.js
245
+ len_with_content = compile_with_file "./spec/etc/service_compiler/config0.rb"
246
+ len_no_content = compile_with_file
247
+
248
+ expect(len_no_content).to be < len_with_content
249
+ end
250
+
251
+ it "Can build a project with an instantized service from the user ./app/services folder" do
252
+ #Compiled to config/services.rb
253
+ def compile_with_file config_path=nil, src_path=nil
254
+ config_src = File.read(config_path) if config_path
255
+ src = File.read(src_path) if src_path
256
+ flok_new do
257
+ File.write "./config/services.rb", config_src if config_path
258
+ File.write "./app/services/service0.rb", src if src_path
259
+
260
+ #Build a new project
261
+ flok "build"
262
+
263
+ #Check it's products directory
264
+ Dir.chdir "products" do
265
+ #Has a platform folder
266
+ Dir.chdir @platform do
267
+ application_user_js = File.read('application_user.js')
268
+
269
+ return application_user_js.split("\n").count
270
+ end
271
+ end
272
+ end
273
+ end
274
+
275
+ platform = ENV['PLATFORM']
276
+ @platform = platform
277
+ config_rb = File.read('./spec/etc/service_compiler/config1.rb')
278
+ service_rb = File.read('./spec/etc/service_compiler/service0.rb')
279
+
280
+ #The file with content should be longer when compiled into the flat application_user.js
281
+ len_with_content = compile_with_file "./spec/etc/service_compiler/config1.rb", "./spec/etc/service_compiler/service0.rb"
282
+ len_no_content = compile_with_file
283
+
284
+ expect(len_no_content).to be < len_with_content
285
+ end
286
+
287
+ it "Can build a project with an instantized service from the user ./app/services folder and this has a function of the service" do
288
+ #Compiled to config/services.rb
289
+ def compile_with_file config_path=nil, src_path=nil
290
+ config_src = File.read(config_path) if config_path
291
+ src = File.read(src_path) if src_path
292
+ flok_new do
293
+ File.write "./config/services.rb", config_src if config_path
294
+ File.write "./app/services/service0.rb", src if src_path
295
+
296
+ #Build a new project
297
+ flok "build"
298
+
299
+ #Check it's products directory
300
+ Dir.chdir "products" do
301
+ #Has a platform folder
302
+ Dir.chdir @platform do
303
+ application_user_js = File.read('application_user.js')
304
+
305
+ return application_user_js
306
+ end
307
+ end
308
+ end
309
+ end
310
+
311
+ platform = ENV['PLATFORM']
312
+ @platform = platform
313
+ config_rb = File.read('./spec/etc/service_compiler/config1.rb')
314
+ service_rb = File.read('./spec/etc/service_compiler/service0.rb')
315
+
316
+ #The file with content should be longer when compiled into the flat application_user.js
317
+ res = compile_with_file "./spec/etc/service_compiler/config1.rb", "./spec/etc/service_compiler/service0.rb"
318
+ expect(res).to include("function blah_on_wakeup()")
319
+ end
320
+
321
+ include SpecHelpers #wget
322
+ it "server does host products on localhost:9992" do
323
+ platform = ENV['PLATFORM']
324
+
325
+ flok_new do
326
+ begin
327
+ rd, wr = IO.pipe
328
+ @pid = fork do
329
+ STDOUT.reopen(wr)
330
+ STDERR.reopen(wr)
331
+ exec("#{$flok_bin_path} server")
332
+ end
333
+
334
+ #Wait for server started
335
+ $stderr.puts "Waiting for server to start..."
336
+ $stderr.puts "="*100
337
+ loop do
338
+ res = rd.readline
339
+ $stderr.puts "[flok server]: #{res}"
340
+ break if res =~ /.*SERVER STARTED.*/
341
+ end
342
+ $stderr.puts "="*100
343
+
344
+ #Grab the application_user.js file
345
+ res = wget "http://localhost:9992/application_user.js"
346
+ expect(res).not_to eq(nil)
347
+ expect(res.length).not_to eq(0)
348
+ ensure
349
+ Process.kill :INT, @pid
350
+ end
351
+ end
352
+ end
353
+
354
+ it "server does host products on localhost:9992 and changes the products when the files change" do
355
+ platform = ENV['PLATFORM']
356
+
357
+ flok_new do
358
+ #Now execute the command with a set of arguments
359
+
360
+ begin
361
+ rd, wr = IO.pipe
362
+ @pid = fork do
363
+ STDOUT.reopen(wr)
364
+ STDERR.reopen(wr)
365
+ exec("#{$flok_bin_path} server")
366
+ end
367
+
368
+ #Wait for server started
369
+ $stderr.puts "Waiting for server to start..."
370
+ $stderr.puts "="*100
371
+ loop do
372
+ res = rd.readline
373
+ $stderr.puts "[flok server]: #{res}"
374
+ break if res =~ /.*SERVER STARTED.*/
375
+ end
376
+ $stderr.puts "="*100
377
+
378
+ #Grab the application_user.js file before making a change
379
+ res0 = wget "http://localhost:9992/application_user.js"
380
+
381
+ #Now add a file
382
+ File.write "./app/controllers/test2.rb", %{
383
+ controller "my_controller" do
384
+ action "my_action" do
385
+ on_entry %{
386
+ }
387
+ end
388
+ end
389
+ }
390
+
391
+ #Grab the application_user.js after adding a change
392
+ res1 = wget "http://localhost:9992/application_user.js"
393
+
394
+ #They shouldn't be nil or 0 length
395
+ expect(res0).not_to eq(nil); expect(res1).not_to eq(nil)
396
+ expect(res0.length).not_to eq(0); expect(res1.length).not_to eq(0)
397
+
398
+ #And they shouldn't be the same
399
+ expect(res0.length).to be < res1.length
400
+ ensure
401
+ Process.kill :INT, @pid
402
+ end
403
+ end
404
+ end
390
405
  end