summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2009-06-05 01:17:29 +0000
committerPaul Smith <psmith@gnu.org>2009-06-05 01:17:29 +0000
commit71385e12250ea56ddb2186f22a3f741684562ac5 (patch)
tree0019528d008184f579bacd2e5af9c37e323d403a
parent81f3e4babd128f6740d05b371122762924522fb6 (diff)
downloadgunmake-71385e12250ea56ddb2186f22a3f741684562ac5.tar.gz
- Add forgotten variable/define test suite
- Skip initial whitespace including formfeeds, vertical tab, etc. - Add tests for that - Fix the variable/SHELL test; it was wrong!
-rw-r--r--ChangeLog2
-rw-r--r--read.c7
-rw-r--r--tests/ChangeLog5
-rw-r--r--tests/scripts/misc/general413
-rw-r--r--tests/scripts/variables/SHELL2
-rw-r--r--tests/scripts/variables/define234
6 files changed, 261 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 4996eab..a3ea3e4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2009-06-04 Paul Smith <psmith@gnu.org>
+ * read.c (eval): Skip initial whitespace (ffeed, vtab, etc.)
+
* maintMakefile: Modify access of config and gnulib Savannah
modules to use GIT instead of CVS.
diff --git a/read.c b/read.c
index 6ecc2ca..aa13a21 100644
--- a/read.c
+++ b/read.c
@@ -680,9 +680,14 @@ eval (struct ebuffer *ebuf, int set_default)
collapse_continuations (collapsed);
remove_comments (collapsed);
+ /* Get rid if starting space (including formfeed, vtab, etc.) */
+ p = collapsed;
+ while (isspace ((unsigned char)*p))
+ ++p;
+
/* See if this is a variable assignment. We need to do this early, to
allow variables with names like 'ifdef', 'export', 'private', etc. */
- p = parse_var_assignment(collapsed, &vmod);
+ p = parse_var_assignment(p, &vmod);
if (vmod.assign_v)
{
struct variable *v;
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 52c2d73..9e48022 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,5 +1,10 @@
2009-06-04 Paul Smith <psmith@gnu.org>
+ * scripts/variables/SHELL: The export target-specific SHELL test
+ has an incorrect known-good-value.
+
+ * scripts/misc/general4: Check for whitespace (ffeed, vtab, etc.)
+
* scripts/features/se_explicit: Add tests for Savannah bug #24588.
2009-05-31 Paul Smith <psmith@gnu.org>
diff --git a/tests/scripts/misc/general4 b/tests/scripts/misc/general4
index ccccf88..e67323b 100644
--- a/tests/scripts/misc/general4
+++ b/tests/scripts/misc/general4
@@ -80,4 +80,17 @@ dir/subdir/%.$$a: dir/subdir/%.$$b ; @echo 'cp $< $@'
!,
'', "mkdir -p dir/subdir\ntouch dir/subdir/file.\$b\ncp dir/subdir/file.\$b dir/subdir/file.\$a\n");
+# Test odd whitespace at the beginning of a line
+
+run_make_test("
+all:
+ \f
+
+ \\
+ \f \\
+ \013 \\
+all: ; \@echo hi
+",
+ '', "hi\n");
+
1;
diff --git a/tests/scripts/variables/SHELL b/tests/scripts/variables/SHELL
index 67593e5..acc5903 100644
--- a/tests/scripts/variables/SHELL
+++ b/tests/scripts/variables/SHELL
@@ -51,6 +51,6 @@ $extraENV{SHELL} = $mshell;
run_make_test("all: export SHELL := /./$mshell\n".'
all:;@echo "$(SHELL) $$SHELL"
-', '', "/./$mshell $mshell");
+', '', "/./$mshell /./$mshell");
1;
diff --git a/tests/scripts/variables/define b/tests/scripts/variables/define
new file mode 100644
index 0000000..f91519e
--- /dev/null
+++ b/tests/scripts/variables/define
@@ -0,0 +1,234 @@
+# -*-perl-*-
+
+$description = "Test define/endef variable assignments.";
+
+$details = "";
+
+# TEST 0: old-style basic define/endef
+
+run_make_test('
+define multi
+@echo hi
+echo there
+endef
+
+all: ; $(multi)
+',
+ '', "hi\necho there\nthere\n");
+
+# TEST 1: Various new-style define/endef
+
+run_make_test('
+FOO = foo
+
+define multi =
+echo hi
+@echo $(FOO)
+endef # this is the end
+
+define simple :=
+@echo $(FOO)
+endef
+
+append = @echo a
+
+define append +=
+
+@echo b
+endef
+
+define cond ?= # this is a conditional
+@echo first
+endef
+
+define cond ?=
+@echo second
+endef
+
+FOO = there
+
+all: ; $(multi)
+ $(simple)
+ $(append)
+ $(cond)
+',
+ '', "echo hi\nhi\nthere\nfoo\na\nb\nfirst\n");
+
+# TEST 2: define in true section of conditional (containing conditional)
+
+run_make_test('
+FOO = foo
+NAME = def
+def =
+ifdef BOGUS
+ define $(subst e,e,$(NAME)) =
+ ifeq (1,1)
+ FOO = bar
+ endif
+ endef
+endif
+
+$(eval $(def))
+all: ; @echo $(FOO)
+',
+ 'BOGUS=1', "bar\n");
+
+# TEST 3: define in false section of conditional (containing conditional)
+
+run_make_test(undef, '', "foo\n");
+
+# TEST 4: nested define (supported?)
+
+run_make_test('
+define outer
+ define inner
+ A = B
+ endef
+endef
+
+$(eval $(outer))
+
+outer: ; @echo $(inner)
+',
+ '', "A = B\n");
+
+# TEST 5: NEGATIVE: Missing variable name
+
+run_make_test('
+NAME =
+define $(NAME) =
+ouch
+endef
+all: ; @echo ouch
+',
+ '', "#MAKEFILE#:3: *** empty variable name. Stop.\n", 512);
+
+# TEST 6: NEGATIVE: extra text after define
+
+run_make_test('
+NAME =
+define NAME = $(NAME)
+ouch
+endef
+all: ; @echo ok
+',
+ '', "#MAKEFILE#:3: extraneous text after `define' directive\nok\n");
+
+# TEST 7: NEGATIVE: extra text after endef
+
+run_make_test('
+NAME =
+define NAME =
+ouch
+endef $(NAME)
+all: ; @echo ok
+',
+ '', "#MAKEFILE#:5: extraneous text after `endef' directive\nok\n");
+
+# TEST 8: NEGATIVE: missing endef
+
+run_make_test('
+NAME =
+all: ; @echo ok
+define NAME =
+ouch
+endef$(NAME)
+',
+ '', "#MAKEFILE#:4: *** missing `endef', unterminated `define'. Stop.\n", 512);
+
+# -------------------------
+# Make sure that prefix characters apply properly to define/endef values.
+#
+# There's a bit of oddness here if you try to use a variable to hold the
+# prefix character for a define. Even though something like this:
+#
+# define foo
+# echo bar
+# endef
+#
+# all: ; $(V)$(foo)
+#
+# (where V=@) can be seen by the user to be obviously different than this:
+#
+# define foo
+# $(V)echo bar
+# endef
+#
+# all: ; $(foo)
+#
+# and the user thinks it should behave the same as when the "@" is literal
+# instead of in a variable, that can't happen because by the time make
+# expands the variables for the command line and sees it begins with a "@" it
+# can't know anymore whether the prefix character came before the variable
+# reference or was included in the first line of the variable reference.
+
+# TEST #5
+# -------
+
+run_make_test('
+define FOO
+$(V1)echo hello
+$(V2)echo world
+endef
+all: ; @$(FOO)
+', '', 'hello
+world');
+
+# TEST #6
+# -------
+
+run_make_test(undef, 'V1=@ V2=@', 'hello
+world');
+
+# TEST #7
+# -------
+
+run_make_test('
+define FOO
+$(V1)echo hello
+$(V2)echo world
+endef
+all: ; $(FOO)
+', 'V1=@', 'hello
+echo world
+world');
+
+# TEST #8
+# -------
+
+run_make_test(undef, 'V2=@', 'echo hello
+hello
+world');
+
+# TEST #9
+# -------
+
+run_make_test(undef, 'V1=@ V2=@', 'hello
+world');
+
+# TEST #10
+# -------
+# Test the basics; a "@" internally to the variable applies to only one line.
+# A "@" before the variable applies to the entire variable.
+
+run_make_test('
+define FOO
+@echo hello
+echo world
+endef
+define BAR
+echo hello
+echo world
+endef
+
+all: foo bar
+foo: ; $(FOO)
+bar: ; @$(BAR)
+', '', 'hello
+echo world
+world
+hello
+world
+');
+
+1;