<commit_before>#lang racket

(require "run.rkt" "../send-places.rkt")

;; Assuming that only the log format changed, update test files to the
;; new format.
;; Running this after changes to the behavior of the optimizer is a
;; BAD idea, since in the case of regressions, the new broken behavior
;; would become the expected behavior.
;; Use this script with caution.

(define (transform file dir)
  ;; generate the new log, that will become the expected log
  (define-values (new-tr-log new-output) (generate-log file dir))
  (define source-code
    (call-with-input-file* (build-path dir file)
      (lambda (in)
        (read-line in) ; drop the #;#;
        (read in) ; drop the old expected tr log
        (read in) ; drop the old expected output
        (port->string in))))
  (with-output-to-file (build-path dir file) #:exists 'truncate
    (lambda ()
      (displayln "#;#;")
      (displayln "#<<END")
      (for ((entry new-tr-log))
        (displayln entry))
      (displayln "END")
      (if (regexp-match "\n" new-output)
          (begin
            (displayln "#<<END")
            (displayln new-output)
            (display "END"))
          (begin
            (write new-output)))
          (display source-code))))

;; proc returns the list of tests to be run on each file
(define (transform-dirs dirs)<commit_msg>Replace calls to display with write-string.<commit_after>#lang racket

(require "run.rkt" "../send-places.rkt")

;; Assuming that only the log format changed, update test files to the
;; new format.
;; Running this after changes to the behavior of the optimizer is a
;; BAD idea, since in the case of regressions, the new broken behavior
;; would become the expected behavior.
;; Use this script with caution.

(define (transform file dir)
  (define (write-stringln s)
    (write-string s)
    (newline))
  ;; generate the new log, that will become the expected log
  (define-values (new-tr-log new-output) (generate-log file dir))
  (define source-code
    (call-with-input-file* (build-path dir file)
      (lambda (in)
        (read-line in) ; drop the #;#;
        (read in) ; drop the old expected tr log
        (read in) ; drop the old expected output
        (port->string in))))
  (with-output-to-file (build-path dir file) #:exists 'truncate
    (lambda ()
      (write-stringln "#;#;")
      (write-stringln "#<<END")
      (for ((entry new-tr-log))
        (write-stringln entry))
      (write-stringln "END")
      (if (regexp-match "\n" new-output)
          (begin
            (write-stringln "#<<END")
            (write-stringln new-output)
            (write-string "END"))
          (begin
            (write new-output)))
          (write-string source-code))))

;; proc returns the list of tests to be run on each file
(define (transform-dirs dirs)
{'fraction_non_alphanumeric': 0.12772029967891546, 'fraction_numerical': 0.0, 'mean_word_length': 2.61340206185567, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1223275', 'n_tokens_mistral': 841, 'n_tokens_neox': 827, 'n_words': 310}