Files
sex/tests/args.scm
alex-eg dc15aaadab write a make rule for the modules a unit reads
An import pastes another file's forms into the output, so a Makefile
had to make every object depend on every .sex. --depfile names the
modules read, including those read only for an import's interface,
with an empty rule for each, as cc -MD -MP does.

Fixes #40.
2026-10-19 16:05:08 +03:00

84 lines
3.2 KiB
Scheme

;;; Splitting the command line at `--'.
;;;
;;; getopt-long cannot do this: it consumes the separator and merges
;;; everything after it into `@' alongside the input file. So sexc
;;; splits the raw argv first, and only the head is parsed as options.
;;; Everything else reaches the C compiler exactly as written --
;;; including the words that do not start with a dash, which a previous
;;; leading-dash heuristic used to drop.
(import sexc)
(define full '("foo.sex" "-o" "bar" "--" "-framework" "OpenGL" "-Wall"))
(test-group "argument separator"
(test "options and input file stay with sexc"
'("foo.sex" "-o" "bar")
(args-before-separator full))
(test "the tail reaches the compiler verbatim"
'("-framework" "OpenGL" "-Wall")
(args-after-separator full))
;; The case that motivated this: `OpenGL' has no leading dash and was
;; silently dropped, leaving `-framework' to swallow whatever flag
;; came next.
(test "a word without a dash survives"
'("-framework" "OpenGL")
(args-after-separator '("x.sex" "--" "-framework" "OpenGL")))
(test "no separator means nothing for the compiler"
'()
(args-after-separator '("foo.sex" "-o" "bar")))
(test "no separator leaves every argument with sexc"
'("foo.sex" "-o" "bar")
(args-before-separator '("foo.sex" "-o" "bar")))
(test "a trailing separator is allowed"
'()
(args-after-separator '("foo.sex" "--")))
(test "a leading separator leaves no input file"
'()
(args-before-separator '("--" "-lm")))
;; Only the first `--' separates; a later one is an ordinary compiler
;; argument (ld takes several).
(test "only the first separator counts"
'("-Wl,--as-needed" "--" "-lm")
(args-after-separator '("x.sex" "--" "-Wl,--as-needed" "--" "-lm")))
(test "an empty command line is handled"
'()
(args-before-separator '()))
;; getopt-long reads a lone `-' as an option and refused `-o -', so
;; it is handed the one spelling it takes a dash in
(test "-o - reaches getopt-long as a value"
'("x.sex" "--output=-" "-C")
(spell-stdout-output '("x.sex" "-o" "-" "-C")))
(test "and so does --output -"
'("--output=-")
(spell-stdout-output '("--output" "-")))
(test "any other output is left alone"
'("-o" "out" "-")
(spell-stdout-output '("-o" "out" "-"))))
;;; --depfile: an import pastes another file's forms into the output, so
;;; the output depends on that file as a C object does on a header
(test-group "dependency rule"
(test "the target, the source and the modules, then a rule per module"
"app.o: app.sex /m/greet.sex /m/ledger.sex\n\n/m/greet.sex:\n\n/m/ledger.sex:\n"
(dependency-rule "app.o" "app.sex" '("/m/greet.sex" "/m/ledger.sex")))
(test "no modules, no rules of their own"
"app.o: app.sex\n"
(dependency-rule "app.o" "app.sex" '()))
(test "a space is escaped, the way make reads it"
"a\\ b.o: a\\ b.sex\n"
(dependency-rule "a b.o" "a b.sex" '()))
(test "stdin is no file to depend on"
"app.o: /m/greet.sex\n\n/m/greet.sex:\n"
(dependency-rule "app.o" #f '("/m/greet.sex"))))