Skip to content

Commit

Permalink
Use output option source line for output error
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricereix authored and hurl-bot committed May 24, 2024
1 parent a90f30f commit cf449fd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
8 changes: 5 additions & 3 deletions integration/hurl/tests_failed/output_unauthorized.err
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
error: Unauthorized file access
--> tests_failed/output_unauthorized.hurl:1:1
--> tests_failed/output_unauthorized.hurl:4:9
|
1 | GET http://localhost:8000/hello
| ^ unauthorized access to file ../build/output1, check --file-root option
| GET http://localhost:8000/hello
| ...
4 | output: ../build/output2
| ^^^^^^^^^^^^^^^^ unauthorized access to file ../build/output2, check --file-root option
|

1 change: 1 addition & 0 deletions integration/hurl/tests_failed/output_unauthorized.hurl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
GET http://localhost:8000/hello
[Options]
output: ../build/output1
output: ../build/output2

8 changes: 5 additions & 3 deletions integration/hurl/tests_failed/runner_errors.err.pattern
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ error: File read access
|

error: File write access
--> tests_failed/runner_errors.hurl:38:1
--> tests_failed/runner_errors.hurl:40:9
|
38 | GET http://localhost:8000/runner_errors
| ^ tests_failed~undefined~output can not be written (~~~)
| GET http://localhost:8000/runner_errors
| ...
40 | output: undefined/output
| ^^^^^^^^^^^^^^^^ tests_failed~undefined~output can not be written (~~~)
|

error: Filter error
Expand Down
8 changes: 5 additions & 3 deletions integration/hurl/tests_failed/runner_errors_color.err.pattern
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@
 |

error: File write access
--> tests_failed/runner_errors.hurl:38:1
--> tests_failed/runner_errors.hurl:40:9
 |
 38 | GET http://localhost:8000/runner_errors
 | ^ tests_failed~undefined~output can not be written (~~~)
 | GET http://localhost:8000/runner_errors
 | ...
 40 | output: undefined/output
 | ^^^^^^^^^^^^^^^^ tests_failed~undefined~output can not be written (~~~)
 |

error: Filter error
Expand Down
17 changes: 15 additions & 2 deletions packages/hurl/src/runner/hurl_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ use std::time::Instant;

use chrono::Utc;
use hurl_core::ast::VersionValue::VersionAnyLegacy;
use hurl_core::ast::{Body, Bytes, Entry, MultilineString, Request, Response, Retry};
use hurl_core::ast::{
Body, Bytes, Entry, MultilineString, OptionKind, Request, Response, Retry, SourceInfo,
};
use hurl_core::error::DisplaySourceError;
use hurl_core::parser;

Expand Down Expand Up @@ -271,7 +273,7 @@ pub fn run_entries(
}) = options
{
if !has_error {
let source_info = entry.source_info();
let source_info = get_output_source_info(entry);
if let Err(error) = entry_result.write_response(
&output,
&runner_options.context_dir,
Expand Down Expand Up @@ -330,6 +332,17 @@ pub fn run_entries(
}
}

/// Use source_info from output option if this option has been defined
fn get_output_source_info(entry: &Entry) -> SourceInfo {
let mut source_info = entry.source_info();
for option_entry in entry.request.options() {
if let OptionKind::Output(value) = option_entry.kind {
source_info = value.source_info;
}
}
source_info
}

/// Returns `true` if all the entries results are successful, `false` otherwise.
///
/// For a given list of entry results, only the last one on the same index is checked.
Expand Down

0 comments on commit cf449fd

Please sign in to comment.