Merged
Conversation
Closed
Contributor
Author
|
Thanks again @niknetniko for the detailed and good feedback. Although it took me another week it greatly improved my code. Biggest changes:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pr adds c++ to TESTed.
It is compiled using
gcc 10.2.1. The current version supports allc++ 17features and somec++ 20features.Convention choices:
I have chosen to prefer
stdtypes over standardctypes. So even though you could write validc++without using anystdtypes, this won't work well with our judge as we try to follow best practices.I used the string key
cppinstead ofc++. Both are commonly used, but the first is less likely to cause issues of being parsed incorrectly.Heterogeneous collections are supported using
std::variant.Value arguments to a function are always cast to their type. This is done because not all types are well defined by how a value is written, and if the student uses templates for arguments this can cause compiler issues, without any type info present.
Limitations
TESTed cannot differentiate between applying functions on
objects,pointersandclassesornamespaces.As all three have their own operator in
c++(.,->and::respectively), I could not generate code that works in all cases. For this reason I made the following choices:.operator)::. This is the only case where::is generated.->is never generated)Custom oracles written in
c++require either an object with methods if the filename is camelCase or a a class with static methods if the filename is PascalCase. Simple methods are not supported as TESTed always provides the filename of the oracle as namespace to the generator.Typing statements isn't always easy and heavily reliant on the values. For some statements I simply do not have enough information to provide a type. Eg.
foo: list = bar()andfoo = [bar()]will both generate a variablefooof typestd::vector<std::any>.As all type information is lost on elements of type
std::anythese are hard to use for students and almost impossible to properly convert to json values for me. As type hinting is currently limited in TESTed, it would probably be best to use language specific statements in these cases.Unrelated changes
I forgot to run half the tests for
cppas the language had to manually be specified for every test.I have refactored this so most tests use predefined language sets from
tests/language_markers.py.These tests are now defined with a new helper function
all_languages_except. This way, a new language is automatically tested on all tests, but it remains easy to exclude it from certain test if you decide this test shouldn't work for the given language.Observations
Adding a language to TESTed requires three main parts:
config.pywith a class inheriting from the default language classgenerators.pywhich translates the internal TESTed format into a testfile in the desired languagetemplatesfolder containing language specific helper functions to convert return values and errors to thejsonformat expected by testedExtending the
config.pyis properly done using inheretance. Filling out the required methods, which are also mostly documented.The
generators.pyis badly organized. There seems to be some kind of method naming convention, as allgenerators.pyfiles seem to be largely copied from each other.This results in lots of duplicate code. Because there is no clear API to implement, it is also not always clear which cases should be implemented. This part was the hardest part to write, but is mostly skimmed over in the documentation.
I think this part of the code could really benefit with some types of abstraction, such as an abstract class with methods to implement. Maybe with some different abstract subclasses for
typedanduntypedlanguages, which could also reduce code duplication. This issue could be solved with visitors as specified in #564The
templatesfolder was not really documented either. It took me a while to figure out what the files actually did. These files are technically not required by TESTed, but helpers for the code generated ingenerators.py. But we seem to use this for every language. So some form of specification/standardization would be helpful.This was also hard to implement for me in
c++, but that is just because my knowledge ofc++wasn't good enough to properly write type generics.To end with a more positive observation: The test catch a lot of edge cases. While it was a frustrating experience to keep fixing bugs to get each test passing, it is very clear that the test have heavily improved my initial implementation.
Closes #530