Commit Graph

4554 Commits

Author SHA1 Message Date
rillig b1b4392b00 tests/libcurses: reduce boilerplate in function dispatcher
This makes the code more declarative and easier to reason about.

The generated code stays exactly the same.
2021-02-12 08:55:32 +00:00
rillig 518cbcb21b tests/libcurses: add missing space after control flow keywords 2021-02-09 20:42:31 +00:00
rillig 6938509815 tests/libcurses: replace remaining strcasecmp with strcmp
There is no reason to write special functions in a different case than
the canonical one, just like for the regular curses functions.
2021-02-09 20:39:20 +00:00
rillig e91849a6b1 tests/libcurses: fix spelling of the special call to DRAIN 2021-02-09 20:31:02 +00:00
rillig 82a08c1a4a tests/libcurses: compare function names case-sensitive
There is absolutely no reason to write function names in upper case or
mixed case.
2021-02-09 20:24:02 +00:00
rillig 74a9e3d2cc tests/libcurses: fix scanf parameter for unsigned int 2021-02-09 20:22:11 +00:00
rillig 03f821dbf2 tests/libcurses: fix off-by-one error in line numbers in diagnostics
I had broken this in testlang_parse.y 1.22 from 2021-02-07, when I
extracted the common 'eol' from the statements.  Extracting 'eol' had
the effect that the action for the statement was run before the line
number increased.

Now the line numbers in the diagnostics are the same again as before.

For lines that end with a backslash, the reported line number is the one
from the last of these lines, not the first one, also as before.  This
feature is not used by any of the current tests though.
2021-02-08 23:54:03 +00:00
joerg cfe420e9b1 Don't define a label twice. 2021-02-08 23:50:25 +00:00
rillig facc9c9e92 tests/libcurses: use consistent indentation for grammar rules 2021-02-08 20:55:42 +00:00
rillig 91cc09774d tests/libcurses: extract functions 'input' and 'noinput' from grammar 2021-02-08 20:39:33 +00:00
rillig 9e7915b0b6 tests/libcurses: indent grammar functions consistently 2021-02-08 20:26:46 +00:00
rillig 66374bbd09 tests/libcurses: declare %type in grammar
It looks as if the original author just didn't know how to declare the
type of non-terminals.  The explicit types in the '$' expressions were
all consistent.

No functional change.
2021-02-08 20:09:45 +00:00
rillig 9dc059c978 tests/libcurses: extract function 'delay_millis' from the grammar 2021-02-08 19:35:21 +00:00
rillig b798190935 tests/libcurses: move function 'check' out of the grammar section
This removes the inconsistent indentation.
2021-02-08 19:28:08 +00:00
rillig 09f966d145 tests/libcurses: fix typo in license text 2021-02-08 19:15:20 +00:00
rillig 057f5777ce tests/libcurses: remove unused token DRAIN
There is a special function named 'DRAIN', but not a statement.  The
function name does not need its own token.
2021-02-08 19:09:59 +00:00
rillig 12fb37738f tests/libcurses: fix sentinel for execl
For systems where NULL is defined as a simple 0 or 0L.
2021-02-08 19:04:37 +00:00
rillig dc127031c2 tests/libcurses: on errors, print nonprintable characters as well 2021-02-08 19:00:22 +00:00
rillig 7879077738 tests/libcurses: fix undefined behavior in test addch
The libcurses framework is not strictly typed and thus provides plenty
of ways to shoot yourself in the foot.  It's a waste of time debugging
things that a proper programming language can easily prevent.

The function addch expects an argument of type 'chtype'.  Passing a
"double-quoted" string does not match this, as 'chtype' is completely
different from a plain 'char'.  Instead, functions taking a 'chtype'
must be passed a `backtick-quoted` string.
2021-02-07 23:30:33 +00:00
rillig 1f48f93d43 tests/libcurses: use a single message style for diagnostics
Previously, there were several concurring styles:

	$msg in line %zu of file %s
	$msg line %zu of file %s
	%s, %zu: $msg

All these are now replaced with "%s:%zu: $msg".
2021-02-07 21:33:27 +00:00
rillig 9b3211a8fb tests/libcurses: make grammar for test cases conflict-free
No functional change.
2021-02-07 20:48:07 +00:00
rillig 9903d631af tests/libcurses: fix grammar for arrays
Previously, commas were completely ignored by the grammar.  Erroring out
on invalid characters made some of the tests fail since the comma was
not recognized anymore.  Add it back, but only for defining arrays.  It
would have been possible to leave out the commas or make them optional,
but since the current tests do not make use of that, keep the grammar as
strict as possible.

Fix an unclosed string literal in a test.  This had been wrongly
accepted before by the grammar.
2021-02-07 20:40:05 +00:00
rillig 925203b1c3 tests/libcurses: do not allow control characters in paths 2021-02-07 20:32:25 +00:00
rillig c2ad8acebe tests/libcurses: error out on trying to parse /dev/zero
Be strict when parsing the tests.  Any unknown character is an error.
This avoids an endless loop when running "./director /dev/zero".  There
is no point in silently ignoring other invalid characters as well, as
this would only leave potential test writers in an unclear state,
without any benefit.
2021-02-07 20:27:40 +00:00
rillig b30645eb36 tests/libcurses: fix documentation of call[234]
The function getyx is not a function but a macro.  It does not return
int, but void.  Since these changes destroy the simplicity of the
example, combining a regular return value and pass-by-reference return
values, I rewrote the whole section and added more examples.
2021-02-07 20:20:06 +00:00
rillig ccd1df52a9 tests/libcurses: require keywords to be lowercase, except for OK and ERR
There is no need to write the keywords in upper case or mixed case.  The
only case where a keyword did not have the canonical form yet was a
single lowercase 'ok' in the test case 'innstr'.
2021-02-07 19:49:32 +00:00
rillig 183d5aec4d tests/libcurses: add missing semicolon in grammar 2021-02-07 19:44:34 +00:00
rillig 6989eb7749 tests/libcurses: fix typo in comment 2021-02-07 19:28:07 +00:00
rillig 1134970fd4 tests/libcurses: fix expected test output
The test framework doesn't check the files strictly, it only checks
whether the expected output is a prefix of the actual output, or vice
versa.  This allows several deviations to pass unnoticed, which is
wrong.
2021-02-07 18:56:37 +00:00
rillig cfcf82e703 tests/libcurses: add const to some function parameters 2021-02-07 18:32:20 +00:00
rillig 58e6134faa tests/libcurses: simplify code for writing to the .exp file
If a write(2) returns less than 1, it must be an error.
2021-02-07 18:14:43 +00:00
rillig bdb9e6b7f3 tests/libcurses: actually compare the stream to an absolute path
Up to now, the test command "compare /dev/null" was a no-op since the
command was only parsed but not run at all.  Now run it.

This makes the test mvwin fail.  That test will have to be fixed.

Comparing to /dev/null is certainly possible and may make sense,
comparing to /dev/zero is nonsense since the actual stream can never be
endless.  Some tests do that nevertheless, for whatever reason.

In order to have the expected test output closer to the curses commands
that cause it, it may be a good idea to add another command
'compare_str' that would work independently of an external file and at
the same time allow the expected output to be commented and explained.
This is not possible right now since the .chk files are read exactly
as-is.
2021-02-07 17:50:16 +00:00
rillig 1398f05953 tests/libcurses: use more common abbreviations for tokens 2021-02-07 17:32:55 +00:00
rillig d3b5ee28db tests/libcurses: use standard indentation for grammar rule 'arg' 2021-02-07 17:26:15 +00:00
rillig 126b3d158a tests/libcurses: extract grammar rule 'arg' 2021-02-07 17:23:29 +00:00
rillig aaac17ccef tests/libcurses: error out if called with too many arguments
This helps against users who try to add more options after the first
non-option argument and wonder why these options are silently ignored.
2021-02-07 13:56:23 +00:00
rillig c1b0da3370 tests/libcurses: document another bug in the test director 2021-02-07 13:44:22 +00:00
rillig fb153a60d3 tests/libcurses: fix usage of director 2021-02-07 13:22:23 +00:00
rillig 2eb448fe3b tests/libcurses: demonstrate more bugs in addch 2021-02-07 13:06:02 +00:00
rillig 4e30fe2ad3 tests/libcurses: fail on syntax errors in test files
Previously, a syntax error in a test file made the test pass, which was
outright dangerous.
2021-02-07 12:56:53 +00:00
rillig d51c9371c9 tests/libcurses: use a single indentation style in the test grammar
The grammar rule 'args' has been left as-is since it needs to be split
into 'args' and 'arg' first, to avoid the redundancy.

The braces in "if (create_check_file)" were misleading.  It's strange that
GCC didn't reject this.
2021-02-07 12:48:34 +00:00
rillig 8de39c39e7 tests/libcurses: clean up test case grammar for statements
Previously, each statement ended with 'eol'.  This was unnecessarily
verbose since the 'eol' is not really part of the statement, it's part
of a line.

No functional change.
2021-02-07 12:24:18 +00:00
rillig df2132f7f3 tests/libcurses: fix name of grammar rule
A list of assignments is not a statement, it's several statements.

No functional change.
2021-02-07 12:16:26 +00:00
rillig a13a3f7e27 tests/libcurses: unary minus doesn't make sense on bool expressions
No functional change since -1 is as non-zero as 1.
2021-02-07 12:08:42 +00:00
rillig 4cf90fec0d tests/libcurses: allow end-of-line comments in data lines as well
This makes it possible to write small remarks directly in the affected
line, which not only makes for a clean visual appearance but also shows
up prominently in "cvs annotate" or "git blame", showing when such a
remark has been modified.
2021-02-07 12:05:36 +00:00
rillig 77df4d33b5 tests/libcurses: indent lexer code consistently
Several of the braces were misaligned.  For the simple keywords, there
is no need to write these braces at all, they only made the code look
more complicated than it really is.

I stumbled upon this because syntax errors in the test cases currently
let the test case succeed instead of fail, which is another ingredient
for unreliable tests, besides the loose output matching.
2021-02-07 11:52:43 +00:00
rillig 25d40489d1 libcurses: demonstrate bug in addch that doubles tab indentation
When adding "\t" via addch, win.curx advances by twice the spaces as
intended.  This bug was introduced somewhere between NetBSD 8.0 and 9.0.

Adding "\t" via addstr does not have this bug.

This bug causes the installation menu of sysinst to be have its menu
items indented by 16 characters instead of only 8.  This in turn
produces an ugly line break in the German translation.

The test framework for libcurses is not well integrated into ATF.
Whenever the expected output is longer than the actual output, or vice
versa, the test passes nevertheless.  This makes it necessary to
constantly look into atf-run.log to see whether the actual output is
indeed equal to the expected output, which is crucial, especially for
telling the difference between addstr and addnstr.

Reusing the .chk files for several tests is not a good idea either.  For
example, addstr and waddstr are supposed to produce the same result for
ASCII-only text, so it was tempting to use the same file.  But waddstr
seems to have a bug (maybe undefined behavior), at least waddstr returns
ERR in one case where it shouldn't.  This means that currently the
expected output (acknowledging the bug) must be different.

The "expected" test output in waddstr.chk looks completely broken, but
that's exactly what the test produces right now.
2021-02-07 01:53:54 +00:00
rillig 74e4499250 libcurses: fix typos in introduction to the curses test framework 2021-02-06 20:09:43 +00:00
martin a9fe9302e9 Run all make tests as unprileged user - makes checking permission issues
a lot easier.
2021-02-06 19:00:25 +00:00
rillig b9684d0f53 lint: update message text for 259 in test
That's the one place that is not checked for matching the actual message
by my usual pre-commit checks.
2021-02-04 07:39:39 +00:00