Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCaml tools: add output selection for --machine-readable
Add an optional argument for --machine-readable to select the output, adding a new function to specifically write data to that output stream. The possible choices are: * --machine-readable: to stdout, like before * --machine-readable=file:name-of-file: to the specified file * --machine-readable=stream:stdout: explicitly to stdout * --machine-readable=stream:stderr: explicitly to stderr Adapt all the OCaml-based tools to use the new function, so the --machine-readable choice is respected.
- Loading branch information
Showing
25 changed files
with
351 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(* | ||
* Copyright (C) 2018 Red Hat Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*) | ||
|
||
(* Test the --machine-readable functionality of the module Tools_utils. | ||
* The tests are controlled by the test-machine_readable.sh script. | ||
*) | ||
|
||
open Printf | ||
|
||
open Std_utils | ||
open Tools_utils | ||
open Getopt.OptionName | ||
|
||
let usage_msg = sprintf "%s: test the --machine-readable functionality" prog | ||
|
||
let opthandle = create_standard_options [] ~machine_readable:true usage_msg | ||
let () = | ||
Getopt.parse opthandle; | ||
|
||
print_endline "on-stdout"; | ||
prerr_endline "on-stderr"; | ||
|
||
match machine_readable () with | ||
| Some { pr } -> | ||
pr "machine-readable\n" | ||
| None -> () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/bin/bash - | ||
# libguestfs | ||
# Copyright (C) 2018 Red Hat Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
|
||
# Test the --machine-readable functionality of the module Tools_utils. | ||
# See also: machine_readable_tests.ml | ||
|
||
set -e | ||
set -x | ||
|
||
$TEST_FUNCTIONS | ||
skip_if_skipped | ||
|
||
t=./machine_readable_tests | ||
|
||
tmpdir="$(mktemp -d)" | ||
mkdir -p "$tmpdir" | ||
|
||
# Clean up if the script is killed or exits early. | ||
cleanup () | ||
{ | ||
status=$? | ||
rm -rf "$tmpdir" | ||
exit $status | ||
} | ||
trap cleanup INT QUIT TERM EXIT ERR | ||
|
||
# Program works. | ||
$t | ||
|
||
# No machine-readable output. | ||
$t | grep 'machine-readable' && test $? = 1 | ||
test $($t | wc -l) -eq 1 | ||
test $($t |& wc -l) -eq 2 | ||
|
||
# Default output: stdout. | ||
$t --machine-readable | grep 'machine-readable' | ||
test $($t --machine-readable | wc -l) -eq 2 | ||
test $($t --machine-readable |& wc -l) -eq 3 | ||
|
||
# Output "file:". | ||
fn="$tmpdir/file" | ||
$t --machine-readable=file:"$fn" | ||
test $(cat "$fn" | wc -l) -eq 1 | ||
|
||
# Output "stream:stdout". | ||
$t --machine-readable=stream:stdout | grep 'machine-readable' | ||
test $($t --machine-readable=stream:stdout | wc -l) -eq 2 | ||
test $($t --machine-readable=stream:stdout |& wc -l) -eq 3 | ||
|
||
# Output "stream:stderr". | ||
$t --machine-readable=stream:stderr 2>&1 >/dev/null | grep 'machine-readable' | ||
test $($t --machine-readable=stream:stderr 2>&1 >/dev/null | wc -l) -eq 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.