| 1 |
# -*-perl-*- |
| 2 |
|
| 3 |
$description = 'Test the $(guile ...) function.'; |
| 4 |
|
| 5 |
$details = 'This only works on systems that support it.'; |
| 6 |
|
| 7 |
# If this instance of make doesn't support GNU Guile, skip it |
| 8 |
# This detects if guile is loaded using the "load" directive |
| 9 |
# $makefile = get_tmpfile(); |
| 10 |
# open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n"; |
| 11 |
# print MAKEFILE q! |
| 12 |
# -load guile |
| 13 |
# all: ; @echo $(filter guile,$(.LOADED)) |
| 14 |
# !; |
| 15 |
# close(MAKEFILE) || die "Failed to write $makefile: $!\n"; |
| 16 |
# $cmd = subst_make_string("#MAKEPATH# -f $makefile"); |
| 17 |
# $log = get_logfile(0); |
| 18 |
# $code = run_command_with_output($log, $cmd); |
| 19 |
# read_file_into_string ($log) eq "guile\n" and $FEATURES{guile} = 1; |
| 20 |
|
| 21 |
# If we don't have Guile support, never mind. |
| 22 |
exists $FEATURES{guile} or return -1; |
| 23 |
|
| 24 |
# Guile and Valgrind don't play together at all. |
| 25 |
$valgrind and return -1; |
| 26 |
|
| 27 |
# Verify simple data type conversions |
| 28 |
# Currently we don't support vectors: |
| 29 |
# echo '$(guile (vector 1 2 3))'; \ |
| 30 |
run_make_test(q! |
| 31 |
x:;@echo '$(guile #f)'; \ |
| 32 |
echo '$(guile #t)'; \ |
| 33 |
echo '$(guile #\c)'; \ |
| 34 |
echo '$(guile 1234)'; \ |
| 35 |
echo '$(guile 'foo)'; \ |
| 36 |
echo '$(guile "bar")'; \ |
| 37 |
echo '$(guile (cons 'a 'b))'; \ |
| 38 |
echo '$(guile '(a b (c . d) 1 (2) 3))' |
| 39 |
!, |
| 40 |
'', "\n#t\nc\n1234\nfoo\nbar\na b\na b c d 1 2 3"); |
| 41 |
|
| 42 |
# Verify guile functions in variables -- SV 43378 |
| 43 |
run_make_test(q! |
| 44 |
res := $(guile #f) \ |
| 45 |
$(guile #t) \ |
| 46 |
$(guile #\c) \ |
| 47 |
$(guile 1234) \ |
| 48 |
$(guile 'foo) \ |
| 49 |
$(guile "bar") \ |
| 50 |
$(guile (cons 'a 'b)) \ |
| 51 |
$(guile '(a b (c . d) 1 (2) 3)) |
| 52 |
x:;@echo '$(res)' |
| 53 |
!, |
| 54 |
'', " #t c 1234 foo bar a b a b c d 1 2 3"); |
| 55 |
|
| 56 |
# Verify the gmk-expand function |
| 57 |
run_make_test(q! |
| 58 |
VAR = $(guile (gmk-expand "$(shell echo hi)")) |
| 59 |
x:;@echo '$(VAR)' |
| 60 |
!, |
| 61 |
'', "hi"); |
| 62 |
|
| 63 |
# Verify the gmk-eval function |
| 64 |
# Prove that the string is expanded only once (by eval) |
| 65 |
run_make_test(q! |
| 66 |
TEST = bye |
| 67 |
EVAL = VAR = $(TEST) $(shell echo there) |
| 68 |
$(guile (gmk-eval "$(value EVAL)")) |
| 69 |
TEST = hi |
| 70 |
x:;@echo '$(VAR)' |
| 71 |
!, |
| 72 |
'', "hi there"); |
| 73 |
|
| 74 |
# Verify the gmk-eval function with a list |
| 75 |
run_make_test(q! |
| 76 |
$(guile (gmk-eval '(VAR = 1 (2) () 3))) |
| 77 |
x:;@echo '$(VAR)' |
| 78 |
!, |
| 79 |
'', "1 2 3"); |
| 80 |
|
| 81 |
# Verify the gmk-var function |
| 82 |
run_make_test(q! |
| 83 |
VALUE = hi $(shell echo there) |
| 84 |
VAR = $(guile (gmk-var "VALUE")) |
| 85 |
x:;@echo '$(VAR)' |
| 86 |
!, |
| 87 |
'', "hi there"); |
| 88 |
|
| 89 |
# Verify the gmk-var function with a symbol |
| 90 |
run_make_test(q! |
| 91 |
VALUE = hi $(shell echo there) |
| 92 |
VAR = $(guile (gmk-var 'VALUE)) |
| 93 |
x:;@echo '$(VAR)' |
| 94 |
!, |
| 95 |
'', "hi there"); |
| 96 |
|
| 97 |
# Write a Guile program using define and run it |
| 98 |
run_make_test(q! |
| 99 |
# Define the "fib" function in Guile |
| 100 |
define fib |
| 101 |
;; A procedure for counting the n:th Fibonacci number |
| 102 |
;; See SICP, p. 37 |
| 103 |
(define (fib n) |
| 104 |
(cond ((= n 0) 0) |
| 105 |
((= n 1) 1) |
| 106 |
(else (+ (fib (- n 1)) |
| 107 |
(fib (- n 2)))))) |
| 108 |
endef |
| 109 |
$(guile $(fib)) |
| 110 |
|
| 111 |
# Now run it |
| 112 |
x:;@echo $(guile (fib $(FIB))) |
| 113 |
!, |
| 114 |
'FIB=10', "55"); |
| 115 |
|
| 116 |
1; |