Megatest

Check-in [ffa2b8e7af]
Login
Overview
Comment:updated ducttape-lib to fix incompatibilities with megatest
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | v1.63-xor-report
Files: files | file ages | folders
SHA1: ffa2b8e7afb0b1912353e3df9671df1c477d65d2
User & Date: bjbarcla on 2017-02-01 16:01:17
Other Links: branch diff | manifest | tags
Context
2017-02-01
16:03
updated ducttape-lib to fix incompatibilities with megatest check-in: f792807bb9 user: bjbarcla tags: v1.63-xor-report
16:01
updated ducttape-lib to fix incompatibilities with megatest check-in: ffa2b8e7af user: bjbarcla tags: v1.63-xor-report
13:49
enahnced -log so it will create leading directory if specified check-in: e984e41fb4 user: bjbarcla tags: v1.63-xor-report
Changes

Modified ducttape/ducttape-lib.scm from [07138d2aca] to [789effec13].

16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     iputs
     re-match?
                                        ;     launch-repl
     keyword-skim
     skim-cmdline-opts-noarg-by-regex
     skim-cmdline-opts-withargs-by-regex 
     concat-lists
     process-command-line
     ducttape-append-logfile
     ducttape-activate-logfile
     isys
     do-or-die
     counter-maker
     dir-is-writable?
     mktemp







|







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     iputs
     re-match?
                                        ;     launch-repl
     keyword-skim
     skim-cmdline-opts-noarg-by-regex
     skim-cmdline-opts-withargs-by-regex 
     concat-lists
     ducttape-process-command-line
     ducttape-append-logfile
     ducttape-activate-logfile
     isys
     do-or-die
     counter-maker
     dir-is-writable?
     mktemp
44
45
46
47
48
49
50
51



52
53
54
55
56
57
58
     wwdate->isodate
     current-wwdate
     current-isodate
     
     )

  (import scheme chicken extras ports data-structures )
  (use posix regex ansi-escape-sequences test srfi-1 irregex slice srfi-13 rfc3339 scsh-process directory-utils uuid-lib filepath srfi-19 ) ; linenoise



  (include "mimetypes.scm") ; provides ext->mimetype
  (include "workweekdate.scm")
  (define ducttape-lib-version 1.00)
  (define (toplevel-command sym proc) (lambda () #f))
;;;; utility procedures

  ;; begin credit: megatest's process.scm







|
>
>
>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
     wwdate->isodate
     current-wwdate
     current-isodate
     
     )

  (import scheme chicken extras ports data-structures )
  (use posix regex ansi-escape-sequences test srfi-1 irregex slice srfi-13 rfc3339)
  ;;scsh-process ;; dropping scsh-process, it was clobbering posix's process and process*
  (use directory-utils uuid-lib filepath srfi-19 ) ; linenoise
  
  (include "mimetypes.scm") ; provides ext->mimetype
  (include "workweekdate.scm")
  (define ducttape-lib-version 1.00)
  (define (toplevel-command sym proc) (lambda () #f))
;;;; utility procedures

  ;; begin credit: megatest's process.scm
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
  (define (do-or-die command   #!key nodie (foreach-stdout #f) (stdin-proc #f))
    (let-values (((exit-code stdout-str stderr-str) (isys command foreach-stdout-thunk: foreach-stdout stdin-proc: stdin-proc )))
      (if (equal? 0 exit-code)
          stdout-str
          (begin
            (ierr (conc "Command  > " command " "  "< failed with " exit-code " because: \n" stderr-str) )
            (if nodie #f (exit exit-code))))))




  ;; this is broken.  one day i will fix it and thus understand run/collecting... don't use isys-broken.
  (define (isys-broken  command-list)

    (let-values ( ( (rv outport errport) (run/collecting (1 2) ("ls" "-l")  ) ) ) 
      (print "rv is " rv)
      (print "op is " outport)
      (print "ep is " errport)
      (values rv (port->string outport) (port->string errport))))



  ;; runs-ok: evaluate expression while suppressing exceptions.
                                        ;    on caught exception, returns #f
                                        ;    otherwise, returns expression value
  (define (runs-ok thunk)
    (handle-exceptions exn #f (begin (thunk) #t)))







<
<
<
<
<
<
<
<
<
<
<
<
<







183
184
185
186
187
188
189













190
191
192
193
194
195
196
  (define (do-or-die command   #!key nodie (foreach-stdout #f) (stdin-proc #f))
    (let-values (((exit-code stdout-str stderr-str) (isys command foreach-stdout-thunk: foreach-stdout stdin-proc: stdin-proc )))
      (if (equal? 0 exit-code)
          stdout-str
          (begin
            (ierr (conc "Command  > " command " "  "< failed with " exit-code " because: \n" stderr-str) )
            (if nodie #f (exit exit-code))))))















  ;; runs-ok: evaluate expression while suppressing exceptions.
                                        ;    on caught exception, returns #f
                                        ;    otherwise, returns expression value
  (define (runs-ok thunk)
    (handle-exceptions exn #f (begin (thunk) #t)))
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
          (host (or (get-environment-variable "HOST") "nohost")))
      (if logfile
          (begin
            (ducttape-log-file logfile)
            (setenv "DUCTTAPE_LOG_FILE" (ducttape-log-file))))
      (ducttape-append-logfile 'note (format #f "START - pid=~A ppid=~A argv=(~A) pwd=~A user=~A host=~A" pid ppid argv pwd user host) #t)))         

  ;; immediately activate logfile (will be noop if logfile disabled)
  (ducttape-activate-logfile)

  ;; log exit code
  (define (set-exit-handler)
    (let ((orig-exit-handler (exit-handler)))
      (exit-handler 
       (lambda (exitcode) 
         (ducttape-append-logfile 'note (format #f "Exit ~A by sys.exit" exitcode) #t)
         (orig-exit-handler exitcode)))))
  (set-exit-handler)
  
  ;; TODO: hook exception handler so we can log exception before we sign off.

  (define (idbg first-message  . rest-args)
    (let* ((debug-level-threshold
            (if (> (length rest-args) 0) (car rest-args) 1))
           (message-list
            (if (> (length rest-args) 1)
                (cons first-message (cdr rest-args))







<
<


|





<
|
<







329
330
331
332
333
334
335


336
337
338
339
340
341
342
343

344

345
346
347
348
349
350
351
          (host (or (get-environment-variable "HOST") "nohost")))
      (if logfile
          (begin
            (ducttape-log-file logfile)
            (setenv "DUCTTAPE_LOG_FILE" (ducttape-log-file))))
      (ducttape-append-logfile 'note (format #f "START - pid=~A ppid=~A argv=(~A) pwd=~A user=~A host=~A" pid ppid argv pwd user host) #t)))         




  ;; log exit code
  (define (set-ducttape-log-exit-handler)
    (let ((orig-exit-handler (exit-handler)))
      (exit-handler 
       (lambda (exitcode) 
         (ducttape-append-logfile 'note (format #f "Exit ~A by sys.exit" exitcode) #t)
         (orig-exit-handler exitcode)))))




  (define (idbg first-message  . rest-args)
    (let* ((debug-level-threshold
            (if (> (length rest-args) 0) (car rest-args) 1))
           (message-list
            (if (> (length rest-args) 1)
                (cons first-message (cdr rest-args))
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
                   (next-rest (cdr rest-path-items))
                   (candidate (conc this-dir "/" exe)))
              (if (file-execute-access? candidate)
                  candidate
                  (loop next-rest)))))))




  ;; (define (launch-repl )
  ;;   (use linenoise)
  ;;   (current-input-port (make-linenoise-port))

  ;;   (let ((histfile (conc (or (get-environment-variable "HOME") ".") "/." (script-name) "-hist")))
  
  ;;     (set-history-length! 30000)
  
  ;;     (load-history-from-file histfile)
  
  ;;     (let loop ((l (linenoise "> ")))
  ;;       (cond ((equal? l "bye")
  ;;              (save-history-to-file histfile)
  ;;              "Bye!")
  ;;             ((eof-object? l)
  ;;              (save-history-to-file histfile)
  ;;              (exit))
  ;;             (else
  ;;              (display l)
  ;;              (handle-exceptions exn
  ;;                  ;;(print-call-chain (current-error-port))
  ;;                  (let ((message ((condition-property-accessor 'exn 'message) exn)))
  ;;                    (print "exn> " message )
  ;;                    ;;(pp (condition->list exn))
  ;;                    ;;(exit)
  ;;                    ;;(display "Went wrong")
  ;;                    (newline))
  ;;                (print (eval l)))))
  ;;       (newline)
  ;;       (history-add l)
  ;;       (loop (linenoise "> ")))))
  
  ;; (define (launch-repl2 )
  ;;   (use readline)
  ;;   (use apropos)
  ;;   (use trace)
  ;;   ;(import csi)
  ;;   (current-input-port (make-readline-port (conc (script-name) "> ") "... "))
  ;;  ; (install-history-file #f (conc (or (get-environment-variable "HOME") ".") "/." (script-name) "_history"))
  ;;   (parse-and-bind "set editing-mode emacs")
  ;;   (install-history-file)
  ;;   (let loop ((foo #f))

  ;;     (let ((expr (read)))
  ;;       (cond
  ;;        ((eof-object? expr) (exit))
  ;;        (else
  ;;         (handle-exceptions exn
  ;;             ;;(print-call-chain (current-error-port))
  ;;             (let ((message ((condition-property-accessor 'exn 'message) exn)))
  ;;               (print "exn> " message )
  ;;               ;;(pp (condition->list exn))
  ;;               ;;(exit)
  ;;               ;;(display "Went wrong")
  ;;               (newline))
  ;;           (print (eval expr))))))
  ;;     (loop #f))
  ;;   )

;;;; process command line options

  ;; get command line switches (have no subsequent arg; eg. [-foo])
  ;;  assumes these are switches without arguments
  ;;  will return list of matches
  ;;  removes matches from command-line-arguments parameter
  (define (skim-cmdline-opts-noarg-by-regex switch-pattern)







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







599
600
601
602
603
604
605





























































606
607
608
609
610
611
612
                   (next-rest (cdr rest-path-items))
                   (candidate (conc this-dir "/" exe)))
              (if (file-execute-access? candidate)
                  candidate
                  (loop next-rest)))))))































































;;;; process command line options

  ;; get command line switches (have no subsequent arg; eg. [-foo])
  ;;  assumes these are switches without arguments
  ;;  will return list of matches
  ;;  removes matches from command-line-arguments parameter
  (define (skim-cmdline-opts-noarg-by-regex switch-pattern)
737
738
739
740
741
742
743


744
745
746
747
748
749
750
751
  
  

  ;; recognize ducttape-lib command line switches (--quiet, --silent, --color, -d.., -dp.., -logfile)
  ;;    - reset parameters; reset DUCTTAPE_* env vars to match user specified intent
  ;;    - mutate (command-line-arguments) parameter to subtract these recognized and handled switches
  ;;       * beware -- now (argv) and (command-line-arguments) are inconsistent... cannot mutate (argv) alas.  Use (command-line-arguments)


  (define (process-command-line)

    ;; --quiet
    (let ((quiet-opts (skim-cmdline-opts-noarg-by-regex "--?quiet")))
      (if (not (null? quiet-opts))
          (begin
            (setenv "DUCTTAPE_QUIET_MODE" "1")
            (ducttape-quiet-mode "1"))))







>
>
|







662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
  
  

  ;; recognize ducttape-lib command line switches (--quiet, --silent, --color, -d.., -dp.., -logfile)
  ;;    - reset parameters; reset DUCTTAPE_* env vars to match user specified intent
  ;;    - mutate (command-line-arguments) parameter to subtract these recognized and handled switches
  ;;       * beware -- now (argv) and (command-line-arguments) are inconsistent... cannot mutate (argv) alas.  Use (command-line-arguments)
  ;; WARNING: this defines command line arguments that may clash with your program.  Only call this if you
  ;; are sure they can coexist.
  (define (ducttape-process-command-line)

    ;; --quiet
    (let ((quiet-opts (skim-cmdline-opts-noarg-by-regex "--?quiet")))
      (if (not (null? quiet-opts))
          (begin
            (setenv "DUCTTAPE_QUIET_MODE" "1")
            (ducttape-quiet-mode "1"))))
801
802
803
804
805
806
807








808
809
810
811
812
    ;; -dp <pat> / --debug-pattern <pat>
    (let ((debugpat-opts (skim-cmdline-opts-withargs-by-regex "--?(debug-pattern|dp)")))
      (if (not (null? debugpat-opts))
          (begin
            (ducttape-debug-regex-filter (string-join debugpat-opts "|"))
            (setenv "DUCTTAPE_DEBUG_PATTERN" (ducttape-debug-regex-filter)))))) 









  ;; handle command line immediately; 
  (process-command-line)                    


  ) ; end module







>
>
>
>
>
>
>
>

|



728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
    ;; -dp <pat> / --debug-pattern <pat>
    (let ((debugpat-opts (skim-cmdline-opts-withargs-by-regex "--?(debug-pattern|dp)")))
      (if (not (null? debugpat-opts))
          (begin
            (ducttape-debug-regex-filter (string-join debugpat-opts "|"))
            (setenv "DUCTTAPE_DEBUG_PATTERN" (ducttape-debug-regex-filter)))))) 


  ;;; following code commented out; side effects not wanted on startup
  ;; immediately activate logfile (will be noop if logfile disabled)
  ;;(ducttape-activate-logfile)
  ;;(set-ducttape-log-exit-handler)
  
  ;; TODO: hook exception handler so we can log exception before we sign off.

  ;; handle command line immediately; 
  ;;(process-command-line)                    


  ) ; end module

Modified ducttape/test_ducttape.scm from [be9cb91086] to [5a04bd5130].

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  (ducttape-color-mode #f)
)

(define (reset-ducttape-with-cmdline-list cmdline-list)
  (reset-ducttape)

  (command-line-arguments cmdline-list)
  (process-command-line)
)


(define (direct-iputs-test)
  (ducttape-color-mode #f)
  (ierr "I'm an error")
  (iwarn "I'm a warning")







|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
  (ducttape-color-mode #f)
)

(define (reset-ducttape-with-cmdline-list cmdline-list)
  (reset-ducttape)

  (command-line-arguments cmdline-list)
  (ducttape-process-command-line)
)


(define (direct-iputs-test)
  (ducttape-color-mode #f)
  (ierr "I'm an error")
  (iwarn "I'm a warning")
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
   
   (let-values (((ec o e) (isys "/bin/ls /zzzzz")))
     (let ((expected-code
            (if (equal? systype "Darwin") 1 2))
           (expected-err
            (if (equal? systype "Darwin")
                "ls: /zzzzz: No such file or directory"
                "/bin/ls: cannot access /zzzzz: No such file or directory"))

           )
       (test "isys: /bin/ls /zzzzz should have exit code 2" expected-code ec)
       (test "isys: /bin/ls /zzzzz should have empty stdout" "" o)
       (test
        "isys: /bin/ls /zzzzz should have stderr"
        expected-err







|







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
   
   (let-values (((ec o e) (isys "/bin/ls /zzzzz")))
     (let ((expected-code
            (if (equal? systype "Darwin") 1 2))
           (expected-err
            (if (equal? systype "Darwin")
                "ls: /zzzzz: No such file or directory"
                "/bin/ls: .* /zzzzz: No such file or directory"))

           )
       (test "isys: /bin/ls /zzzzz should have exit code 2" expected-code ec)
       (test "isys: /bin/ls /zzzzz should have empty stdout" "" o)
       (test
        "isys: /bin/ls /zzzzz should have stderr"
        expected-err