Skip to content

Commit

Permalink
Updating test
Browse files Browse the repository at this point in the history
remove jq
  • Loading branch information
chiragramani committed Aug 9, 2023
1 parent 29540aa commit 73bce66
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
* An output formatter that outputs a protocol buffer json representation of a query result and
* outputs the json to the output print stream.
* An output formatter that prints a list of targets according to ndjson spec to the output print stream.
*/
public class StreamedJSONProtoOutputFormatter extends ProtoOutputFormatter {
@Override
Expand Down
34 changes: 28 additions & 6 deletions src/test/shell/integration/bazel_query_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1108,17 +1108,39 @@ genrule(
outs = ["bar_out.txt"],
cmd = "echo unused > $(OUTS)",
)
genrule(
name = "foo",
srcs = ["dummy.txt"],
outs = ["foo_out.txt"],
cmd = "echo unused > $(OUTS)",
)
EOF
bazel query --output=streamed_jsonproto --noimplicit_deps "//$pkg:bar" > output 2> "$TEST_log" \
bazel query --output=streamed_jsonproto --noimplicit_deps "//$pkg/..." > output 2> "$TEST_log" \
|| fail "Expected success"
cat output >> "$TEST_log"

# Verify that the appropriate attributes were included.
assert_contains "\"ruleClass\":\"genrule\"" output
assert_contains "\"name\":\"//$pkg:bar\"" output
assert_contains "\"ruleInput\":\[\"//$pkg:dummy.txt\"\]" output
assert_contains "\"ruleOutput\":\[\"//$pkg:bar_out.txt\"\]" output
assert_contains "echo unused" output

foo_line_number=$(grep -n "foo" output | cut -d':' -f1)
bar_line_number=$(grep -n "bar" output | cut -d':' -f1)

foo_ndjson_line=$(sed -n "${foo_line_number}p" output)
bar_ndjson_line=$(sed -n "${bar_line_number}p" output)

echo "$foo_ndjson_line" > foo_ndjson_file
echo "$bar_ndjson_line" > bar_ndjson_file

assert_contains "\"ruleClass\":\"genrule\"" foo_ndjson_file
assert_contains "\"name\":\"//$pkg:foo\"" foo_ndjson_file
assert_contains "\"ruleInput\":\[\"//$pkg:dummy.txt\"\]" foo_ndjson_file
assert_contains "\"ruleOutput\":\[\"//$pkg:foo_out.txt\"\]" foo_ndjson_file
assert_contains "echo unused" foo_ndjson_file

assert_contains "\"ruleClass\":\"genrule\"" bar_ndjson_file
assert_contains "\"name\":\"//$pkg:bar\"" bar_ndjson_file
assert_contains "\"ruleInput\":\[\"//$pkg:dummy.txt\"\]" bar_ndjson_file
assert_contains "\"ruleOutput\":\[\"//$pkg:bar_out.txt\"\]" bar_ndjson_file
assert_contains "echo unused" bar_ndjson_file
}

run_suite "${PRODUCT_NAME} query tests"

0 comments on commit 73bce66

Please sign in to comment.