11require 'erb'
2+ require 'yard/doctest/rake'
23
34task :default => :test
45
5- def what_day ( arg = nil )
6- if arg
7- arg
8- else
9- if day = ENV . fetch ( "DAY" , nil )
10- day
11- else
12- Time . now . day
13- end
14- end . to_s . rjust ( 2 , '0' )
6+ def what_day
7+ ENV
8+ . fetch ( "DAY" , Time . now . day )
9+ . to_i
10+ . to_s
11+ . rjust ( 2 , '0' )
1512end
1613
17- task :run , [ :day ] do |t , args |
18- day = what_day ( args [ :day ] )
14+ task :run do |t , args |
15+ day = what_day
1916 puts "OK. Let's run Day#{ day } !\n \n "
2017 require "./day#{ day } "
2118 Object . const_get ( "Day#{ day } " ) . go
2219end
2320
24- task :test , [ :day ] do |t , args |
25- day = what_day ( args [ :day ] )
21+ desc "Run the tests my way; set env var DAY to run a day other than today"
22+ task :test do |t , args |
23+ day = what_day
2624 puts "Wooo! Let's test Day#{ day } !\n \n "
2725
2826 File . open ( './doctest_helper.rb' , 'w' ) do |file |
@@ -35,7 +33,12 @@ task :test, [:day] do |t, args|
3533 TEST_HELPER
3634 end
3735
38- abort unless system ( "yard doctest -v ./day#{ day } .rb" )
36+ Rake ::Task [ "yard:doctest" ] . invoke
37+ end
38+
39+ YARD ::Doctest ::RakeTask . new do |task |
40+ task . doctest_opts = %w[ -v ] << ENV . fetch ( "TESTOPTS" , "" ) . split ( " " )
41+ task . pattern = "./day#{ what_day } .rb"
3942end
4043
4144task :new do
@@ -57,6 +60,6 @@ rule ( /^day\d\d$/ ) do |task|
5760 input_file = "../inputs/#{ task . name } -input.txt"
5861 system ( "pbpaste > #{ input_file } " )
5962 puts "📝 wrote the clipboard to #{ input_file } , hope it was right:"
60- system ( "cat #{ input_file } " )
63+ system ( "head -n 5 #{ input_file } " )
6164 end
6265end
0 commit comments