mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 15:27:45 +03:00
Reproduce some multi-dep bugs
This commit is contained in:
parent
1f183769c4
commit
244486eba6
@ -12,7 +12,7 @@ mod helpers;
|
||||
#[cfg(test)]
|
||||
mod cli_run {
|
||||
use crate::helpers::{
|
||||
example_file, extract_valgrind_errors, run_cmd, run_roc, run_with_valgrind,
|
||||
example_file, extract_valgrind_errors, fixture_file, run_cmd, run_roc, run_with_valgrind,
|
||||
};
|
||||
use serial_test::serial;
|
||||
use std::path::Path;
|
||||
@ -161,4 +161,60 @@ mod cli_run {
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial(multi_dep_str)]
|
||||
fn run_multi_dep_str() {
|
||||
if true {
|
||||
todo!(
|
||||
"fix this test so it no longer deadlocks and hangs during monomorphization! The test never shows the error; to see the panic error, run this: cargo run run cli/tests/fixtures/multi-dep-str/Main.roc"
|
||||
);
|
||||
}
|
||||
|
||||
check_output(
|
||||
&fixture_file("multi-dep-str", "Main.roc"),
|
||||
&[],
|
||||
"I am Dep2.str2\n",
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial(multi_dep_str)]
|
||||
fn run_multi_dep_str_optimized() {
|
||||
if true {
|
||||
todo!(
|
||||
"fix this test so it no longer deadlocks and hangs during monomorphization! The test never shows the error; to see the panic error, run this: cargo run run cli/tests/fixtures/multi-dep-str/Main.roc"
|
||||
);
|
||||
}
|
||||
|
||||
check_output(
|
||||
&fixture_file("multi-dep-str", "Main.roc"),
|
||||
&[],
|
||||
"I am Dep2.str2\n",
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial(multi_dep_thunk)]
|
||||
fn run_multi_dep_thunk() {
|
||||
check_output(
|
||||
&fixture_file("multi-dep-thunk", "Main.roc"),
|
||||
&[],
|
||||
"I am Dep2.value2\n",
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial(multi_dep_str)]
|
||||
fn run_multi_dep_thunk_optimized() {
|
||||
check_output(
|
||||
&fixture_file("multi-dep-thunk", "Main.roc"),
|
||||
&[],
|
||||
"I am Dep2.value2\n",
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
4
cli/tests/fixtures/.gitignore
vendored
Normal file
4
cli/tests/fixtures/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
app
|
||||
host.o
|
||||
c_host.o
|
||||
app.dSYM
|
4
cli/tests/fixtures/multi-dep-str/Dep1.roc
vendored
Normal file
4
cli/tests/fixtures/multi-dep-str/Dep1.roc
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
interface Dep1 exposes [ str1 ] imports [ Dep2 ]
|
||||
|
||||
str1 : Str
|
||||
str1 = Dep2.str2 {}
|
4
cli/tests/fixtures/multi-dep-str/Dep2.roc
vendored
Normal file
4
cli/tests/fixtures/multi-dep-str/Dep2.roc
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
interface Dep2 exposes [ str2 ] imports []
|
||||
|
||||
str2 : Str
|
||||
str2 = "I am Dep2.str2"
|
4
cli/tests/fixtures/multi-dep-str/Main.roc
vendored
Normal file
4
cli/tests/fixtures/multi-dep-str/Main.roc
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
app Main provides [ main ] imports [ Dep1 ]
|
||||
|
||||
main : Str
|
||||
main = Dep1.str1
|
23
cli/tests/fixtures/multi-dep-str/platform/Cargo.lock
generated
vendored
Normal file
23
cli/tests/fixtures/multi-dep-str/platform/Cargo.lock
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "host"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"roc_std 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "roc_std"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"libc 0.2.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum libc 0.2.79 (registry+https://github.com/rust-lang/crates.io-index)" = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
|
13
cli/tests/fixtures/multi-dep-str/platform/Cargo.toml
vendored
Normal file
13
cli/tests/fixtures/multi-dep-str/platform/Cargo.toml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "host"
|
||||
version = "0.1.0"
|
||||
authors = ["Richard Feldman <oss@rtfeldman.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
roc_std = { path = "../../../roc_std" }
|
||||
|
||||
[workspace]
|
8
cli/tests/fixtures/multi-dep-str/platform/README.md
vendored
Normal file
8
cli/tests/fixtures/multi-dep-str/platform/README.md
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Rebuilding the host from source
|
||||
|
||||
Run `build.sh` to manually rebuild this platform's host.
|
||||
|
||||
Note that the compiler currently has its own logic for rebuilding these hosts
|
||||
(in `link.rs`). It's hardcoded for now, but the long-term goal is that
|
||||
hosts will be precompiled by platform authors and distributed in packages,
|
||||
at which point only package authors will need to think about rebuilding hosts.
|
12
cli/tests/fixtures/multi-dep-str/platform/build.sh
vendored
Executable file
12
cli/tests/fixtures/multi-dep-str/platform/build.sh
vendored
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
# compile c_host.o and rust_host.o
|
||||
clang -c host.c -o c_host.o
|
||||
rustc host.rs -o rust_host.o
|
||||
|
||||
# link them together into host.o
|
||||
ld -r c_host.o rust_host.o -o host.o
|
||||
|
||||
# clean up
|
||||
rm -f c_host.o
|
||||
rm -f rust_host.o
|
7
cli/tests/fixtures/multi-dep-str/platform/host.c
vendored
Normal file
7
cli/tests/fixtures/multi-dep-str/platform/host.c
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
extern int rust_main();
|
||||
|
||||
int main() {
|
||||
return rust_main();
|
||||
}
|
18
cli/tests/fixtures/multi-dep-str/platform/src/lib.rs
vendored
Normal file
18
cli/tests/fixtures/multi-dep-str/platform/src/lib.rs
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
use roc_std::RocStr;
|
||||
use std::str;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "main_1"]
|
||||
fn main() -> RocStr;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn rust_main() -> isize {
|
||||
println!(
|
||||
"Roc says: {}",
|
||||
str::from_utf8(unsafe { main().as_slice() }).unwrap()
|
||||
);
|
||||
|
||||
// Exit code
|
||||
0
|
||||
}
|
4
cli/tests/fixtures/multi-dep-thunk/Dep1.roc
vendored
Normal file
4
cli/tests/fixtures/multi-dep-thunk/Dep1.roc
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
interface Dep1 exposes [ value1 ] imports [ Dep2 ]
|
||||
|
||||
value1 : {} -> Str
|
||||
value1 = \_ -> Dep2.value2 {}
|
4
cli/tests/fixtures/multi-dep-thunk/Dep2.roc
vendored
Normal file
4
cli/tests/fixtures/multi-dep-thunk/Dep2.roc
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
interface Dep2 exposes [ value2 ] imports []
|
||||
|
||||
value2 : {} -> Str
|
||||
value2 = \_ -> "I am Dep2.value2"
|
4
cli/tests/fixtures/multi-dep-thunk/Main.roc
vendored
Normal file
4
cli/tests/fixtures/multi-dep-thunk/Main.roc
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
app Main provides [ main ] imports [ Dep1 ]
|
||||
|
||||
main : Str
|
||||
main = Dep1.value1 {}
|
23
cli/tests/fixtures/multi-dep-thunk/platform/Cargo.lock
generated
vendored
Normal file
23
cli/tests/fixtures/multi-dep-thunk/platform/Cargo.lock
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "host"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"roc_std 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.79"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "roc_std"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"libc 0.2.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum libc 0.2.79 (registry+https://github.com/rust-lang/crates.io-index)" = "2448f6066e80e3bfc792e9c98bf705b4b0fc6e8ef5b43e5889aff0eaa9c58743"
|
13
cli/tests/fixtures/multi-dep-thunk/platform/Cargo.toml
vendored
Normal file
13
cli/tests/fixtures/multi-dep-thunk/platform/Cargo.toml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "host"
|
||||
version = "0.1.0"
|
||||
authors = ["Richard Feldman <oss@rtfeldman.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
roc_std = { path = "../../../roc_std" }
|
||||
|
||||
[workspace]
|
8
cli/tests/fixtures/multi-dep-thunk/platform/README.md
vendored
Normal file
8
cli/tests/fixtures/multi-dep-thunk/platform/README.md
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
# Rebuilding the host from source
|
||||
|
||||
Run `build.sh` to manually rebuild this platform's host.
|
||||
|
||||
Note that the compiler currently has its own logic for rebuilding these hosts
|
||||
(in `link.rs`). It's hardcoded for now, but the long-term goal is that
|
||||
hosts will be precompiled by platform authors and distributed in packages,
|
||||
at which point only package authors will need to think about rebuilding hosts.
|
12
cli/tests/fixtures/multi-dep-thunk/platform/build.sh
vendored
Executable file
12
cli/tests/fixtures/multi-dep-thunk/platform/build.sh
vendored
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
# compile c_host.o and rust_host.o
|
||||
clang -c host.c -o c_host.o
|
||||
rustc host.rs -o rust_host.o
|
||||
|
||||
# link them together into host.o
|
||||
ld -r c_host.o rust_host.o -o host.o
|
||||
|
||||
# clean up
|
||||
rm -f c_host.o
|
||||
rm -f rust_host.o
|
7
cli/tests/fixtures/multi-dep-thunk/platform/host.c
vendored
Normal file
7
cli/tests/fixtures/multi-dep-thunk/platform/host.c
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
extern int rust_main();
|
||||
|
||||
int main() {
|
||||
return rust_main();
|
||||
}
|
18
cli/tests/fixtures/multi-dep-thunk/platform/src/lib.rs
vendored
Normal file
18
cli/tests/fixtures/multi-dep-thunk/platform/src/lib.rs
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
use roc_std::RocStr;
|
||||
use std::str;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "main_1"]
|
||||
fn main() -> RocStr;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn rust_main() -> isize {
|
||||
println!(
|
||||
"Roc says: {}",
|
||||
str::from_utf8(unsafe { main().as_slice() }).unwrap()
|
||||
);
|
||||
|
||||
// Exit code
|
||||
0
|
||||
}
|
@ -207,6 +207,40 @@ pub fn example_file(dir_name: &str, file_name: &str) -> PathBuf {
|
||||
path
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn fixtures_dir(dir_name: &str) -> PathBuf {
|
||||
let mut path = env::current_exe().ok().unwrap();
|
||||
|
||||
// Get rid of the filename in target/debug/deps/cli_run-99c65e4e9a1fbd06
|
||||
path.pop();
|
||||
|
||||
// If we're in deps/ get rid of deps/ in target/debug/deps/
|
||||
if path.ends_with("deps") {
|
||||
path.pop();
|
||||
}
|
||||
|
||||
// Get rid of target/debug/ so we're back at the project root
|
||||
path.pop();
|
||||
path.pop();
|
||||
|
||||
// Descend into cli/tests/fixtures/{dir_name}
|
||||
path.push("cli");
|
||||
path.push("tests");
|
||||
path.push("fixtures");
|
||||
path.push(dir_name);
|
||||
|
||||
path
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn fixture_file(dir_name: &str, file_name: &str) -> PathBuf {
|
||||
let mut path = fixtures_dir(dir_name);
|
||||
|
||||
path.push(file_name);
|
||||
|
||||
path
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn repl_eval(input: &str) -> Out {
|
||||
let mut cmd = Command::new(path_to_roc_binary());
|
||||
|
Loading…
Reference in New Issue
Block a user