Re: DejaGnu directive matching multiple messages on the same line

2016-07-25 Thread Joseph Myers
On Wed, 20 Jul 2016, Jakub Jelinek wrote:

> On Wed, Jul 20, 2016 at 02:19:15PM -0600, Martin Sebor wrote:
> > Is there a way to express a requirement that a single line cause
> > two or more diagnostic messages (in any order) each matching one
> > of the regex strings?
> 
> Sure, and it is used many times in the testsuite.
> 
>   whatever; /* { dg-error "whatever1" } */
>   /* { dg-error "whatever2" "" { target *-*-* } 33 } */

But use something distinct in place of "", as if you use "" (or more 
generally, the same string for multiple dg-error on the same line) then 
you get multiple test assertions with the same name (the string that 
appears after PASS: or FAIL: in the .sum file), which is bad for comparing 
test results.

-- 
Joseph S. Myers
jos...@codesourcery.com


Re: DejaGnu directive matching multiple messages on the same line

2016-07-21 Thread Segher Boessenkool
On Wed, Jul 20, 2016 at 02:57:22PM -0600, Martin Sebor wrote:
> Btw., the above works fine when each directive is on its own line
> but when the second follows the first on the same line (somehow
> I thought it needed to be at first), the second one needs another
> string argument.  I haven't looked into what it's for but the regex
> is the second argument in this case, not the first.  Like this:
> 
>   whatever; // { dg-error "regex-1" } { dg-error "???" "regex2" "fail 
> message" { target-selector }  }

dg-error takes the current line number as the first argument; it is
automagically put there unless you do weird things like you do ;-)


Segher


Re: DejaGnu directive matching multiple messages on the same line

2016-07-20 Thread Martin Sebor

On 07/20/2016 02:28 PM, Jakub Jelinek wrote:

On Wed, Jul 20, 2016 at 02:19:15PM -0600, Martin Sebor wrote:

Is there a way to express a requirement that a single line cause
two or more diagnostic messages (in any order) each matching one
of the regex strings?


Sure, and it is used many times in the testsuite.

   whatever; /* { dg-error "whatever1" } */
   /* { dg-error "whatever2" "" { target *-*-* } 33 } */

You need to use the target specification and supply line number in the
second and following directive which you want to apply to the same line.


Thanks!  I'd seen this pattern but completely forgot about it.
Let me update the Wiki.

Btw., the above works fine when each directive is on its own line
but when the second follows the first on the same line (somehow
I thought it needed to be at first), the second one needs another
string argument.  I haven't looked into what it's for but the regex
is the second argument in this case, not the first.  Like this:

  whatever; // { dg-error "regex-1" } { dg-error "???" "regex2" "fail 
message" { target-selector }  }


Martin


Re: DejaGnu directive matching multiple messages on the same line

2016-07-20 Thread Jakub Jelinek
On Wed, Jul 20, 2016 at 02:19:15PM -0600, Martin Sebor wrote:
> Is there a way to express a requirement that a single line cause
> two or more diagnostic messages (in any order) each matching one
> of the regex strings?

Sure, and it is used many times in the testsuite.

  whatever; /* { dg-error "whatever1" } */
  /* { dg-error "whatever2" "" { target *-*-* } 33 } */

You need to use the target specification and supply line number in the
second and following directive which you want to apply to the same line.

Jakub


DejaGnu directive matching multiple messages on the same line

2016-07-20 Thread Martin Sebor

When multiple diagnostics for a given line in a test are expected,
I have been using the vertical bar ('|') in regular expression
arguments to DejaGnu directives like dg-error and dg-warning on
the assumption that all are matched.

This use appears to be sanctioned by the GCC TestCaseWriting Wiki
(https://gcc.gnu.org/wiki/TestCaseWriting):

  Should a line produce two errors, the regular expression can
  include an "|" (ie. a regular expression OR) between the possible
  message fragments.

  If only one of the errors is important, a better way to deal
  with the multiple errors is to check for the one you want with
  dg-error and discard the extras with dg-prune-output: ...

In a discussion of a recent patch of mine I was surprised to learn
that this use may not actually accomplish quite what's intended.
The effect of the bar operator is for the directive to match
a message on that line that contains either the left operand or
the right operand of the regex.  Which means that the directive
is appropriate when it doesn't matter which of the alternatives
matches, but not when both or all messages are expected and need
to be verified.

Is there a way to express a requirement that a single line cause
two or more diagnostic messages (in any order) each matching one
of the regex strings?

I've searched the test suite for examples but couldn't find
anything.  The dg-{begin,end}-multiline-output directive looked
promising until I realized that it does plain string matching
and doesn't appear to be able to match whole errors.

Thanks
Martin