-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
koans.cr
99 lines (92 loc) · 1.93 KB
/
koans.cr
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
require "colorize"
TESTS = %w(
booleans
numbers
strings
symbols
nil
regular_expressions
enums
arrays
deque
tuples
named_tuples
sets
hashes
ranges
loops
blocks
functions
splat
structs
classes
chaining_methods
iterators
enumerable
generics
exceptions
require_path
magic_constants
concurrency
macros
macro_hooks
annotations
type_reflection
c_interop
low_level_primitives
bitarray
bigint
bigdecimal
bigrational
static_array
complex_numbers
random
levenshtein
semantic_version
env
dir
path
file
io_memory
html
json_plain
json_custom
csv
xml
yaml
http_server
ecr
)
CACHE_DIR = ".cache"
Dir.mkdir_p(CACHE_DIR)
PASSED_FILE = File.join(CACHE_DIR, "passed")
passed = {} of String => Int64
if File.exists?(PASSED_FILE)
File.each_line(PASSED_FILE) do |line|
test_case, timestamp = line.split
passed[test_case] = timestamp.to_i64
end
else
File.touch(PASSED_FILE)
end
percent = (100*passed.size/TESTS.size).round.to_i
puts "You are at #{percent}% of your journey".colorize(:yellow)
TESTS.each_with_index(1) do |test_case, test_number|
if timestamp = passed[test_case]?
mtime = File.info("spec/#{test_case}_spec.cr").modification_time.to_unix
next if timestamp > mtime
end
puts "Level #{test_number}: testing your strength on #{test_case} ..."
spec_process = Process.run("crystal spec spec/#{test_case}_spec.cr --fail-fast", shell: true, error: STDERR, output: STDOUT)
if spec_process.success?
File.open(PASSED_FILE, "a") do |file|
file.puts "#{test_case} #{Time.local.to_unix}"
end
else
test_case_bold = test_case.colorize(:green).mode(:bold)
print "--- \u{1F9D9} The Master says: ---\n".colorize(:light_yellow)
print "\"Something is wrong. Please meditate on ".colorize(:green)
print test_case_bold, " topic\nand try to follow the path to Enlightenment \u{1F9D8}\"\n".colorize(:green)
exit 1
end
end