Skip to content
Open
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
## Enso Signatures 1.0
## module Standard.Test.Suite
- type Suite
- Impl groups:(Standard.Base.Data.Vector.Vector Standard.Test.Group.Group)
- group_names self -> Standard.Base.Any.Any
- print_all self -> Standard.Base.Any.Any
- run_with_filter self filter:(Standard.Base.Data.Text.Text|Standard.Base.Nothing.Nothing)= should_exit:Standard.Base.Data.Boolean.Boolean= -> (Standard.Base.Data.Boolean.Boolean|Standard.Base.Nothing.Nothing)
- type Suite_Builder
- Impl builder:Standard.Base.Any.Any
- group self name:Standard.Base.Data.Text.Text fn:Standard.Base.Any.Any pending:(Standard.Base.Data.Text.Text|Standard.Base.Nothing.Nothing)= -> Standard.Base.Any.Any
- group self name:Standard.Base.Data.Text.Text fn:Standard.Base.Any.Any ~pending:(Standard.Base.Data.Text.Text|Standard.Base.Nothing.Nothing)= -> Standard.Base.Any.Any
- name_matches name:Standard.Base.Data.Text.Text filter:(Standard.Base.Data.Text.Text|Standard.Base.Nothing.Nothing) -> Standard.Base.Data.Boolean.Boolean
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## Enso Signatures 1.0
## module Standard.Test.Test_Result
- type Test_Result
- Impl group_name:Standard.Base.Data.Text.Text spec_name:Standard.Base.Data.Text.Text spec_result:Standard.Test.Spec_Result.Spec_Result time_taken:Standard.Base.Data.Time.Duration.Duration
- is_fail self -> Standard.Base.Any.Any
- is_pending self -> Standard.Base.Any.Any
- is_success self -> Standard.Base.Any.Any
Expand Down
8 changes: 2 additions & 6 deletions distribution/lib/Standard/Test/0.0.0-dev/src/Group.enso
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ type Group_Builder
- `code`: A thunk that takes no arguments.
- `pending`: Contains a reason for why the test should be ignored. If
Nothing, the test is not ignored.
specify self (name : Text) (~code : Any) (pending : (Text | Nothing) = Nothing) =
case pending of
Nothing ->
self.builder.append <| Spec.Impl name (_ -> code) pending
pend_reason : Text ->
self.builder.append <| Spec.Impl name (_ -> Nothing) pend_reason
specify self (name : Text) (~code : Any) (~pending : (Text | Nothing) = Nothing) =
self.builder.append <| Spec.Impl name (_ -> code) pending


## Provide a teardown of a group - a method that will be called once all the
Expand Down
2 changes: 1 addition & 1 deletion distribution/lib/Standard/Test/0.0.0-dev/src/Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ private
from Standard.Base import all

type Spec
Impl (name : Text) (code : Any -> Any) (pending : (Nothing | Text))
private Impl (name : Text) (code : Any -> Any) (~pending : (Nothing | Text))

to_text self =
pend = if self.pending.is_nothing then "" else
Expand Down
17 changes: 6 additions & 11 deletions distribution/lib/Standard/Test/0.0.0-dev/src/Suite.enso
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Suite_Builder

## Arguments
- `builder`: Vector builder that holds all the groups.
Impl builder
private Impl builder

## Add a group to the suite builder.

Expand All @@ -31,16 +31,11 @@ type Suite_Builder
- `pending`: Contains a reason for why the test group should be ignored.
If Nothing, the test is not ignored.
group : Text -> (Group_Builder -> Any) -> (Text | Nothing) -> Nothing
group self (name:Text) (fn : (Group_Builder -> Any)) (pending : (Text | Nothing) = Nothing) =
group self (name:Text) (fn : (Group_Builder -> Any)) (~pending : (Text | Nothing) = Nothing) =
group_builder = Group_Builder.Impl name
case pending of
Nothing ->
fn group_builder
group = Group.Impl name group_builder.teardown_ref.get group_builder.builder.to_vector pending
self.builder.append group
pend_reason : Text ->
group = Group.Impl name group_builder.teardown_ref.get [] pend_reason
self.builder.append group
fn group_builder
group = Group.Impl name group_builder.teardown_ref.get group_builder.builder.to_vector (pending...)
self.builder.append group


## A testing suite that holds all the groups with test specs.
Expand All @@ -50,7 +45,7 @@ type Suite
## ---
private: true
---
Impl (groups : Vector Group)
private Impl (groups : Vector Group)

## Run only tests that match the provided filter.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type Test_Result
## ---
private: true
---
Impl (group_name : Text) (spec_name : Text) (spec_result : Spec_Result) (time_taken : Duration)
private Impl (group_name : Text) (spec_name : Text) (spec_result : Spec_Result) (time_taken : Duration)

## ---
private: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Object execute(VirtualFrame frame) {
var state = EnsoContext.get(this).currentState();
var args = Function.ArgumentsHelper.getPositionalArguments(frame.getArguments());
assert args.length == 1;
assert args[0] instanceof Function fn && fn.isThunk();
assert args[0] instanceof Function fn && fn.isFullyApplied();
var raw = evalThunk.executeThunk(frame, args[0], state, BaseNode.TailStatus.NOT_TAIL);
var result = check.handleCheckOrConversion(frame, raw);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final Object findDirectMatch(VirtualFrame frame, Object v) {

@ExplodeLoop
private final Object directMatchImpl(Object v) {
if (v instanceof Function fn && fn.isThunk()) {
if (v instanceof Function fn && fn.isFullyApplied()) {
return fn;
}
assert EnsoContext.get(this).getBuiltins().any() != expectedType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public final Object handleCheckOrConversion(VirtualFrame frame, Object value) {

private final Object handleCheckOrConversionImpl(VirtualFrame frame, Object value) {
var direct = check.findDirectMatch(frame, value);
if (direct instanceof Function fn && fn.isThunk()) {
if (direct instanceof Function fn && fn.isFullyApplied()) {
if (lazyCheck == null) {
CompilerDirectives.transferToInterpreter();
var enso = EnsoLanguage.get(this);
Expand Down
6 changes: 4 additions & 2 deletions test/Base_Tests/src/Network/Http/Http_Auto_Parse_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ add_specs suite_builder =
content_utf = '["x", "Hello! 😊👍 ąę"]'
content_windows_1250 = '["y", "Hello! ąę"]'

url_utf8 = (URI.from base_url_with_slash / "test_headers")
url_utf8 =
(URI.from base_url_with_slash / "test_headers")
. add_query_argument "Content-Type" "text/plain; charset=utf-8"
. add_query_argument "base64_response_data" (Base_64.encode_text content_utf)

url_windows_1250 = (URI.from base_url_with_slash / "test_headers")
url_windows_1250 =
(URI.from base_url_with_slash / "test_headers")
. add_query_argument "Content-Type" "text/plain; charset=windows-1250"
. add_query_argument "base64_response_data" (Base_64.encode_text content_windows_1250 Encoding.windows_1250)

Expand Down
21 changes: 14 additions & 7 deletions test/Base_Tests/src/Network/Http_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ add_specs suite_builder =

url_get = base_url_with_slash.if_not_nothing <| base_url_with_slash + "get"
suite_builder.group "fetch" pending=pending_has_url group_builder->
url_head = base_url_with_slash + "head"
url_options = base_url_with_slash + "options"
url_head =
base_url_with_slash + "head"
url_options =
base_url_with_slash + "options"

group_builder.specify "Can perform a GET with a JSON response" <| Test.with_retries <|
response = Data.fetch url_get
Expand Down Expand Up @@ -240,10 +242,14 @@ add_specs suite_builder =
err.catch.message.should_equal "Data.read cannot be used with a Vector. Please use Data.read_many."

suite_builder.group "post" pending=pending_has_url group_builder->
url_post = base_url_with_slash + "post"
url_put = base_url_with_slash + "put"
url_patch = base_url_with_slash + "patch"
url_delete = base_url_with_slash + "delete"
url_post =
base_url_with_slash + "post"
url_put =
base_url_with_slash + "put"
url_patch =
base_url_with_slash + "patch"
url_delete =
base_url_with_slash + "delete"

group_builder.specify "Can perform a Request_Body.Text POST" <| Test.with_retries <|
response = Data.post url_post (Request_Body.Text "hello world")
Expand Down Expand Up @@ -457,7 +463,8 @@ add_specs suite_builder =
Data.post url_post (Request_Body.Binary test_file) . should_fail_with Request_Error

suite_builder.group "Headers" pending=pending_has_url group_builder->
url_post = base_url_with_slash + "post"
url_post =
base_url_with_slash + "post"

group_builder.specify "Content-type in the body is respected" <| Test.with_retries <|
response = Data.post url_post (Request_Body.Text '{"a": "asdf", "b": 123}' content_type="application/json")
Expand Down
15 changes: 10 additions & 5 deletions test/Cloud_Tests/src/Network/Fetch_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,16 @@ add_specs suite_builder =
fake_reload =
ReloadDetector.simulateReloadTestOnly get_lru_cache

url0 = base_url_with_slash+'test_download?max-age=16&length=10'
url1 = base_url_with_slash+'test_download?max-age=16&length=20'
url_post = base_url_with_slash + "post"
headers0 = [Header.new "A-Header" "a-header-value", Header.new "A-Header" "a-header-value"]
headers1 = [Header.new "A-Header" "a-different-header-value", Header.new "A-Header" "a-header-value"]
url0 =
base_url_with_slash+'test_download?max-age=16&length=10'
url1 =
base_url_with_slash+'test_download?max-age=16&length=20'
url_post =
base_url_with_slash + "post"
headers0 =
[Header.new "A-Header" "a-header-value", Header.new "A-Header" "a-header-value"]
headers1 =
[Header.new "A-Header" "a-different-header-value", Header.new "A-Header" "a-header-value"]

# Run the request(s) twice and confirm the results are the same
check_same_results ~action =
Expand Down
6 changes: 4 additions & 2 deletions test/Cloud_Tests/src/Network/Http/Http_Auto_Parse_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ add_specs suite_builder =
content_utf = '["x", "Hello! 😊👍 ąę"]'
content_windows_1250 = '["y", "Hello! ąę"]'

url_utf8 = (URI.from base_url_with_slash / "test_headers")
url_utf8 =
(URI.from base_url_with_slash / "test_headers")
. add_query_argument "Content-Type" "text/plain; charset=utf-8"
. add_query_argument "base64_response_data" (Base_64.encode_text content_utf)

url_windows_1250 = (URI.from base_url_with_slash / "test_headers")
url_windows_1250 =
(URI.from base_url_with_slash / "test_headers")
. add_query_argument "Content-Type" "text/plain; charset=windows-1250"
. add_query_argument "base64_response_data" (Base_64.encode_text content_windows_1250 Encoding.windows_1250)

Expand Down
21 changes: 14 additions & 7 deletions test/Cloud_Tests/src/Network/Http_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ add_specs suite_builder =

url_get = base_url_with_slash.if_not_nothing <| base_url_with_slash + "get"
suite_builder.group "fetch" pending=pending_has_url group_builder->
url_head = base_url_with_slash + "head"
url_options = base_url_with_slash + "options"
url_head =
base_url_with_slash + "head"
url_options =
base_url_with_slash + "options"

group_builder.specify "Can perform a GET with a JSON response" <| Test.with_retries <|
response = Data.fetch url_get
Expand Down Expand Up @@ -238,10 +240,14 @@ add_specs suite_builder =
err.catch.message.should_equal "Data.read cannot be used with a Vector. Please use Data.read_many."

suite_builder.group "post" pending=pending_has_url group_builder->
url_post = base_url_with_slash + "post"
url_put = base_url_with_slash + "put"
url_patch = base_url_with_slash + "patch"
url_delete = base_url_with_slash + "delete"
url_post =
base_url_with_slash + "post"
url_put =
base_url_with_slash + "put"
url_patch =
base_url_with_slash + "patch"
url_delete =
base_url_with_slash + "delete"

group_builder.specify "Can perform a Request_Body.Text POST" <| Test.with_retries <|
response = Data.post url_post (Request_Body.Text "hello world")
Expand Down Expand Up @@ -455,7 +461,8 @@ add_specs suite_builder =
Data.post url_post (Request_Body.Binary test_file) . should_fail_with Request_Error

suite_builder.group "Headers" pending=pending_has_url group_builder->
url_post = base_url_with_slash + "post"
url_post =
base_url_with_slash + "post"

group_builder.specify "Content-type in the body is respected" <| Test.with_retries <|
response = Data.post url_post (Request_Body.Text '{"a": "asdf", "b": 123}' content_type="application/json")
Expand Down
2 changes: 2 additions & 0 deletions test/Test_Tests/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ from Standard.Base import all
from Standard.Test import Test

import project.Extensions_Spec
import project.Pending_Lazy_Spec

add_specs suite_builder =
Extensions_Spec.add_specs suite_builder
Pending_Lazy_Spec.add_specs suite_builder

main filter=Nothing =
suite = Test.build suite_builder->
Expand Down
54 changes: 54 additions & 0 deletions test/Test_Tests/src/Pending_Lazy_Spec.enso
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from Standard.Base import all
from Standard.Test import all

import Standard.Base.Runtime.Ref.Ref

add_specs suite_builder =
group_pending_counter = Ref.new 0
spec_pending_counter = Ref.new 0
# created here, checked inside of the test specifications
# filled after the specifications are defined
group_pending_snapshot = Ref.new -1
spec_pending_snapshot = Ref.new -1

group_pending_msg =
group_pending_counter.modify (+1)
Nothing

group_pending_yes =
group_pending_counter.modify (+1)
"Never executed"

spec_pending_msg =
spec_pending_counter.modify (+1)
Nothing

spec_pending_yes =
spec_pending_counter.modify (+1)
"Never executed"

suite_builder.group "pending is lazy" pending=group_pending_msg group_builder->
group_builder.specify "group pending is lazy" <|
group_pending_counter.get>0 . should_be_true
group_pending_snapshot.get . should_equal 0

group_builder.specify "spec pending is lazy" pending=spec_pending_msg <|
spec_pending_counter.get>0 . should_be_true
spec_pending_snapshot.get . should_equal 0

group_builder.specify "never executed test" pending=spec_pending_yes <|
Test.fail "This test is always pending"

suite_builder.group "group with pending is ignored" pending=group_pending_yes group_builder->
group_builder.specify "never executed test" <|
Test.fail "Group of this test is always pending"

# these two "snapshots" are recorded _before_ the specifications
# are executed but after the group definition has been processed
group_pending_snapshot.put group_pending_counter.get
spec_pending_snapshot.put spec_pending_counter.get

main filter=Nothing =
suite = Test.build suite_builder->
add_specs suite_builder
suite.run_with_filter filter
Loading