Commit Graph

89 Commits (master)

Author SHA1 Message Date
Nicolas Hake a0c9bfd931 Aul: Correctly check for enable/disable keywords in warning pragma
The parser was only checking that the passed setting matched the
beginning of the expected keyword, instead of checking for the full
length. This way, users could write "#warning e" instead of the
expected "#warning enable" and still have it work.
2019-02-17 11:58:03 +01:00
Nicolas Hake c8d22e321b Aul: Throw correct exception on parameter-less warning pragma
When no parameter followed the "#warning" pragma, because the end
iterator would be located before the begin iterator, basic_string's
constructor would throw std::length_error. Check for this case
beforehand so we can throw the expected C4ParseError instead.
2019-02-17 11:58:03 +01:00
Lukas Werling ee35d256aa Add basic character classes to WildcardMatch() 2019-02-03 19:14:53 +01:00
Nicolas Hake 486619b653 Script: Test SetLength parameter 0 for nil (GH #79)
SetLength didn't check whether its first parameter was valid, and
attempted to dereference a NULL pointer when passed nil.
2019-01-05 19:25:35 +01:00
Nicolas Hake d7ea9acfea C4Property: Don't use operator void* in tests anymore either 2019-01-01 22:20:04 +01:00
Lukas Werling 05e3648495 Travis: Skip TCP bind test because of missing IPv6 support 2018-09-25 20:02:51 +02:00
Nicolas Hake 4c43ebf58c Warn when using variables outside of their block
When we introduce block scoping, using variables declared in a more
narrow scope from a block with wider scope will fail. Warn about
these so people can avoid it and fix their code.
2018-07-23 12:12:23 +02:00
Nicolas Hake 81dff1b92a Disable suspicious_assigment warning in for conditions
While I do not agree with the idea of using straight assignments in
the condition of a for loop, people are divided on the argument and
lots of old code uses it.
2018-07-23 08:29:46 +02:00
Nicolas Hake 704994f1b9 Remove warning on assignment in while() conditions (for now) 2018-04-04 21:42:24 +02:00
Nicolas Hake c73b8b3ece Warn on assignments where an expression is expected
This introduces a new diagnostic (suspicious_assignment) which
issues when an the compiler finds an assignment either where a
condition is expected or as the parameter to return.
2018-03-27 08:12:21 +02:00
Lukas Werling ee34ac1b06 Add C4NetIOTCP::Bind() for binding without connect 2018-03-07 17:30:58 +01:00
Julius Michaelis 24cf662cbd Rust script to iterate over all scenarios with openclonk-server and look for script errors 2018-01-12 23:15:29 +01:00
Nicolas Hake b87f8e3f47 C4Script: Add ParseInt function
ParseInt() will take a string parameter and try to convert it into an
integer. If the conversion fails, it returns nil.
2017-04-11 14:21:25 +02:00
Nicolas Hake 1ee3081de2 Add tests for StdMeshQuaternion 2017-04-10 19:13:04 +02:00
Nicolas Hake 4d33df9dfe Add tests for StdMeshVector 2017-04-10 19:13:04 +02:00
Nicolas Hake 379c5a5746 Tests: Add missing C4Include reference to UnicodeHandlingTest
All of our headers are designed to be included *after* C4Include.h,
which UnicodeHandlingTest.cpp didn't do, resulting in an ill-formed
program on some implementations.
2017-03-19 11:28:51 +01:00
Lukas Werling 9b61ba468d Fix JSON serialization of proplists within arrays 2017-03-18 00:26:58 +01:00
Nicolas Hake ca62ee82bf Test invalid_escape_sequence, invalid_hex_escape, arg_count_mismatch 2017-03-16 18:51:16 +01:00
Lukas Werling 3ebedd0c5f Rank private/UL addresses lower than global ones
Also adds some tests. Yay tests!
2017-02-28 22:15:29 +01:00
Nicolas Hake 144451783d Get random stuff test to build again
TestHost can't check that SourceScripts is unmodified anymore because
C4ScriptHost contains a std::unique_ptr these days, so we can't copy
derived classes. Next best thing is just creating two instances of
TestHost and comparing those.
2017-02-21 20:39:02 +01:00
Lukas Werling 61bcdeba46 Remove separate c4value_test
Those test cases are included in the main "tests" binary as well.
2017-02-21 19:25:21 +01:00
Julius Michaelis 5f1ad6a5d7 Travis: fancy stuff
- gtest
 - colors
 - container based builds and GCC PCH (for a faster: "you failed")
2017-02-21 17:13:18 +01:00
Nicolas Hake 76b9d68126 C4ValueTest: Use custom formatter instead of a custom macro
We can just make GTest use a custom formatter to write a value to the
console instead of using a custom macro to wrap everything in a
std::string.
2017-02-19 18:40:19 +01:00
Nicolas Hake bbf9e1ee50 C4Value tests: Work around MSVC 2015 preprocessor bug
MSVC 2015 doesn't support raw strings that contain the sequence \"
(U+005C REVERSE SOLIDUS, U+0022 QUOTATION MARK) and fails to compile
with error C2017.
2017-02-19 18:38:39 +01:00
Lukas Werling fc418a219e Fix use-after-free in C4ValueTest 2017-02-19 18:29:34 +01:00
Lukas Werling ee0b1c2599 Implement JSON serialization for C4Value 2017-02-17 23:29:01 +01:00
Lukas Werling a44bd69b2f Fix find_path for GMock on Arch Linux
The path is /usr/src/gmock/gmock-all.cc there.
2017-02-17 20:21:47 +01:00
Nicolas Hake 5006a7409e Aul tests: Increment subtest counter per script execution
GTest usually only increments its part count per EXPECT_* call, which we
don't use in diagnostics tests, so all compilation failures would show
as part number 0.
2017-02-16 19:32:47 +01:00
Nicolas Hake 15f5eefc3f Diagnostics tests: Pull common code into a macro
Instead of declaring an error handler every time we run a subtest, we'll
just use a class member that we clear when we leave the scope of the
subtest.
The macro is a bit ugly but solves the issue with redeclaring the scope
guard.
2017-02-16 19:32:46 +01:00
Nicolas Hake c07e0768d6 Aul tests: Split DiagnosticsTest.Warnings into individual parts
We'll test every diagnostic we want to issue in a separate test case so
they get grouped more nicely.
2017-02-16 19:32:45 +01:00
Nicolas Hake c67d188d91 Aul tests: Check for warning ID instead of message 2017-02-16 19:32:44 +01:00
Nicolas Hake b4127439ac Tests: Move aul diagnostics test to a separate file 2017-02-16 19:32:43 +01:00
Nicolas Hake 78bbbc917b Fallback to sane settings when compiling scripts without ScriptHost
Compilation without an associated ScriptHost happens in a call to eval,
in which case we'll fall back to the default warning settings (because
we don't have a location which we could get settings from).

Fixes #1891.
2017-02-16 19:32:42 +01:00
Nicolas Hake 1594acd3ed Aul: Warn if a function parameter shadows a local variable
Yeah. Aul looks up function parameters before local variables when
trying to resolve an identifier. Usually this doesn't matter, but you'll
notice it if you have a local variable and a parameter with the same
name, because the variable should be initialized to nil yet you get the
value of the parameter.
2017-02-13 17:20:03 +01:00
Nicolas Hake 1595bf56a5 Aul test: Write correct output for BoolLit 2017-02-13 15:24:17 +01:00
Nicolas Hake 30c5bb5f8d Aul: Allow the user to selectively enable/disable warnings
This commit introduces a new Aul directive "#warning", which can be used
to enable or disable warnings for a particular piece of code.

"#warning enable" enables all warnings.
"#warning disable" disables all warnings.
"#warning enable empty_parameter_in_call" selectively enables one
specific warning while not affecting any other.

All warnings that used to be controlled by Developer.ExtraWarnings
remain disabled by default.
2017-02-13 15:07:50 +01:00
Nicolas Hake a33d98ee71 Aul: Warn on empty controlled statement
Aul will now emit a warning if you type something like
    if (...); return true;
(note the semicolon right after the condition). It will also warn on an
empty 'else' branch. If you actually intended to have a no-op there, use
an empty block '{}'.
2017-02-05 14:17:37 +01:00
Nicolas Hake 60829ae5e4 Aul: Don't let exceptions escape from constant resolver
Letting the constant resolver throw exceptions prevented us from doing
checking on later initializers anyway, so instead we'll send them to the
error handler. As a special bonus this makes it so we don't crash when
a global variable initializer has errors. Fixes #1850, #1855.
2016-11-30 13:37:33 +01:00
Nicolas Hake eda6cc9c7f Aul: Gracefully handle errors in codegen (#1840)
By continuing to generate bytecode even after an error is found, we're
able to find more syntax errors and will also be able to keep the value
stack at the expected height.
2016-11-13 11:07:21 +01:00
Nicolas Hake e2fd7095c1 Merge branch 'ast'
# Conflicts:
#	src/C4Include.h
#	src/script/C4AulCompiler.cpp
#	src/script/C4AulParse.cpp
#	src/script/C4AulParse.h
#	src/script/C4ScriptHost.cpp
#	src/script/C4ScriptHost.h
#	tests/CMakeLists.txt
2016-10-20 17:33:02 +02:00
Nicolas Hake 266feeda4d Aul: Add AST generation tests
Just making sure the parser creates the AST the way we expect before we
hand off the code to the codegen.
2016-10-20 17:20:55 +02:00
Nicolas Hake 5f3dbdd417 Reject function expressions inside proplists inside functions
These aren't supported by the codegen on account of not working in
savegames.
2016-10-19 14:20:45 +02:00
Nicolas Hake 9caaf1e298 Aul: Split out error handling into a separate class for easier testing
By using an extern error handler in the script engine, we can mock that
handler and make sure something that should fail actually does, instead
of having to parse log messages.
2016-10-19 14:20:41 +02:00
Nicolas Hake ab1e6bd5a4 Allow proplist-local funcs to access vars of their owner's prototype
Thanks to JCaesar for providing this test case.
2016-10-19 13:45:35 +02:00
Nicolas Hake 46f342dd0c Tests: Split test helper functions into Expr/Code/Script evaluators
RunExpr will evaluate and return the value of a single expression.
RunCode will evaluate a full function body.
RunScript will compile a complete standalone script and return the
return value of its Main() function.
2016-10-19 13:45:11 +02:00
Nicolas Hake 49a98e54a5 Add test for 57a35bf fix
So it turns out that the fix stops the engine from crashing, but it
still doesn't seem to generate valid code - Aul emits an internal error
at runtime.
2016-06-05 13:36:32 +02:00
Nicolas Hake 092a23c2f7 Aul: Parse scripts into an AST, then generate bytecode from that
This commit contains a fairly substantial rewrite of the C4Script code
generator. Instead of generating bytecode while parsing the script,
we're now parsing the script into a syntax tree, and have any further
processing happen on that instead of the raw source.

At this time, the code generator emits the same bytecode as the old
parser; there are several optimization opportunities that arise from the
new possibility to emit code out of order from its specification by the
author.

Compared to the old compiler, this one is still rather deficient when
dealing with incorrect code; it's also not emitting several warnings
that used to be diagnosed.
2016-05-12 19:43:48 +02:00
Nicolas Hake f2bf34ff3e Add missing semicolons to CreateEffect tests 2016-05-09 12:33:56 +02:00
Günther Brammer b00b8554ab Merge branch script 2016-04-28 03:25:44 +02:00
Günther Brammer d8e8d25ab4 Aul tests: CreateEffect 2016-04-28 02:59:11 +02:00