<commit_before>
(import (chibi) (chibi ast) (chibi match)
        (chibi process) (chibi filesystem) (chibi test))

(define generated-shared-objects '())

(define (trash-shared-object! file)
  (set! generated-shared-objects (cons file generated-shared-objects)))

(define (cleanup-shared-objects!)
  (for-each (lambda (file) (protect (exn (else #f)) (delete-file file)))
            generated-shared-objects))

(test-begin "ffi")

(define-syntax test-ffi
  (syntax-rules ()
    ((test-ffi name-expr decls tests ...)
     (let* ((name name-expr)
            (stub-file (string-append "tests/ffi/" name ".stub"))
            (c-file (string-append "tests/ffi/" name ".c"))
            (lib-file
             (string-append "tests/ffi/" name *shared-object-extension*)))
       (call-with-output-file stub-file
         (lambda (out) (write 'decls out) (newline out)))
       (let ((res (system
                   "./chibi-scheme" "tools/chibi-ffi" "-c"
                   "-f" (string-append
                         "-O0 -L. -Iinclude"
                         (cond-expand
                          (boehm-gc
                           " -DSEXP_USE_BOEHM=1 -I/opt/local/include")
                          (else
                           "")))
                   stub-file)))
         (cond
          ((zero? (cadr res))
           (let ((orig-failures (test-failure-count)))
             (load lib-file)
             tests ...
             ;; on any failure leave the stub and c file for reference
             (cond
              ((= orig-failures (test-failure-count))
               (delete-file stub-file)
               (delete-file c-file)))
             (delete-file lib-file)
             (trash-shared-object! lib-file)))<commit_msg>tests/ffi: Complete removal of delete-file on .dll<commit_after>
(import (chibi) (chibi ast) (chibi match)
        (chibi process) (chibi filesystem) (chibi test))

(define generated-shared-objects '())

(define (trash-shared-object! file)
  (set! generated-shared-objects (cons file generated-shared-objects)))

(define (cleanup-shared-objects!)
  (for-each (lambda (file) (protect (exn (else #f)) (delete-file file)))
            generated-shared-objects))

(test-begin "ffi")

(define-syntax test-ffi
  (syntax-rules ()
    ((test-ffi name-expr decls tests ...)
     (let* ((name name-expr)
            (stub-file (string-append "tests/ffi/" name ".stub"))
            (c-file (string-append "tests/ffi/" name ".c"))
            (lib-file
             (string-append "tests/ffi/" name *shared-object-extension*)))
       (call-with-output-file stub-file
         (lambda (out) (write 'decls out) (newline out)))
       (let ((res (system
                   "./chibi-scheme" "tools/chibi-ffi" "-c"
                   "-f" (string-append
                         "-O0 -L. -Iinclude"
                         (cond-expand
                          (boehm-gc
                           " -DSEXP_USE_BOEHM=1 -I/opt/local/include")
                          (else
                           "")))
                   stub-file)))
         (cond
          ((zero? (cadr res))
           (let ((orig-failures (test-failure-count)))
             (load lib-file)
             tests ...
             ;; on any failure leave the stub and c file for reference
             (cond
              ((= orig-failures (test-failure-count))
               (delete-file stub-file)
               (delete-file c-file)))
             (trash-shared-object! lib-file)))
{'fraction_non_alphanumeric': 0.1461736887360275, 'fraction_numerical': 0.0011464603038119805, 'mean_word_length': 1.553035844915874, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4518707', 'n_tokens_mistral': 1063, 'n_tokens_neox': 1025, 'n_words': 243}