diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-10-09 13:38:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-09 13:38:33 -0700 |
| commit | 06b2192aa2bb6698c863388c5d085ba5b1f28374 (patch) | |
| tree | 27a959d883adad48652ca9461291fddb64b5a9b9 /tests/preprocessor | |
| parent | fe5eef423389b82e7eb2586fb7a16b96afd004f2 (diff) | |
Preprocessor: fix `undef` and redefinition (#204)
* Preprocessor: fix `undef` and redefinition
The logic for `undef` directives was failing to suppress macro expansion when reading the name to un-define, and so it wasn't actually working at all. We didn't notice this because we didn't have a test case, and users hadn't tried it.
The logic for `define` had a similar bug, which meant that any attempt to define an already-defined macro would fail with a cryptic error, rather than raising the intended warning.
Test cases have been added for both issues, along with the fixes.
* fixup: add expected output for tests added
Diffstat (limited to 'tests/preprocessor')
| -rw-r--r-- | tests/preprocessor/define-redefine.slang | 10 | ||||
| -rw-r--r-- | tests/preprocessor/define-redefine.slang.expected | 7 | ||||
| -rw-r--r-- | tests/preprocessor/undef.slang | 32 | ||||
| -rw-r--r-- | tests/preprocessor/undef.slang.expected | 6 |
4 files changed, 55 insertions, 0 deletions
diff --git a/tests/preprocessor/define-redefine.slang b/tests/preprocessor/define-redefine.slang new file mode 100644 index 000000000..42b7a4dbe --- /dev/null +++ b/tests/preprocessor/define-redefine.slang @@ -0,0 +1,10 @@ +//TEST:SIMPLE: + +// Confirm that we handle redefinition +// of an existing define (with a diagnostic) + +#define FOO 1.0f + +float foo() { return FOO + 2.0; } + +#define FOO 2.0f diff --git a/tests/preprocessor/define-redefine.slang.expected b/tests/preprocessor/define-redefine.slang.expected new file mode 100644 index 000000000..2542c05d8 --- /dev/null +++ b/tests/preprocessor/define-redefine.slang.expected @@ -0,0 +1,7 @@ +result code = 0 +standard error = { +tests/preprocessor/define-redefine.slang(10): warning 15400: redefinition of macro 'FOO' +tests/preprocessor/define-redefine.slang(6): note: see previous definition of 'FOO' +} +standard output = { +} diff --git a/tests/preprocessor/undef.slang b/tests/preprocessor/undef.slang new file mode 100644 index 000000000..42ce05be7 --- /dev/null +++ b/tests/preprocessor/undef.slang @@ -0,0 +1,32 @@ +//TEST:SIMPLE: +// #undef support + +// warning: undef of something not defined +#undef FOO + +#define BAR 1.0f + +float foo() { return BAR + 2.0; } + +#ifdef BAR +// okay +#else +#error not okay +#endif + +#undef BAR + +typedef float BAR; + +BAR bar() { return 2.0; } + +#if !defined(BAR) +// okay +#else +#error not okay +#endif + + +#define FOO + +#undef FOO diff --git a/tests/preprocessor/undef.slang.expected b/tests/preprocessor/undef.slang.expected new file mode 100644 index 000000000..2f7026487 --- /dev/null +++ b/tests/preprocessor/undef.slang.expected @@ -0,0 +1,6 @@ +result code = 0 +standard error = { +tests/preprocessor/undef.slang(5): warning 15401: macro 'FOO' is not defined +} +standard output = { +} |
