This commit is contained in:
damirka 2021-08-04 23:34:11 +03:00
parent ad6e27000d
commit eb0863cda9
51 changed files with 293 additions and 10 deletions

View File

@ -66,8 +66,9 @@ fn hash(input: String) -> String {
pub(crate) fn parse_program(
program_string: &str,
theorem_options: Option<AstSnapshotOptions>,
cwd: Option<PathBuf>,
) -> Result<EdwardsTestCompiler, CompilerError> {
let mut compiler = new_compiler("compiler-test".into(), theorem_options);
let mut compiler = new_compiler(cwd.unwrap_or("compiler-test".into()), theorem_options);
compiler.parse_program_from_string(program_string)?;
@ -101,15 +102,12 @@ impl Namespace for CompileNamespace {
// ``` cwd: import ```
// When set, uses different working directory for current file.
// If not, uses file path as current working directory.
// let cwd = test
// .config
// .get("cwd")
// .map(|val| {
// let mut cwd = test.path.clone();
// cwd.pop();
// cwd.join(&val.as_str().unwrap())
// })
// .unwrap_or(test.path.clone());
let cwd = test.config.get("cwd").map(|val| {
let mut cwd = test.path.clone();
cwd.pop();
cwd.join(&val.as_str().unwrap())
});
// .unwrap_or(test.path.clone());
let parsed = parse_program(
&test.content,
@ -118,6 +116,7 @@ impl Namespace for CompileNamespace {
canonicalized: true,
type_inferenced: true,
}),
cwd,
)
.map_err(|x| x.to_string())?;

View File

@ -0,0 +1,3 @@
[main]
[registers]

View File

@ -0,0 +1,9 @@
circuit Cave {
function name() -> [char; 4] {
return "cave";
}
}
function main() {
}

View File

@ -0,0 +1,6 @@
[main]
y: bool = true;
n: bool = false;
[registers]
r0: bool = true;

View File

@ -0,0 +1,8 @@
Tests in this folder test external dependencies that were imported. To mock that we
need to have structure similar to typical Leo package: source files must be in the
directory next to `imports/`; but instead of `src/` we have `tests/` here.
Option `cwd` param in these tests must point to the `tests/`, so having it as `.`
should be enough.
Have fun testing!

View File

@ -0,0 +1,12 @@
/*
namespace: Compile
expectation: Pass
input_file: ../input/dummy.in
cwd: .
*/
import dependency.*;
function main(y: bool) -> bool {
return y == (Cave::name() == "cave");
}

View File

@ -0,0 +1,14 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
cwd: local_imports
*/
import circuits.*;
function main(y: bool) -> bool {
const a = Point { x: 1u32, y: 0u32 };
return (foo() == 1u32) == y;
}

View File

@ -0,0 +1,12 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
cwd: local_imports
*/
import lib.say_hello as howdy;
function main(y: bool) -> bool {
return y == (howdy() == "hello");
}

View File

@ -0,0 +1,12 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
cwd: local_imports
*/
import nested.hello.say_hello;
function main(y: bool) -> bool {
return y == (say_hello() == "hello");
}

View File

@ -0,0 +1,12 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
cwd: local_imports
*/
import lib.say_hello;
function main(y: bool) -> bool {
return y == (say_hello() == "hello");
}

View File

@ -0,0 +1,17 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
cwd: local_imports
*/
import circuits.(
Point,
foo
);
function main(y: bool) -> bool {
const a = Point { x: 1u32, y: 0u32 };
return (foo() == 1u32) == y;
}

View File

@ -0,0 +1,12 @@
/*
namespace: Compile
expectation: Pass
input_file: input/dummy.in
cwd: local_imports
*/
import a-9.*;
function main(y: bool) -> bool {
return y == true;
}

View File

@ -0,0 +1,6 @@
[main]
y: bool = true;
n: bool = false;
[registers]
r0: bool = true;

View File

@ -0,0 +1,8 @@
circuit Point {
x: u32
y: u32
}
function foo() -> u32 {
return 1u32;
}

View File

@ -0,0 +1,3 @@
function say_hello() -> [char; 5] {
return "hello";
}

View File

@ -0,0 +1,3 @@
function say_hello() -> [char; 5] {
return "hello";
}

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: "../input/dummy.in"
output:
registers:
r0:
type: bool
value: "true"
initial_ast: d6273a716c2546b210eeefb640b5c34830fb2b2a4195ae0b636843e855fcbc1e
canonicalized_ast: 41a3c4ffe7c243ffc76bc7d3c147f77f71119d64e632581a20eb1cd576752ac3
type_inferenced_ast: 196e5191c3d8c8cc552b419422b3e1411fa576336f63ae9d5c340bf2a7d62942

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 1a78fdc95fad861e53d1b0463228701df726fa0bf5092bd94d1d35f57c8c2a94
canonicalized_ast: 1a78fdc95fad861e53d1b0463228701df726fa0bf5092bd94d1d35f57c8c2a94
type_inferenced_ast: be1c8166ce3ae7f805d8600441996328ce8f45ada3c16c4284f07d07af52ef75

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 47ef8cd0b57a42612bc9138c6da6e05fbca27c47464acf5af569c2fe0c91dd31
canonicalized_ast: 39c0b27ba63cc34eed735900912e154031ca1f291aade9d9964ce49e77eeb19e
type_inferenced_ast: 19bfc761f899b48a3e0c4142bac6cbdaceac8230e92422cf9f6a99d9f7eddc6f

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 7e0ba7b09b3840a5d4fc9f0d413163ba2de8f207c3818f604f9a71297aac30f3
canonicalized_ast: 3f7efb61847fd75fed58b70526da8ceffb573a0806521fb30443f341c3d14a45
type_inferenced_ast: a1baf614c8ab13c1ff978faf8022f90eef4c482261928cb3256ab4d63e20096c

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 042e056c86e545ce256459a0de20d44c0bae24ff406becba4330e3208c48e180
canonicalized_ast: 6cab1ab863f40c96d5d6921e2ced0dd00ebe5e9e334d84508af708be19ae8f59
type_inferenced_ast: 17ff3e62f1c48edfbfb1c35ed4ac542260b59153d85afeca2e707dde217dc675

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: ad1dd786c43b4d3de69b6e162bed3f01a0a53f0643e6fd2d95f12c98dfa16855
canonicalized_ast: ad1dd786c43b4d3de69b6e162bed3f01a0a53f0643e6fd2d95f12c98dfa16855
type_inferenced_ast: 1c983cf518cfafbe158ee3e42aed5cb190863b09aedfc4dd34e0268160ee79e2

View File

@ -0,0 +1,21 @@
---
namespace: Compile
expectation: Pass
outputs:
- circuit:
num_public_variables: 0
num_private_variables: 1
num_constraints: 1
at: 042610d0fd1fe6d6ac112138f8755752f44c7d2a00f1b5960574d6da5cda393f
bt: e97756698880ab7555a959a5fb5c6b4e15bd64612aa677adbfe2d0bd91f0a83c
ct: cf1cbb66a638b4860a516671fb74850e6ccf787fe6c4c8d29e9c04efe880bd05
output:
- input_file: input/dummy.in
output:
registers:
r0:
type: bool
value: "true"
initial_ast: 6a099d784f82bb8065c8efdd2b4018089d968a7f57cbab3406df3ec5d0612410
canonicalized_ast: 6a099d784f82bb8065c8efdd2b4018089d968a7f57cbab3406df3ec5d0612410
type_inferenced_ast: 58541200a815edfee41333b9b2b048add269d0924ca17457ecf9fbcbb5032ccf