repla 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/repla/logger/test/run_tests.sh +1 -1
- data/lib/repla/logger/test/tc_logger.rb +84 -28
- data/lib/repla/logger.rb +12 -5
- data/lib/repla/test/bundles/Cat.replabundle/Contents/Resources/cat.sh +2 -2
- data/lib/repla/test/bundles/FileExtension.replabundle/Contents/Resources/cat.sh +2 -2
- data/lib/repla/test/bundles/PromptInterrupt.replabundle/Contents/Resources/cat.sh +2 -2
- data/lib/repla/test/bundles/TestServer.replabundle/Contents/Resources/server.sh +1 -1
- data/lib/repla/test.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71286d9be60c5f021154d6c3f947a920507cb3e9
|
4
|
+
data.tar.gz: 15d263e2d2d59eb1dc61d1000c0ba639d948d850
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad06997ab931d826250fb37a7919a5b363321abb1eb6b701cb40f6f1b8fc82f6459bed747e76b64c4744e1795439a3b1bf887fffa1cf9d0f33dc9883c3c58493
|
7
|
+
data.tar.gz: fd5dd84d1481fb86843c0944909dae0e413c74291e647da9f057b6bff1b9a3debd9f97441bb4144ebaa8f9759ccac288d0bdd43f2f404af67542ec3a65bf6671
|
@@ -30,15 +30,18 @@ class TestUnintializedLogger < Minitest::Test
|
|
30
30
|
# Test Message
|
31
31
|
message = 'Testing log message'
|
32
32
|
@logger.info(message)
|
33
|
-
|
34
|
-
|
35
|
-
#
|
36
|
-
# `
|
37
|
-
# message and running the logger itself simultaneously. This is why the
|
38
|
-
# `LogHelper` is intialized after logging the message.
|
33
|
+
# Make sure the log messages appear before accessing the logger's `view_id`
|
34
|
+
# and `window_id` because those run the logger. This test should test
|
35
|
+
# logging a message and running the logger itself simultaneously. This is
|
36
|
+
# why the `LogHelper` is intialized after logging the message.
|
39
37
|
test_log_helper = Repla::Test::LogHelper.new(@logger.window_id,
|
40
38
|
@logger.view_id)
|
41
|
-
test_message =
|
39
|
+
test_message = nil
|
40
|
+
Repla::Test.block_until do
|
41
|
+
test_message = test_log_helper.last_log_message
|
42
|
+
test_message == message
|
43
|
+
end
|
44
|
+
|
42
45
|
assert_equal(message, test_message, 'The messages should match')
|
43
46
|
test_class = test_log_helper.last_log_class
|
44
47
|
assert_equal('message', test_class, 'The classes should match')
|
@@ -65,8 +68,11 @@ class TestLogger < Minitest::Test
|
|
65
68
|
# Test Error
|
66
69
|
message = 'Testing log error'
|
67
70
|
@logger.error(message)
|
68
|
-
|
69
|
-
|
71
|
+
test_message = nil
|
72
|
+
Repla::Test.block_until do
|
73
|
+
test_message = @test_log_helper.last_log_message
|
74
|
+
message == test_message
|
75
|
+
end
|
70
76
|
assert_equal(message, test_message)
|
71
77
|
test_class = @test_log_helper.last_log_class
|
72
78
|
assert_equal('error', test_class)
|
@@ -77,8 +83,11 @@ class TestLogger < Minitest::Test
|
|
77
83
|
# Test Message
|
78
84
|
message = 'Testing log message'
|
79
85
|
@logger.info(message)
|
80
|
-
|
81
|
-
|
86
|
+
test_message = nil
|
87
|
+
Repla::Test.block_until do
|
88
|
+
test_message = @test_log_helper.last_log_message
|
89
|
+
message == test_message
|
90
|
+
end
|
82
91
|
assert_equal(message, test_message)
|
83
92
|
test_class = @test_log_helper.last_log_class
|
84
93
|
assert_equal('message', test_class)
|
@@ -90,8 +99,11 @@ class TestLogger < Minitest::Test
|
|
90
99
|
# Note the trailing whitespace is trimmed
|
91
100
|
message = Repla::Logger::ERROR_PREFIX.rstrip
|
92
101
|
@logger.info(message)
|
93
|
-
|
94
|
-
|
102
|
+
test_message = nil
|
103
|
+
Repla::Test.block_until do
|
104
|
+
test_message = @test_log_helper.last_log_message
|
105
|
+
message == test_message
|
106
|
+
end
|
95
107
|
assert_equal(message, test_message)
|
96
108
|
test_class = @test_log_helper.last_log_class
|
97
109
|
assert_equal('message', test_class)
|
@@ -103,8 +115,11 @@ class TestLogger < Minitest::Test
|
|
103
115
|
# Note the trailing whitespace is trimmed
|
104
116
|
message = Repla::Logger::MESSAGE_PREFIX.rstrip
|
105
117
|
@logger.info(message)
|
106
|
-
|
107
|
-
|
118
|
+
test_message = nil
|
119
|
+
Repla::Test.block_until do
|
120
|
+
test_message = @test_log_helper.last_log_message
|
121
|
+
message == test_message
|
122
|
+
end
|
108
123
|
assert_equal(message, test_message)
|
109
124
|
test_class = @test_log_helper.last_log_class
|
110
125
|
assert_equal('message', test_class)
|
@@ -112,16 +127,11 @@ class TestLogger < Minitest::Test
|
|
112
127
|
test_count += 1
|
113
128
|
assert_equal(test_count, result_count)
|
114
129
|
|
115
|
-
# Test
|
116
|
-
|
117
|
-
|
118
|
-
test_message = @test_log_helper.last_log_message
|
119
|
-
assert_equal(message, test_message)
|
120
|
-
test_class = @test_log_helper.last_log_class
|
121
|
-
assert_equal('message', test_class)
|
122
|
-
|
123
|
-
# Test Empty String
|
130
|
+
# Test empty string is ignored
|
131
|
+
# Test blank space is ignored
|
132
|
+
# Note this uses the same `message` from the last test
|
124
133
|
@logger.info('')
|
134
|
+
@logger.info(" \t")
|
125
135
|
sleep Repla::Test::TEST_PAUSE_TIME # Pause for output to be processed
|
126
136
|
test_message = @test_log_helper.last_log_message
|
127
137
|
assert_equal(message, test_message)
|
@@ -154,12 +164,16 @@ Line 1
|
|
154
164
|
Line 2
|
155
165
|
Line 3
|
156
166
|
'
|
167
|
+
lines = 3
|
157
168
|
@logger.info(message)
|
158
|
-
|
159
|
-
|
160
|
-
|
169
|
+
result_count = nil
|
170
|
+
Repla::Test.block_until do
|
171
|
+
result_count = @test_log_helper.number_of_log_messages
|
172
|
+
result_count == lines
|
173
|
+
end
|
174
|
+
assert_equal(result_count, lines)
|
161
175
|
|
162
|
-
(1..
|
176
|
+
(1..lines).each do |i|
|
163
177
|
result = @test_log_helper.log_message_at_index(i - 1)
|
164
178
|
test_result = "Line #{i}"
|
165
179
|
assert_equal(result,
|
@@ -168,3 +182,45 @@ Line 3
|
|
168
182
|
end
|
169
183
|
end
|
170
184
|
end
|
185
|
+
|
186
|
+
# Test logger threads
|
187
|
+
class TestLoggerThreads < Minitest::Test
|
188
|
+
def setup
|
189
|
+
@logger = Repla::Logger.new
|
190
|
+
@logger.show
|
191
|
+
end
|
192
|
+
|
193
|
+
def teardown
|
194
|
+
window = Repla::Window.new(@logger.window_id)
|
195
|
+
window.close
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_multiple_threads
|
199
|
+
error_text = 'Error line'
|
200
|
+
message_text = 'Info line'
|
201
|
+
message_called = false
|
202
|
+
message_thread = Thread.new do
|
203
|
+
@logger.info(message_text)
|
204
|
+
message_called = true
|
205
|
+
end
|
206
|
+
|
207
|
+
error_called = false
|
208
|
+
error_thread = Thread.new do
|
209
|
+
@logger.error(error_text)
|
210
|
+
error_called = true
|
211
|
+
end
|
212
|
+
|
213
|
+
message_thread.join
|
214
|
+
error_thread.join
|
215
|
+
|
216
|
+
assert(error_called)
|
217
|
+
assert(message_called)
|
218
|
+
@test_log_helper = Repla::Test::LogHelper.new(@logger.window_id,
|
219
|
+
@logger.view_id)
|
220
|
+
Repla::Test.block_until { @test_log_helper.number_of_log_messages >= 2 }
|
221
|
+
result = @test_log_helper.last_log_message
|
222
|
+
result_two = @test_log_helper.log_message_at_index(0)
|
223
|
+
assert(result == message_text || result_two == message_text)
|
224
|
+
assert(result == error_text || result_two == error_text)
|
225
|
+
end
|
226
|
+
end
|
data/lib/repla/logger.rb
CHANGED
@@ -7,6 +7,9 @@ module Repla
|
|
7
7
|
ERROR_PREFIX = 'ERROR '.freeze
|
8
8
|
LOG_PLUGIN_NAME = 'Log'.freeze
|
9
9
|
|
10
|
+
def initialize
|
11
|
+
@mutex = Mutex.new
|
12
|
+
end
|
10
13
|
# Toggle
|
11
14
|
|
12
15
|
SHOW_LOG_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, 'show_log.scpt')
|
@@ -48,12 +51,16 @@ module Repla
|
|
48
51
|
end
|
49
52
|
|
50
53
|
def view_id
|
51
|
-
|
52
|
-
|
54
|
+
view_id = nil
|
55
|
+
@mutex.synchronize do
|
56
|
+
@view_id ||= Repla.split_id_in_window(window_id, LOG_PLUGIN_NAME)
|
57
|
+
return @view_id unless @view_id.nil?
|
53
58
|
|
54
|
-
|
55
|
-
|
56
|
-
|
59
|
+
@view_id = Repla.split_id_in_window_last(window_id)
|
60
|
+
Repla.run_plugin_in_split(LOG_PLUGIN_NAME, window_id, @view_id)
|
61
|
+
view_id = @view_id
|
62
|
+
end
|
63
|
+
view_id
|
57
64
|
end
|
58
65
|
|
59
66
|
private
|
@@ -1,3 +1,3 @@
|
|
1
|
-
#!/bin/
|
1
|
+
#!/bin/bash
|
2
2
|
|
3
|
-
cat
|
3
|
+
cat
|
@@ -1,3 +1,3 @@
|
|
1
|
-
#!/bin/
|
1
|
+
#!/bin/bash
|
2
2
|
|
3
|
-
cat
|
3
|
+
cat
|
@@ -1,3 +1,3 @@
|
|
1
|
-
#!/bin/
|
1
|
+
#!/bin/bash
|
2
2
|
|
3
|
-
cat
|
3
|
+
cat
|
data/lib/repla/test.rb
CHANGED
@@ -3,6 +3,8 @@ module Repla
|
|
3
3
|
module Test
|
4
4
|
# General
|
5
5
|
TEST_PAUSE_TIME = 2.00
|
6
|
+
TEST_TIMEOUT_TIME = 4.00
|
7
|
+
POLLING_INTERVAL = 0.5
|
6
8
|
|
7
9
|
# Ruby
|
8
10
|
REPLA_FILE = File.join(File.dirname(__FILE__), '../repla')
|
@@ -22,6 +24,19 @@ module Repla
|
|
22
24
|
'http://127.0.0.1:5000/' + filename
|
23
25
|
end
|
24
26
|
|
27
|
+
def self.block_until_with_timeout(timeout)
|
28
|
+
cycles = [timeout / POLLING_INTERVAL, 1].max
|
29
|
+
count = 0
|
30
|
+
until yield || count >= cycles
|
31
|
+
sleep(POLLING_INTERVAL)
|
32
|
+
count += 1
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.block_until(&block)
|
37
|
+
block_until_with_timeout(TEST_TIMEOUT_TIME, &block)
|
38
|
+
end
|
39
|
+
|
25
40
|
# HTML
|
26
41
|
TEST_HTML_DIRECTORY = File.join(TEST_DIRECTORY, 'html')
|
27
42
|
INDEX_HTML_FILENAME = 'index.html'.freeze
|