mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
Merge pull request #2348 from rtfeldman/i/2329
Make sure line offsets are generated properly for external programs
This commit is contained in:
commit
ab8b70aacd
5 changed files with 79 additions and 3 deletions
|
@ -6,12 +6,16 @@ extern crate roc_collections;
|
|||
extern crate roc_load;
|
||||
extern crate roc_module;
|
||||
|
||||
#[macro_use]
|
||||
extern crate indoc;
|
||||
|
||||
#[cfg(test)]
|
||||
mod cli_run {
|
||||
use cli_utils::helpers::{
|
||||
example_file, examples_dir, extract_valgrind_errors, fixture_file, run_cmd, run_roc,
|
||||
run_with_valgrind, ValgrindError, ValgrindErrorXWhat,
|
||||
example_file, examples_dir, extract_valgrind_errors, fixture_file, known_bad_file, run_cmd,
|
||||
run_roc, run_with_valgrind, ValgrindError, ValgrindErrorXWhat,
|
||||
};
|
||||
use roc_test_utils::assert_multiline_str_eq;
|
||||
use serial_test::serial;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
|
@ -44,6 +48,27 @@ mod cli_run {
|
|||
use_valgrind: bool,
|
||||
}
|
||||
|
||||
fn strip_colors(str: &str) -> String {
|
||||
use roc_reporting::report::*;
|
||||
str.replace(RED_CODE, "")
|
||||
.replace(WHITE_CODE, "")
|
||||
.replace(BLUE_CODE, "")
|
||||
.replace(YELLOW_CODE, "")
|
||||
.replace(GREEN_CODE, "")
|
||||
.replace(CYAN_CODE, "")
|
||||
.replace(MAGENTA_CODE, "")
|
||||
.replace(RESET_CODE, "")
|
||||
.replace(BOLD_CODE, "")
|
||||
.replace(UNDERLINE_CODE, "")
|
||||
}
|
||||
|
||||
fn check_compile_error(file: &Path, flags: &[&str], expected: &str) {
|
||||
let compile_out = run_roc(&[&["check", file.to_str().unwrap()], &flags[..]].concat());
|
||||
let err = compile_out.stdout.trim();
|
||||
let err = strip_colors(&err);
|
||||
assert_multiline_str_eq!(err, expected.into());
|
||||
}
|
||||
|
||||
fn check_output_with_stdin(
|
||||
file: &Path,
|
||||
stdin: &[&str],
|
||||
|
@ -740,6 +765,32 @@ mod cli_run {
|
|||
true,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn known_type_error() {
|
||||
check_compile_error(
|
||||
&known_bad_file("TypeError.roc"),
|
||||
&[],
|
||||
indoc!(
|
||||
r#"
|
||||
── UNRECOGNIZED NAME ───────────────────────────────────────────────────────────
|
||||
|
||||
I cannot find a `d` value
|
||||
|
||||
10│ _ <- await (line d)
|
||||
^
|
||||
|
||||
Did you mean one of these?
|
||||
|
||||
U8
|
||||
Ok
|
||||
I8
|
||||
F64
|
||||
|
||||
────────────────────────────────────────────────────────────────────────────────"#
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
|
|
11
cli/tests/known_bad/TypeError.roc
Normal file
11
cli/tests/known_bad/TypeError.roc
Normal file
|
@ -0,0 +1,11 @@
|
|||
app "type-error"
|
||||
packages { pf: "platform" }
|
||||
imports [ pf.Stdout.{ line }, pf.Task.{ await } ]
|
||||
provides [ main ] to pf
|
||||
|
||||
main =
|
||||
_ <- await (line "a")
|
||||
_ <- await (line "b")
|
||||
_ <- await (line "c")
|
||||
_ <- await (line d)
|
||||
line "e"
|
1
cli/tests/known_bad/platform
Symbolic link
1
cli/tests/known_bad/platform
Symbolic link
|
@ -0,0 +1 @@
|
|||
../../../examples/cli/platform
|
|
@ -294,6 +294,19 @@ pub fn fixture_file(dir_name: &str, file_name: &str) -> PathBuf {
|
|||
path
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn known_bad_file(file_name: &str) -> PathBuf {
|
||||
let mut path = root_dir();
|
||||
|
||||
// Descend into cli/tests/known_bad/{file_name}
|
||||
path.push("cli");
|
||||
path.push("tests");
|
||||
path.push("known_bad");
|
||||
path.push(file_name);
|
||||
|
||||
path
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn repl_eval(input: &str) -> Out {
|
||||
let mut cmd = Command::new(path_to_roc_binary());
|
||||
|
|
|
@ -82,7 +82,7 @@ fn report_problems_help(
|
|||
src_lines.extend(src.split('\n'));
|
||||
}
|
||||
|
||||
let lines = LineInfo::new(src);
|
||||
let lines = LineInfo::new(&src_lines.join("\n"));
|
||||
|
||||
// Report parsing and canonicalization problems
|
||||
let alloc = RocDocAllocator::new(&src_lines, *home, interns);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue