-
Notifications
You must be signed in to change notification settings - Fork 179
Feature: Macros handling to mbed test
#835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Pass macros only to `mbed-os/tools/test.py` and not to mbedgt to enable workflow where `mbed test ... -D SOME_MACRO` will both compile with the macro and also run mbed greentea without `no such option: -D` error. Add macro `MBED_TEST_MODE` to `mbed test` to allow the main application to exclude the main() using the macro. See https://github.com/ARMmbed/pelion-ready-example/blob/master/main.cpp#L18
def get_macros(self): | ||
macros = [] | ||
def get_macros(self, more_macros=False): | ||
macros = more_macros or [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EDIT: oh dear, this is a bad idea, please ignore. Thanks @theotherjimmy
nitpick/simplification: You can simplify this block by altering the function:
def get_macros(self, macros=[]):
This allows you to remove this line
macros = more_macros or [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bridadan please don't suggest this. https://docs.python-guide.org/writing/gotchas/#mutable-default-arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, please change False
to None
, as it's the pythonic "value is missing" value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes, thanks for the heads up. I learned something today.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bridadan see Jimmy's comment and also the extra commit. I had it before the way you suggested :)
mbed/mbed.py
Outdated
macros = [] | ||
def get_macros(self, more_macros=False): | ||
macros = more_macros or [] | ||
# backwards compatibility with old MACROS.txt file | ||
if os.path.isfile('MACROS.txt'): | ||
with open('MACROS.txt') as f: | ||
macros = f.read().splitlines() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to add to the macros that could be found in MACROS.txt
file, then you'd want something like this:
macros = f.read().splitlines() | |
macros.extend(f.read().splitlines()) |
Otherwise the supplied macros from the function arguments will be dropped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I'll change it later.
app_config=None, test_config=None, coverage=None, make_program=None, | ||
new=None, generator=None, regex=None, unittests=None, | ||
build_data=None, greentea=None, icetea=None): | ||
def test_(toolchain=None, target=None, macro=False, compile_list=False, run_list=False, compile_only=False, run_only=False, tests_by_name=None, source=False, profile=False, build=False, clean=False, test_spec=None, app_config=None, test_config=None, coverage=None, make_program=None, new=None, generator=None, regex=None, unittests=None, build_data=None, greentea=None, icetea=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def test_(toolchain=None, target=None, macro=False, compile_list=False, run_list=False, compile_only=False, run_only=False, tests_by_name=None, source=False, profile=False, build=False, clean=False, test_spec=None, app_config=None, test_config=None, coverage=None, make_program=None, new=None, generator=None, regex=None, unittests=None, build_data=None, greentea=None, icetea=None): | |
def test_(toolchain=None, target=None, macro=False, compile_list=False, | |
run_list=False, compile_only=False, run_only=False, tests_by_name=None, | |
source=False, profile=False, build=False, clean=False, test_spec=None, | |
app_config=None, test_config=None, coverage=None, | |
make_program=None, new=None, generator=None, regex=None, | |
unittests=None, build_data=None, greentea=None, icetea=None): |
Co-Authored-By: screamerbg <[email protected]>
@screamerbg Do you have time to make the suggested changes? would you like me to help make them? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs the update to the MACROS.txt I mentioned.
Otherwise the supplied macros from the function arguments will be dropped.
This PR introduces 3 related features:
mbed test
mbed-os/tools/test.py
and not tombedgt
to enable workflow wherembed test ... -D SOME_MACRO
will both compile the tests with the macro and also run mbed greentea without getting theno such option: -D
error.MBED_TEST_MODE
tombed test
to allow the main application to excludemain()
. See https://github.com/ARMmbed/pelion-ready-example/blob/master/main.cpp#L18