Repository navigation
Expand file tree
/
Copy pathRakefile
More file actions
72 lines (59 loc) · 1.81 KB
/
Copy pathRakefile
File metadata and controls
72 lines (59 loc) · 1.81 KB
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
require "rbconfig"
EXERCISES = {
1 => "loading",
2 => "distance",
3 => "filtering",
4 => "chunking",
5 => "hybrid"
}.freeze
# Runs the tests without letting a red result look like a broken setup.
#
# Rake's built-in TestTask aborts the whole run with "rake aborted!" on any
# failure. For four of the five exercises here, failing IS the starting
# state — so that banner would tell people their environment is broken at the
# exact moment it's working correctly.
def run_tests(pattern)
files = FileList[pattern].to_a.sort
abort "No test files matched #{pattern}" if files.empty?
passed = system(RbConfig.ruby, "-Ilib", "-Itest", "-e", "ARGV.each { |f| load f }", *files)
unless passed
puts
puts "Not green yet — which is the normal state until you've filled in the TODOs."
puts "Read the hint under each failure, edit the file it names, and run again."
end
passed
end
task default: :test
desc "Run every exercise's tests"
task :test do
run_tests("test/*_test.rb")
end
namespace :ex do
EXERCISES.each do |number, slug|
desc "Run exercise #{number} (#{slug})"
task number.to_s do
run_tests("test/0#{number}_#{slug}_test.rb")
end
end
end
desc "Run the tests against solutions/ instead of exercises/"
task :solutions do
ENV["SOLUTIONS"] = "1"
run_tests("test/*_test.rb")
end
desc "Show the problem this workshop exists to solve (start here)"
task :warmup do
system(RbConfig.ruby, "-Ilib", "bin/warmup") || abort("warmup failed")
end
desc "Delete every collection so the next run rebuilds from scratch"
task :reset do
$LOAD_PATH.unshift("lib")
require "workshop"
Workshop.setup!
names = Workshop::Store.collection_names
names.each do |name|
Chroma::Resources::Collection.delete(name)
puts "deleted #{name}"
end
puts "nothing to delete" if names.empty?
end