Don't automatically derive Clone

Also add a place to start doing more unit-style testing.

Fixes #143
This commit is contained in:
Godfrey Chan 2018-06-01 23:55:22 +09:00
parent 32d6a67b11
commit 8f1acbcfb1
13 changed files with 82 additions and 6 deletions

View File

@ -3,7 +3,7 @@ cache:
- '%HOMEDRIVE%%HOMEPATH%\.multirust -> .appveyor.yml'
environment:
EXAMPLES: duration calculator console geometry membership text_transform turbo_blank json_builder
EXAMPLES: unit duration calculator console geometry membership text_transform turbo_blank json_builder
VERBOSE: true
RUST_BACKTRACE: 1
matrix:

View File

@ -21,7 +21,7 @@ cache:
env:
global:
- EXAMPLES="duration calculator console geometry membership text_transform turbo_blank json_builder"
- EXAMPLES="unit duration calculator console geometry membership text_transform turbo_blank json_builder"
- VERBOSE=true
- RUST_BACKTRACE=1
- RUST_VERSION=stable

View File

@ -21,7 +21,7 @@ appveyor = { repository = "tildeio/helix", branch = "master", service = "github"
[workspace]
members = ["examples/calculator", "examples/console", "examples/geometry", "examples/duration", "examples/membership", "examples/text_transform", "examples/turbo_blank", "examples/json_builder"]
members = ["examples/unit", "examples/calculator", "examples/console", "examples/geometry", "examples/duration", "examples/membership", "examples/text_transform", "examples/turbo_blank", "examples/json_builder"]
[dependencies]
libc = "0.2.0"

View File

@ -4,7 +4,7 @@ task :test do
sh "bundle exec rake"
end
examples = ENV["EXAMPLES"] || "duration calculator console geometry membership text_transform turbo_blank json_builder"
examples = ENV["EXAMPLES"] || "unit duration calculator console geometry membership text_transform turbo_blank json_builder"
sh "bash ./examples/runner default #{examples}"
end
@ -15,7 +15,7 @@ task :install do
sh "bundle"
end
examples = ENV["EXAMPLES"] || "duration calculator console geometry membership text_transform turbo_blank json_builder"
examples = ENV["EXAMPLES"] || "unit duration calculator console geometry membership text_transform turbo_blank json_builder"
sh "bash ./examples/runner install #{examples}"
end

3
examples/unit/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
target
*.bundle
*.gem

11
examples/unit/Cargo.toml Normal file
View File

@ -0,0 +1,11 @@
[package]
name = "unit"
version = "0.1.0"
authors = ["Godfrey Chan <godfrey@tilde.io>"]
[lib]
crate-type = ["cdylib"]
[dependencies.helix]
path = "../.."

5
examples/unit/Gemfile Normal file
View File

@ -0,0 +1,5 @@
source 'https://rubygems.org'
gem 'helix_runtime', path: '../../ruby'
gem 'rake', '~> 10.0'
gem 'rspec', '~> 3.4'

20
examples/unit/Rakefile Executable file
View File

@ -0,0 +1,20 @@
require 'bundler/setup'
require 'helix_runtime/build_task'
require 'rspec/core/rake_task'
require_relative '../shared.rb'
# For Windows
$stdout.sync = true
HelixRuntime::BuildTask.new do |t|
t.build_root = File.expand_path("../..", __dir__)
t.helix_lib_dir = File.expand_path("../../ruby/windows_build", __dir__)
t.pre_build = HelixRuntime::Tests.pre_build
end
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
end
task :spec => :build
task :default => :spec

View File

@ -0,0 +1,2 @@
require 'helix_runtime'
require 'unit/native'

View File

@ -0,0 +1,2 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'unit'

View File

@ -0,0 +1,10 @@
require "spec_helper"
describe ClassContainingNonClonableFields do
it "works" do
c = ClassContainingNonClonableFields.new
expect(c).to be_instance_of(ClassContainingNonClonableFields)
expect(c.to_s).to eq("ClassContainingNonClonableFields")
end
end

23
examples/unit/src/lib.rs Normal file
View File

@ -0,0 +1,23 @@
#![recursion_limit="1024"]
#[macro_use]
extern crate helix;
#[derive(Debug)]
struct NotClonable();
ruby! {
class ClassContainingNonClonableFields {
struct {
inner: NotClonable,
}
def initialize(helix) {
ClassContainingNonClonableFields { helix, inner: NotClonable {} }
}
def to_s(&self) -> &'static str {
"ClassContainingNonClonableFields"
}
}
}

View File

@ -146,7 +146,7 @@ macro_rules! codegen_struct {
ruby_name: $ruby_name:tt,
struct: { $($struct:tt)* }
} => {
#[derive(Clone, Debug)]
#[derive(Debug)]
#[repr(C)]
$($pub)* struct $rust_name {
helix: $crate::Metadata,