Merge pull request #2348 from rtfeldman/i/2329

Make sure line offsets are generated properly for external programs
This commit is contained in:
Joshua Warner 2022-01-13 18:50:46 -08:00 committed by GitHub
commit ab8b70aacd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 3 deletions

View file

@ -6,12 +6,16 @@ extern crate roc_collections;
extern crate roc_load; extern crate roc_load;
extern crate roc_module; extern crate roc_module;
#[macro_use]
extern crate indoc;
#[cfg(test)] #[cfg(test)]
mod cli_run { mod cli_run {
use cli_utils::helpers::{ use cli_utils::helpers::{
example_file, examples_dir, extract_valgrind_errors, fixture_file, run_cmd, run_roc, example_file, examples_dir, extract_valgrind_errors, fixture_file, known_bad_file, run_cmd,
run_with_valgrind, ValgrindError, ValgrindErrorXWhat, run_roc, run_with_valgrind, ValgrindError, ValgrindErrorXWhat,
}; };
use roc_test_utils::assert_multiline_str_eq;
use serial_test::serial; use serial_test::serial;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
@ -44,6 +48,27 @@ mod cli_run {
use_valgrind: bool, 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( fn check_output_with_stdin(
file: &Path, file: &Path,
stdin: &[&str], stdin: &[&str],
@ -740,6 +765,32 @@ mod cli_run {
true, 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)] #[allow(dead_code)]

View 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"

View file

@ -0,0 +1 @@
../../../examples/cli/platform

View file

@ -294,6 +294,19 @@ pub fn fixture_file(dir_name: &str, file_name: &str) -> PathBuf {
path 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)] #[allow(dead_code)]
pub fn repl_eval(input: &str) -> Out { pub fn repl_eval(input: &str) -> Out {
let mut cmd = Command::new(path_to_roc_binary()); let mut cmd = Command::new(path_to_roc_binary());

View file

@ -82,7 +82,7 @@ fn report_problems_help(
src_lines.extend(src.split('\n')); src_lines.extend(src.split('\n'));
} }
let lines = LineInfo::new(src); let lines = LineInfo::new(&src_lines.join("\n"));
// Report parsing and canonicalization problems // Report parsing and canonicalization problems
let alloc = RocDocAllocator::new(&src_lines, *home, interns); let alloc = RocDocAllocator::new(&src_lines, *home, interns);