-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathchapter-08.srt
434 lines (339 loc) · 8.46 KB
/
chapter-08.srt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
1
00:00:00,000 --> 00:00:04,000
Chapter 08.
Making Target dependencies build.
2
00:00:04,651 --> 00:00:11,005
JC: So in order for that to work, we just need to....
3
00:00:12,400 --> 00:00:17,588
The second target has been
given its dependencies as input,
4
00:00:17,862 --> 00:00:21,977
So we should just be able
to tell them to build themselves.
5
00:00:22,331 --> 00:00:28,388
So if we go back into our target class then build.
6
00:00:28,834 --> 00:00:32,960
And we've got this dependencies
thing that we've not stored.
7
00:00:33,188 --> 00:00:39,977
[Silence]
8
00:00:40,091 --> 00:00:45,211
So build could call update or...
9
00:00:45,862 --> 00:00:50,114
Not necessarily going to update them,
I'm going to make sure they're up to date.
10
00:00:52,411 --> 00:00:58,034
ensure_updated_dependencies
11
00:00:58,250 --> 00:01:04,297
And then let's extract that
into something called build_self.
12
00:01:04,765 --> 00:01:12,674
So build is now a sort of sequence of high level
things you need to do, and this is how to do each one.
13
00:01:12,857 --> 00:01:21,268
[Silence]
14
00:01:21,371 --> 00:01:26,457
We have def ensure_updated_dependencies.
15
00:01:26,450 --> 00:01:32,971
So we should be able to go in
and say dependencies.each &:build.
16
00:01:36,045 --> 00:01:38,971
And they will build themselves.
17
00:01:40,170 --> 00:01:45,371
These things here, which are
primary resources we already created,
18
00:01:45,380 --> 00:01:49,554
they don't have any build
instructions and should work OK.
19
00:01:49,660 --> 00:01:53,017
This is why I made it so it was
OK to have no instructions,
20
00:01:53,040 --> 00:01:56,000
because you need to be able to
model things that already exist.
21
00:01:56,270 --> 00:02:01,291
This should go off and tell file a and b
to build themselves, which will do nothing.
22
00:02:01,302 --> 00:02:04,514
And then this will tell the first
target and file c to build themselves.
23
00:02:04,537 --> 00:02:10,330
The first target will run this command here and
once those are done, run this command here.
24
00:02:10,380 --> 00:02:13,657
And everything should be OK.
25
00:02:13,650 --> 00:02:15,565
TS: Does it work?
26
00:02:15,600 --> 00:02:20,354
JC: It works. Hurrah!
TS: Amazing!
27
00:02:20,370 --> 00:02:25,794
JC: Right, so we've got an integration test
and all that we've changed to do that
28
00:02:25,862 --> 00:02:29,714
is quite a lot of things. (Laughter)
29
00:02:29,737 --> 00:02:38,068
I don't know if all these unit tests should
be on the build method, or on build_self.
30
00:02:42,034 --> 00:02:44,480
I don't want to specify the
implementation of target
31
00:02:44,514 --> 00:02:48,148
but I want to specify it's
relationship with other things.
32
00:02:51,051 --> 00:02:56,354
The important thing is when you build one target, it
will tell those dependencies to build themselves.
33
00:02:56,377 --> 00:03:01,645
That's the minimum abstract
thing that needs to be checked.
34
00:03:01,640 --> 00:03:05,908
I don't want to tell it how its
private method should be organized.
35
00:03:07,930 --> 00:03:14,011
It's more about, what's its interaction with other
stuff and that is that it calls build on them.
36
00:03:14,788 --> 00:03:22,530
In terms of unit tests...
fakemake target_spec... so build.
37
00:03:22,571 --> 00:03:24,990
This is all about running instructions and stuff.
38
00:03:25,017 --> 00:03:29,280
But before we get to running
instructions we have dependencies.
39
00:03:31,291 --> 00:03:33,920
I'm not sure if it makes sense to write
a test for when there are no dependencies.
40
00:03:33,920 --> 00:03:36,708
These tests are already implicitly
for when there are no dependencies.
41
00:03:36,731 --> 00:03:43,880
And if there are none there's no other target for
you to say that it should or should not call build on.
42
00:03:44,114 --> 00:03:47,954
So let's make a test for when there are dependencies.
43
00:03:48,102 --> 00:03:58,571
[Silence]
44
00:03:58,680 --> 00:04:04,891
We can have several of them and in
this case the order shouldn't be important.
45
00:04:04,982 --> 00:04:10,982
Or rather you should construct your
dependency tree so the order doesn't matter.
46
00:04:10,980 --> 00:04:21,245
If c depends on a and b, but b has to happen
after a then you should just say b depends on a.
47
00:04:21,240 --> 00:04:25,405
That will ensure that that happens first.
48
00:04:26,880 --> 00:04:34,640
So... The first dependency is a double.
49
00:04:35,960 --> 00:04:40,388
And the second dependency is also a double.
50
00:04:44,971 --> 00:04:50,491
This does let us check that if the first dependency
fails then we don't call the second dependency.
51
00:04:50,490 --> 00:04:56,331
That isn't really a requirement, it's
accidental because the order doesn't matter.
52
00:04:56,620 --> 00:05:06,388
So we should say it should tell all
its dependencies to build themselves.
53
00:05:08,354 --> 00:05:18,971
So we expect first_dep to receive build once.
54
00:05:19,382 --> 00:05:24,125
And likewise for the second_dep.
55
00:05:24,720 --> 00:05:26,571
And, what's our target here?
56
00:05:26,594 --> 00:05:38,262
Our target is FakeMake::Target.new
with a pathname (that won't matter yet).
57
00:05:38,880 --> 00:05:45,360
And the dependencies, second dep and no
instructions because we're not testing that here.
58
00:05:50,650 --> 00:05:56,388
That looks OK, so when we call target build it
should tell each of the targets to build themselves.
59
00:05:57,028 --> 00:05:59,348
Oops, I've lost my other shell.
60
00:06:02,091 --> 00:06:05,428
Path again...
61
00:06:05,730 --> 00:06:13,040
[Silence]
62
00:06:13,211 --> 00:06:16,251
OK that looks good.
63
00:06:16,788 --> 00:06:22,605
This is a good place to commit. It's a new
feature: we have dependency management.
64
00:06:24,360 --> 00:06:27,371
Let's have a look at what we've changed.
65
00:06:27,980 --> 00:06:36,468
We've added dependencies to target class and made
it so that the target will build its dependencies.
66
00:06:36,480 --> 00:06:40,411
If you have a tree of targets
they will recursively build themselves.
67
00:06:40,525 --> 00:06:44,365
And we've added tests for those things.
68
00:06:44,660 --> 00:06:48,262
[Silence]
69
00:06:48,388 --> 00:06:50,420
OK.
70
00:06:56,130 --> 00:06:58,171
TS: I was surprised to see when you ran that unit test,
71
00:06:58,170 --> 00:07:01,805
it looks like there was some
output on stdout during the test,
72
00:07:01,805 --> 00:07:05,610
which wasn't what I expected to see.
73
00:07:05,988 --> 00:07:11,851
JC: You're right we're printing the commands.
74
00:07:11,954 --> 00:07:17,650
We'll still have an issue with system, because
system inherits stdout from the ruby process.
75
00:07:18,050 --> 00:07:23,840
Cat happens to not emit any output; well it does,
but we're piping it into a file, so it's fine.
76
00:07:23,874 --> 00:07:26,457
But we are still echoing stuff.
77
00:07:26,530 --> 00:07:28,388
TS: But this wasn't happening before right?
78
00:07:28,434 --> 00:07:31,737
When you ran the unit test before
it was just a line of green dots.
79
00:07:31,760 --> 00:07:34,400
JC: Yes.
80
00:07:34,750 --> 00:07:38,525
I've let these targets in the
integration tests use stdout.
81
00:07:38,560 --> 00:07:41,451
and I can maybe stop them from doing that.
82
00:07:41,560 --> 00:07:47,131
It's a bit frustrating in that I could have
used puts and set $stdout to StringIO,
83
00:07:47,131 --> 00:07:49,900
but then the tests wouldn't emit any output.
84
00:07:49,908 --> 00:07:53,245
It's one of those isolation things.
85
00:07:53,337 --> 00:07:57,725
I want this thing that prints
stuff to print to a black hole.
86
00:07:57,720 --> 00:08:02,034
But I want the tests that are running the
process to still be able to talk to stdout.
87
00:08:03,965 --> 00:08:13,462
We can get around that by passing
in an output like we did before.
88
00:08:18,330 --> 00:08:22,674
We'll call it stdout here to make
it a bit more clear what its role is.
89
00:08:24,868 --> 00:08:30,400
And then that can take it as an argument.
Although not all of them will need it.
90
00:08:30,400 --> 00:08:34,640
Only the ones that run code need it.
91
00:08:34,822 --> 00:08:41,680
[Silence]
92
00:08:41,954 --> 00:08:46,651
I'm not having a very good typing day today. [Laughter]
93
00:08:48,285 --> 00:08:52,251
Private method puts called for; that's interesting.
94
00:08:52,525 --> 00:08:57,714
Oh! I've called it output sorry, I forgot what
I called it. It's called stdout in this test.
95
00:09:01,314 --> 00:09:03,931
OK that's better, outputs gone away.
TS: Great.