Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cpp/examples/ExampleFunctions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ add_test(ExampleFunctions call_with_optional_string)
add_test(ExampleFunctions pass_by_reference_dict)
add_test(ExampleFunctions pass_by_reference_vector)
add_test(ExampleFunctions throws_error)
add_test(ExampleFunctions returns_noisy_int)
20 changes: 20 additions & 0 deletions cpp/examples/ExampleFunctions/returns_noisy_int.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2020 Lawrence Livermore National Security, LLC and other CLIPPy
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: MIT

#include <clippy/clippy.hpp>

int main(int argc, char **argv) {
clippy::clippy clip("returns_noisy_int",
"Tests returning a int with some extraneous stdout");
clip.returns<size_t>("The Int");
if (clip.parse(argc, argv)) {
return 0;
}

std::cout << "Here's some noise\n";
std::cout << "More noise!\n";
clip.to_return(size_t(42));
return 0;
}
8 changes: 7 additions & 1 deletion py/src/clippy/backends/fs/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import select
import subprocess
import sys

from ... import cfg
from ...clippy_types import AnyDict
Expand Down Expand Up @@ -99,7 +100,12 @@ def _stream_exec(
stdout_buffer += text
while "\n" in stdout_buffer:
line, stdout_buffer = stdout_buffer.split("\n", 1)
d = json.loads(line, object_hook=decode_clippy_json)
try:
d = json.loads(line, object_hook=decode_clippy_json)
except json.JSONDecodeError:
warning = f"Warning: invalid JSON on stdout: {line!r}"
stderr_lines.append(warning + "\n")
print(warning, file=sys.stderr, flush=True)
elif fd == stderr_fd:
stderr_buffer += text
while "\n" in stderr_buffer:
Expand Down
9 changes: 9 additions & 0 deletions test/test_clippy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
clippy.logger.setLevel(logging.WARN)
logging.getLogger().setLevel(logging.WARN)

@pytest.fixture()
def examplefn():
return clippy.ExampleFunctions()

@pytest.fixture()
def examplebag():
Expand Down Expand Up @@ -206,3 +209,9 @@ def test_graph(examplegraph):
examplegraph.degree(examplegraph.node.degree)
c_e_only = examplegraph.dump2(examplegraph.node.degree, where=examplegraph.node.degree > 2)
assert "c" in c_e_only and "e" in c_e_only and len(c_e_only) == 2


def test_noise(examplefn, capsys):
assert examplefn.returns_noisy_int() == 42
captured = capsys.readouterr()
assert "Warning: invalid JSON on stdout" in captured.err
Loading