Skip to content

lib/tinytest: fix result not printed on newline #5414

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

Closed
wants to merge 2 commits into from

Conversation

dlech
Copy link
Contributor

@dlech dlech commented Dec 12, 2019

When a test prints output during a test, it does so by adding a newline to the beginning of the line, rather than the end. So we need to do the same when printing the final result of the test, otherwise it ends up being appended to the end of the last message, which makes it hard to read.

Fixes: f4ed2df

@dpgeorge
Copy link
Member

When a test prints output during a test, it does so by adding a newline to the beginning of the line, rather than the end.

Do you have a pointer to the code that does this? I don't see any problem with the output as it currently is. Eg excerpt from build/console.out in qemu-arm test run:

...
# starting inlineasm/asmsum.py
array('l', [100, 200, 300, 400]) 1000
array('b', [10, 20, 30, 40, 50, 60, 70, 80]) 360
b'\x01\x02\x03\x04' 10
inlineasm/asmsum.py: OK
# starting qemu-arm/native_test.py
2       
3       
4   
qemu-arm/native_test.py: OK
614 tests ok.  (82 skipped)
status: 0

@dlech
Copy link
Contributor Author

dlech commented Dec 16, 2019

I've been using MicroPython's copy of tinytest with custom code that is integrated with MicroPython.

Since MicroPython tests use printf with trailing newlines instead of tinytest macros, the problem probably isn't really a problem with anything currently in MicroPython itself. So, this change will probably cause an empty line before qemu-arm/native_test.py: OK in the existing MicroPython test output, but it will fix the regression (caused by the commit I linked above) for general usage of tinytest.

@dpgeorge
Copy link
Member

So, this change will probably cause an empty line before qemu-arm/native_test.py: OK in the existing MicroPython test output,

Hmm, that might make it mildly confusing because it will group the result of one test (this OK line) with the output of the next test (the following lines which are not separated by a blank line).

but it will fix the regression (caused by the commit I linked above) for general usage of tinytest.

How did the output look for "normal use" of tinytest before that commit?

@dlech
Copy link
Contributor Author

dlech commented Dec 16, 2019

Example code:

#include <tinytest.h>
#include <tinytest_macros.h>

static void test1(void *env) {
    tt_fail_msg("didn't work");
}

static struct testcase_t example_tests[] = {
    { "test1", test1, 0,  NULL, NULL },
    END_OF_TESTCASES
};

static struct testgroup_t test_groups[] = {
    { "example/", example_tests },
    END_OF_GROUPS
};

int main(int argc, const char **argv) {
    return tinytest_main(argc, argv, test_groups);
}

Output before f4ed2df:

example/test1: 
  FAIL test.c:5: didn't work
  [test1 FAILED]
1/1 TESTS FAILED. (0 skipped)

Output after f4ed2df:

# starting example/test1

  FAIL test-pbio.c:5: didn't workexample/test1: FAILED
1/1 TESTS FAILED. (0 skipped)

Output with this PR:

# starting example/test1

  FAIL test-pbio.c:227: didn't work
example/test1: FAILED
1/1 TESTS FAILED. (0 skipped)

I think the fact that it always mentions the test name (e.g. example/test1) in the message would prevent any confusion by having an extra blank line. But if it is really a concern, we could further modify tinytest to use newlines at the end instead of the beginning everywhere.

@dpgeorge
Copy link
Member

Ok, thanks for the further info.

One option would be to revert the changes made in f4ed2df to keep tinytest as-is (and work as it was originally designed), then modify the MicroPython-tinytest interface code to just print out a bit of extra info, eg:

--- a/tools/tinytest-codegen.py
+++ b/tools/tinytest-codegen.py
@@ -33,8 +33,10 @@ test_function = (
     "void {name}(void* data) {{\n"
     "  static const char pystr[] = {script};\n"
     "  static const char exp[] = {output};\n"
+    '  printf("\\n");\n'
     "  upytest_set_expected_output(exp, sizeof(exp) - 1);\n"
     "  upytest_execute_test(pystr);\n"
+    '  printf("result: ");\n'
     "}}"
 )

…ut output."

This reverts commit f4ed2df.

An alternate solution will be implemented in a future commit.
This is an alternative to f4ed2df that adds a newline so that the
output of the test starts on a new line and the result of the test
is prefixed with "result: " to distinguish it from the test output.

Suggested-by: @dpgeorge
@dlech
Copy link
Contributor Author

dlech commented Dec 18, 2019

I have update the PR with your suggestion. The effects of the changes on console.out can be seen below. The andor.py test was manually rigged to fail so that we could both possible outcomes for a test.

I tested locally with the qemu-arm port and tests pass. Also, this should not break grep "FAIL" ports/qemu-arm/build/console.out in .travis.py.

Current:

# starting basics/array1.py
array('B', [1, 2, 3]) 3
array('I', [1, 2, 3]) 3
1
3
1 -1
2
True
0
array('i')
False
True
False
False
ValueError
basics/array1.py: OK
# starting basics/andor.py
1
(1,)
()
1
basics/andor.py: FAILED

Proposed:

basics/array1.py: 
array('B', [1, 2, 3]) 3
array('I', [1, 2, 3]) 3
1
3
1 -1
2
True
0
array('i')
False
True
False
False
ValueError
result: OK
basics/andor.py: 
1
(1,)
()
1
result: 
  [basics/andor.py FAILED]

@dpgeorge
Copy link
Member

Thanks for updating and for the tests. Looks good now. Merged in fd0ba7b

@dpgeorge dpgeorge closed this Dec 19, 2019
@dlech dlech deleted the patch-3 branch December 19, 2019 16:22
tannewt added a commit to tannewt/circuitpython that referenced this pull request Aug 4, 2022
This replaces supervisor.enable_autoreload() and
supervisor.disable_autoreload(). It also allows user code to get
the current autoreload state.

Replaces micropython#5352 and part of micropython#5414
tannewt added a commit to tannewt/circuitpython that referenced this pull request Aug 4, 2022
This replaces supervisor.enable_autoreload() and
supervisor.disable_autoreload(). It also allows user code to get
the current autoreload state.

Replaces micropython#5352 and part of micropython#5414
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants