diff --git a/README.md b/README.md index 828c5aeea..33d471e09 100644 --- a/README.md +++ b/README.md @@ -1217,6 +1217,7 @@ will follow a redirection only for the second entry. | --path-as-is | Tell Hurl to not handle sequences of /../ or /./ in the given URL path. Normally Hurl will squash or merge them according to standards but with this option set you tell it not to do that.
| | -x, --proxy <[PROTOCOL://]HOST[:PORT]> | Use the specified proxy.
| | --report-html <DIR> | Generate HTML report in DIR.

If the HTML report already exists, it will be updated with the new test results.

This is a cli-only option.
| +| --report-json <DIR> | Generate JSON report in DIR.

If the JSON report already exists, it will be updated with the new test results.

This is a cli-only option.
| | --report-junit <FILE> | Generate JUnit File.

If the FILE report already exists, it will be updated with the new test results.

This is a cli-only option.
| | --report-tap <FILE> | Generate TAP report.

If the FILE report already exists, it will be updated with the new test results.

This is a cli-only option.
| | --resolve <HOST:PORT:ADDR> | Provide a custom address for a specific host and port pair. Using this, you can make the Hurl requests(s) use a specified address and prevent the otherwise normally resolved address to be used. Consider it a sort of /etc/hosts alternative provided on the command line.
| diff --git a/completions/_hurl b/completions/_hurl index 4f962f175..0b136647a 100644 --- a/completions/_hurl +++ b/completions/_hurl @@ -60,6 +60,7 @@ _hurl() { '--path-as-is[Tell Hurl to not handle sequences of /../ or /./ in the given URL path]' \ '(-x --proxy)'{-x,--proxy}'[Use proxy on given PROTOCOL/HOST/PORT]: :' \ '--report-html[Generate HTML report to DIR]: :' \ + '--report-json[Generate JSON report to DIR]: :' \ '--report-junit[Write a JUnit XML report to FILE]: :_files' \ '--report-tap[Write a TAP report to FILE]: :_files' \ '*--resolve[Provide a custom address for a specific HOST and PORT pair]: :' \ diff --git a/completions/_hurl.ps1 b/completions/_hurl.ps1 index dc5b68842..754a4a031 100644 --- a/completions/_hurl.ps1 +++ b/completions/_hurl.ps1 @@ -65,6 +65,7 @@ Register-ArgumentCompleter -Native -CommandName 'hurl' -ScriptBlock { [CompletionResult]::new('--path-as-is', 'path-as-is', [CompletionResultType]::ParameterName, 'Tell Hurl to not handle sequences of /../ or /./ in the given URL path') [CompletionResult]::new('--proxy', 'proxy', [CompletionResultType]::ParameterName, 'Use proxy on given PROTOCOL/HOST/PORT') [CompletionResult]::new('--report-html', 'report-html', [CompletionResultType]::ParameterName, 'Generate HTML report to DIR') + [CompletionResult]::new('--report-json', 'report-json', [CompletionResultType]::ParameterName, 'Generate JSON report to DIR') [CompletionResult]::new('--report-junit', 'report-junit', [CompletionResultType]::ParameterName, 'Write a JUnit XML report to FILE') [CompletionResult]::new('--report-tap', 'report-tap', [CompletionResultType]::ParameterName, 'Write a TAP report to FILE') [CompletionResult]::new('--resolve', 'resolve', [CompletionResultType]::ParameterName, 'Provide a custom address for a specific HOST and PORT pair') diff --git a/completions/hurl.bash b/completions/hurl.bash index 36f705302..f68dd54e3 100644 --- a/completions/hurl.bash +++ b/completions/hurl.bash @@ -5,7 +5,7 @@ _hurl() _init_completion || return if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --delay --error-format --fail-at-end --file-root --location --location-trusted --from-entry --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --jobs --json --max-filesize --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --report-html --report-junit --report-tap --resolve --retry --retry-interval --ssl-no-revoke --test --to-entry --unix-socket --user --user-agent --variable --variables-file --verbose --very-verbose --help --version' -- "$cur")) + COMPREPLY=($(compgen -W '--aws-sigv4 --cacert --cert --key --color --compressed --connect-timeout --connect-to --continue-on-error --cookie --cookie-jar --delay --error-format --fail-at-end --file-root --location --location-trusted --from-entry --glob --http1.0 --http1.1 --http2 --http3 --ignore-asserts --include --insecure --interactive --ipv4 --ipv6 --jobs --json --max-filesize --max-redirs --max-time --netrc --netrc-file --netrc-optional --no-color --no-output --noproxy --output --parallel --path-as-is --proxy --report-html --report-json --report-junit --report-tap --resolve --retry --retry-interval --ssl-no-revoke --test --to-entry --unix-socket --user --user-agent --variable --variables-file --verbose --very-verbose --help --version' -- "$cur")) return fi diff --git a/completions/hurl.fish b/completions/hurl.fish index c34fbf47d..055cb8016 100644 --- a/completions/hurl.fish +++ b/completions/hurl.fish @@ -43,6 +43,7 @@ complete -c hurl -l parallel -d '(Experimental) Run files in parallel' complete -c hurl -l path-as-is -d 'Tell Hurl to not handle sequences of /../ or /./ in the given URL path' complete -c hurl -l proxy -d 'Use proxy on given PROTOCOL/HOST/PORT' complete -c hurl -l report-html -d 'Generate HTML report to DIR' +complete -c hurl -l report-json -d 'Generate JSON report to DIR' complete -c hurl -l report-junit -d 'Write a JUnit XML report to FILE' complete -c hurl -l report-tap -d 'Write a TAP report to FILE' complete -c hurl -l resolve -d 'Provide a custom address for a specific HOST and PORT pair' diff --git a/docs/manual.md b/docs/manual.md index 6168fa83f..7e18c4c9f 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -192,6 +192,7 @@ will follow a redirection only for the second entry. | --path-as-is | Tell Hurl to not handle sequences of /../ or /./ in the given URL path. Normally Hurl will squash or merge them according to standards but with this option set you tell it not to do that.
| | -x, --proxy <[PROTOCOL://]HOST[:PORT]> | Use the specified proxy.
| | --report-html <DIR> | Generate HTML report in DIR.

If the HTML report already exists, it will be updated with the new test results.

This is a cli-only option.
| +| --report-json <DIR> | Generate JSON report in DIR.

If the JSON report already exists, it will be updated with the new test results.

This is a cli-only option.
| | --report-junit <FILE> | Generate JUnit File.

If the FILE report already exists, it will be updated with the new test results.

This is a cli-only option.
| | --report-tap <FILE> | Generate TAP report.

If the FILE report already exists, it will be updated with the new test results.

This is a cli-only option.
| | --resolve <HOST:PORT:ADDR> | Provide a custom address for a specific host and port pair. Using this, you can make the Hurl requests(s) use a specified address and prevent the otherwise normally resolved address to be used. Consider it a sort of /etc/hosts alternative provided on the command line.
| diff --git a/docs/manual/hurl.1 b/docs/manual/hurl.1 index ea0f18bab..01bfefe6c 100644 --- a/docs/manual/hurl.1 +++ b/docs/manual/hurl.1 @@ -1,4 +1,4 @@ -.TH hurl 1 "24 Apr 2024" "hurl 5.0.0-SNAPSHOT" " Hurl Manual" +.TH hurl 1 "13 May 2024" "hurl 5.0.0-SNAPSHOT" " Hurl Manual" .SH NAME hurl - run and test HTTP requests. @@ -390,6 +390,14 @@ If the HTML report already exists, it will be updated with the new test results. This is a cli-only option. +.IP "--report-json " + +Generate JSON report in DIR. + +If the JSON report already exists, it will be updated with the new test results. + +This is a cli-only option. + .IP "--report-junit " Generate JUnit File. diff --git a/docs/manual/hurl.md b/docs/manual/hurl.md index 809886091..275a8b177 100644 --- a/docs/manual/hurl.md +++ b/docs/manual/hurl.md @@ -409,6 +409,14 @@ If the HTML report already exists, it will be updated with the new test results. This is a cli-only option. +### --report-json {#report-json} + +Generate JSON report in DIR. + +If the JSON report already exists, it will be updated with the new test results. + +This is a cli-only option. + ### --report-junit {#report-junit} Generate JUnit File. diff --git a/docs/manual/hurlfmt.1 b/docs/manual/hurlfmt.1 index 9eb25b346..d6aa62ee2 100644 --- a/docs/manual/hurlfmt.1 +++ b/docs/manual/hurlfmt.1 @@ -1,4 +1,4 @@ -.TH hurl 1 "24 Apr 2024" "hurl 5.0.0-SNAPSHOT" " Hurl Manual" +.TH hurl 1 "13 May 2024" "hurl 5.0.0-SNAPSHOT" " Hurl Manual" .SH NAME hurlfmt - format Hurl files diff --git a/docs/running-tests.md b/docs/running-tests.md index b3437f30e..8bbc57fc2 100644 --- a/docs/running-tests.md +++ b/docs/running-tests.md @@ -81,6 +81,8 @@ The input Hurl files (HTML version) are also included and are easily accessed fr Hurl HTML file +### JSON Report + ### JUnit Report A JUnit report can be produced by using the [`--report-junit FILE`] option. diff --git a/docs/spec/options/hurl/report_json.option b/docs/spec/options/hurl/report_json.option new file mode 100644 index 000000000..af8a35dfd --- /dev/null +++ b/docs/spec/options/hurl/report_json.option @@ -0,0 +1,9 @@ +name: report_json +long: report-json +value: DIR +help: Generate JSON report to DIR +cli_only: true +--- +Generate JSON report in DIR. + +If the JSON report already exists, it will be updated with the new test results. diff --git a/integration/hurl/tests_ok/help.out.pattern b/integration/hurl/tests_ok/help.out.pattern index 44d78d4f6..ecba7ef89 100644 --- a/integration/hurl/tests_ok/help.out.pattern +++ b/integration/hurl/tests_ok/help.out.pattern @@ -97,6 +97,8 @@ Options: Use proxy on given PROTOCOL/HOST/PORT --report-html Generate HTML report to DIR + --report-json + Generate JSON report to DIR --report-junit Write a JUnit XML report to FILE --report-tap diff --git a/packages/hurl/README.md b/packages/hurl/README.md index 29cd8e70e..d20038c36 100644 --- a/packages/hurl/README.md +++ b/packages/hurl/README.md @@ -1209,6 +1209,7 @@ will follow a redirection only for the second entry. | --path-as-is | Tell Hurl to not handle sequences of /../ or /./ in the given URL path. Normally Hurl will squash or merge them according to standards but with this option set you tell it not to do that.
| | -x, --proxy <[PROTOCOL://]HOST[:PORT]> | Use the specified proxy.
| | --report-html <DIR> | Generate HTML report in DIR.

If the HTML report already exists, it will be updated with the new test results.

This is a cli-only option.
| +| --report-json <DIR> | Generate JSON report in DIR.

If the JSON report already exists, it will be updated with the new test results.

This is a cli-only option.
| | --report-junit <FILE> | Generate JUnit File.

If the FILE report already exists, it will be updated with the new test results.

This is a cli-only option.
| | --report-tap <FILE> | Generate TAP report.

If the FILE report already exists, it will be updated with the new test results.

This is a cli-only option.
| | --resolve <HOST:PORT:ADDR> | Provide a custom address for a specific host and port pair. Using this, you can make the Hurl requests(s) use a specified address and prevent the otherwise normally resolved address to be used. Consider it a sort of /etc/hosts alternative provided on the command line.
| diff --git a/packages/hurl/src/cli/options/commands.rs b/packages/hurl/src/cli/options/commands.rs index f2c72c3f4..06ac915b6 100644 --- a/packages/hurl/src/cli/options/commands.rs +++ b/packages/hurl/src/cli/options/commands.rs @@ -403,6 +403,14 @@ pub fn report_html() -> clap::Arg { .num_args(1) } +pub fn report_json() -> clap::Arg { + clap::Arg::new("report_json") + .long("report-json") + .value_name("DIR") + .help("Generate JSON report to DIR") + .num_args(1) +} + pub fn report_junit() -> clap::Arg { clap::Arg::new("report_junit") .long("report-junit") diff --git a/packages/hurl/src/cli/options/matches.rs b/packages/hurl/src/cli/options/matches.rs index 7372163e6..13dd52cf8 100644 --- a/packages/hurl/src/cli/options/matches.rs +++ b/packages/hurl/src/cli/options/matches.rs @@ -254,6 +254,30 @@ pub fn jobs(arg_matches: &ArgMatches) -> Option { get::(arg_matches, "jobs").map(|m| m as usize) } +pub fn json_report_dir(arg_matches: &ArgMatches) -> Result, CliOptionsError> { + if let Some(dir) = get::(arg_matches, "report_json") { + let path = Path::new(&dir); + if !path.exists() { + match std::fs::create_dir_all(path) { + Err(_) => Err(CliOptionsError::Error(format!( + "JSON dir {} can not be created", + path.display() + ))), + Ok(_) => Ok(Some(path.to_path_buf())), + } + } else if path.is_dir() { + Ok(Some(path.to_path_buf())) + } else { + return Err(CliOptionsError::Error(format!( + "{} is not a valid directory", + path.display() + ))); + } + } else { + Ok(None) + } +} + pub fn netrc(arg_matches: &ArgMatches) -> bool { has_flag(arg_matches, "netrc") } diff --git a/packages/hurl/src/cli/options/mod.rs b/packages/hurl/src/cli/options/mod.rs index 145ae0ae1..9a6dbb8c8 100644 --- a/packages/hurl/src/cli/options/mod.rs +++ b/packages/hurl/src/cli/options/mod.rs @@ -66,6 +66,7 @@ pub struct CliOptions { pub interactive: bool, pub ip_resolve: Option, pub jobs: Option, + pub json_report_dir: Option, pub junit_file: Option, pub max_filesize: Option, pub max_redirect: Option, @@ -206,6 +207,7 @@ pub fn parse() -> Result { .arg(commands::path_as_is()) .arg(commands::proxy()) .arg(commands::report_html()) + .arg(commands::report_json()) .arg(commands::report_junit()) .arg(commands::report_tap()) .arg(commands::resolve()) @@ -265,6 +267,7 @@ fn parse_matches(arg_matches: &ArgMatches) -> Result Result