Caught by edef's harness. I rewrote the structured build log tests in
f2 and added a test for this one.
Before: it failed the build altogether:
```
building '/tmp/jade/pytest-of-jade/pytest-77/test_invalid_fields_files0_0/nix/store/skhjs5zs082nqiakj69qz32gyywz0v1a-unusual-loggi
ng.drv'...
error: unsupported JSON type 7
```
Now the output is as expected:
```
warning: Unable to handle a JSON message from the derivation builder: error: unsupported log field type number
@nix {"action": "start", "fields": [1.5], "id": 2, "type": 1, "level": 1, "text": "abc"}
```
Change-Id: Idbd28c5a4d4cf15f27207f83b730e7946a6a6964
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import logging
|
|
from testlib.fixtures.file_helper import CopyFile, with_files
|
|
from testlib.fixtures.nix import Nix
|
|
from testlib.utils import get_global_asset
|
|
|
|
|
|
_files = {
|
|
"config.nix": get_global_asset("config.nix"),
|
|
"unusual-logging.nix": CopyFile("assets/test_structured_build_logging/unusual-logging.nix"),
|
|
}
|
|
|
|
_INVALID_LOG_WARNING = "message from the derivation builder: "
|
|
|
|
|
|
@with_files(_files)
|
|
def test_bad_logs(nix: Nix, logger: logging.Logger):
|
|
nix.settings.add_xp_feature("nix-command")
|
|
expected_errors = (
|
|
nix.nix(["eval", "--json", "-f", "unusual-logging.nix", "normalInvalidLogs"])
|
|
.run()
|
|
.ok()
|
|
.json()
|
|
)
|
|
|
|
res = nix.nix_build(["unusual-logging.nix", "-A", "normalInvalid"])
|
|
errs = res.run().stderr_plain
|
|
logger.debug("err: %s", errs)
|
|
assert errs.count(_INVALID_LOG_WARNING) == len(expected_errors)
|
|
|
|
# we expect that the error message contains the offending log line
|
|
for err in expected_errors:
|
|
assert err in errs
|
|
|
|
|
|
@with_files(_files)
|
|
def test_invalid_fields(nix: Nix, logger: logging.Logger):
|
|
nix.settings.add_xp_feature("nix-command")
|
|
expected_error = (
|
|
nix.nix(["eval", "--json", "-f", "unusual-logging.nix", "invalidFieldsLog"])
|
|
.run()
|
|
.ok()
|
|
.json()
|
|
)
|
|
|
|
res = nix.nix_build(["unusual-logging.nix", "-A", "invalidFields"])
|
|
errs = res.run().stderr_plain
|
|
logger.debug("err: %s", errs)
|
|
assert _INVALID_LOG_WARNING in errs
|
|
assert expected_error in errs
|