- Add forgotten variable/define test suite
authorPaul Smith <psmith@gnu.org>
Fri, 5 Jun 2009 01:17:29 +0000 (01:17 +0000)
committerPaul Smith <psmith@gnu.org>
Fri, 5 Jun 2009 01:17:29 +0000 (01:17 +0000)
- Skip initial whitespace including formfeeds, vertical tab, etc.
- Add tests for that
- Fix the variable/SHELL test; it was wrong!

ChangeLog
read.c
tests/ChangeLog
tests/scripts/misc/general4
tests/scripts/variables/SHELL
tests/scripts/variables/define [new file with mode: 0644]

index 4996eab..a3ea3e4 100644 (file)
--- 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 (file)
--- 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;
index 52c2d73..9e48022 100644 (file)
@@ -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>
index ccccf88..e67323b 100644 (file)
@@ -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;
index 67593e5..acc5903 100644 (file)
@@ -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 (file)
index 0000000..f91519e
--- /dev/null
@@ -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;