Skip to content

Commit 408e41a

Browse files
authored
Merge pull request #51 from Hywan/doc-inline-ruby
test+doc: Doctests are now tested via `rustdoc`
2 parents 58e09c6 + 66ac819 commit 408e41a

File tree

13 files changed

+526
-165
lines changed

13 files changed

+526
-165
lines changed

.github/workflows/test.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ jobs:
4747
override: true
4848
target: ${{ matrix.target.target-name }}
4949

50-
- uses: Swatinem/rust-cache@v1
51-
5250
- name: Set up Ruby ${{ matrix.ruby }}
5351
uses: ruby/setup-ruby@v1
5452
with:
@@ -68,9 +66,8 @@ jobs:
6866
gem install bundler
6967
just build
7068
71-
- name: Run all the tests
69+
- name: Run the tests
7270
shell: bash
7371
run: |
7472
export PATH="$HOME/.cargo/bin:$PATH"
75-
export GEM_HOME="$HOME/.gem"
7673
just test

Cargo.lock

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
members = [
33
"crates/rutie-derive",
44
"crates/rutie-derive-macros",
5+
"crates/rutie-test",
56
"crates/wasmer",
67
]

Rakefile

+2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ end
99

1010
desc 'Install the bundle'
1111
task :bundle_install do
12+
sh 'bundle config set --local path "vendor/bundle"'
1213
sh 'bundle install'
14+
sh 'cd vendor/bundle && ln -f -s ruby/*/gems/rutie-*/ rutie'
1315
end
1416

1517
Rake::TestTask.new(test: [:bundle_install, :build_lib]) do |t|

crates/rutie-test/Cargo.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "rutie-test"
3+
version = "0.1.0"
4+
authors = ["Wasmer Engineering Team <[email protected]>"]
5+
edition = "2018"
6+
description = "Helpers to test code written with `rutie`."
7+
readme = "README.md"
8+
repository = "https://github.com/wasmerio/wasmer-ruby"
9+
keywords = ["ruby", "extension"]
10+
publish = false

crates/rutie-test/src/lib.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#[macro_export]
2+
macro_rules! test_ruby {
3+
($code:expr) => {
4+
use rutie::VM;
5+
6+
let code = format!(
7+
r#"
8+
root = File.expand_path("../..", ENV["CARGO_MANIFEST_DIR"])
9+
10+
Dir.chdir(root)
11+
12+
class RbConfig
13+
CONFIG = {{
14+
"host_os" => ENV["TARGET"]
15+
}}
16+
end
17+
18+
$LOAD_PATH.unshift(File.expand_path("lib", root))
19+
$LOAD_PATH.unshift(File.expand_path("vendor/bundle/rutie/lib", root))
20+
21+
require "wasmer"
22+
23+
class AssertionError < RuntimeError
24+
end
25+
26+
def assert &block
27+
raise AssertionError unless yield
28+
end
29+
30+
{code}
31+
"#,
32+
code = $code
33+
);
34+
35+
VM::init();
36+
VM::init_loadpath();
37+
38+
match VM::eval(&code) {
39+
Ok(value) => assert!(true),
40+
Err(err) => panic!("{:?}", err),
41+
}
42+
};
43+
}
44+
45+
pub fn foo() {}

crates/wasmer/Cargo.toml

+6-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ categories = ["wasm"]
1111
publish = false
1212

1313
[lib]
14-
name = "wasmer"
15-
crate-type = ["dylib"]
14+
name = "wasmer_ruby"
15+
crate-type = ["dylib", "rlib"]
1616

1717
[dependencies]
1818
wasmer = "1.0"
@@ -21,4 +21,7 @@ rutie = "0.8"
2121
rutie-derive = { path = "../rutie-derive", version = "0.1.0" }
2222
lazy_static = "1.4"
2323
wat = "1.0"
24-
wasmprinter = "0.2"
24+
wasmprinter = "0.2"
25+
26+
[dev-dependencies]
27+
rutie-test = { path = "../rutie-test", version = "0.1.0" }

crates/wasmer/build.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
// To satisfy `rutie-test`'s macros.
3+
println!(
4+
"cargo:rustc-env=TARGET={}",
5+
std::env::var("TARGET").unwrap()
6+
);
7+
}

0 commit comments

Comments
 (0)