1414 abort ( "Unknown benchmark '#{ BENCHMARK } '" )
1515end
1616
17- PROGRAM = File . expand_path ( " programs/ #{ BENCHMARK } .rb", __dir__ )
17+ PROGRAM = File . join ( 'test' , 'benchmarks' , ' programs' , " #{ BENCHMARK } .rb")
1818FIXTURE = File . expand_path ( "fixtures/#{ BENCHMARK } _trace.json" , __dir__ )
1919TMP_DIR = File . expand_path ( 'tmp' , __dir__ )
20- OUTPUT = File . join ( TMP_DIR , " #{ BENCHMARK } _trace.json" )
20+ OUTPUT_DIR = File . join ( TMP_DIR , BENCHMARK )
2121EXPECTED_HASH = HASHES [ BENCHMARK ]
2222
2323FileUtils . mkdir_p ( TMP_DIR )
24+ FileUtils . mkdir_p ( OUTPUT_DIR )
2425
2526unless File . exist? ( FIXTURE ) && Digest ::SHA256 . file ( FIXTURE ) . hexdigest == EXPECTED_HASH
2627 warn "Reference trace missing or corrupt. Attempting to fetch via git lfs..."
3132raise 'reference trace hash mismatch' unless Digest ::SHA256 . file ( FIXTURE ) . hexdigest == EXPECTED_HASH
3233
3334elapsed = Benchmark . realtime do
34- env = { 'CODETRACER_DB_TRACE_PATH' => OUTPUT }
35- system ( env , 'ruby' , File . expand_path ( '../../src/trace.rb' , __dir__ ) , PROGRAM )
35+ system ( 'ruby' , File . expand_path ( '../../src/trace.rb' , __dir__ ) , '--out-dir' , OUTPUT_DIR , PROGRAM )
3636 raise 'trace failed' unless $?. success?
3737end
3838puts "Benchmark runtime: #{ ( elapsed * 1000 ) . round } ms"
@@ -43,7 +43,8 @@ def files_identical?(a, b)
4343 File . binread ( a ) == File . binread ( b )
4444end
4545
46- if files_identical? ( FIXTURE , OUTPUT )
46+ OUTPUT_TRACE = File . join ( OUTPUT_DIR , 'trace.json' )
47+ if files_identical? ( FIXTURE , OUTPUT_TRACE )
4748 puts 'Trace matches reference.'
4849else
4950 warn 'Trace differs from reference!'
0 commit comments