diff --git a/compiler/src/test.rs b/compiler/src/test.rs index 728ee65d4f..d7ccbdedb5 100644 --- a/compiler/src/test.rs +++ b/compiler/src/test.rs @@ -66,8 +66,9 @@ fn hash(input: String) -> String { pub(crate) fn parse_program( program_string: &str, theorem_options: Option, + cwd: Option, ) -> Result { - 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())?; diff --git a/tests/compiler/import_dependency/imports/dependency/inputs/dependency.in b/tests/compiler/import_dependency/imports/dependency/inputs/dependency.in new file mode 100644 index 0000000000..03eacdd3ad --- /dev/null +++ b/tests/compiler/import_dependency/imports/dependency/inputs/dependency.in @@ -0,0 +1,3 @@ +[main] + +[registers] diff --git a/tests/compiler/import_dependency/imports/dependency/src/main.leo b/tests/compiler/import_dependency/imports/dependency/src/main.leo new file mode 100644 index 0000000000..1516361c71 --- /dev/null +++ b/tests/compiler/import_dependency/imports/dependency/src/main.leo @@ -0,0 +1,9 @@ +circuit Cave { + function name() -> [char; 4] { + return "cave"; + } +} + +function main() { + +} diff --git a/tests/compiler/import_dependency/input/dummy.in b/tests/compiler/import_dependency/input/dummy.in new file mode 100644 index 0000000000..5686421617 --- /dev/null +++ b/tests/compiler/import_dependency/input/dummy.in @@ -0,0 +1,6 @@ +[main] +y: bool = true; +n: bool = false; + +[registers] +r0: bool = true; diff --git a/tests/compiler/import_dependency/readme.md b/tests/compiler/import_dependency/readme.md new file mode 100644 index 0000000000..276f8fe3e9 --- /dev/null +++ b/tests/compiler/import_dependency/readme.md @@ -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! diff --git a/tests/compiler/import_dependency/tests/import_dependency_folder.leo b/tests/compiler/import_dependency/tests/import_dependency_folder.leo new file mode 100644 index 0000000000..2b67b4af14 --- /dev/null +++ b/tests/compiler/import_dependency/tests/import_dependency_folder.leo @@ -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"); +} diff --git a/tests/compiler/import_local/import_all.leo b/tests/compiler/import_local/import_all.leo new file mode 100644 index 0000000000..4ede4f3f38 --- /dev/null +++ b/tests/compiler/import_local/import_all.leo @@ -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; +} diff --git a/tests/compiler/import_local/import_as.leo b/tests/compiler/import_local/import_as.leo new file mode 100644 index 0000000000..36629594f9 --- /dev/null +++ b/tests/compiler/import_local/import_as.leo @@ -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"); +} diff --git a/tests/compiler/import_local/import_dir.leo b/tests/compiler/import_local/import_dir.leo new file mode 100644 index 0000000000..229b4a90e9 --- /dev/null +++ b/tests/compiler/import_local/import_dir.leo @@ -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"); +} diff --git a/tests/compiler/import_local/import_files.leo b/tests/compiler/import_local/import_files.leo new file mode 100644 index 0000000000..05c1b68a97 --- /dev/null +++ b/tests/compiler/import_local/import_files.leo @@ -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"); +} diff --git a/tests/compiler/import_local/import_many.leo b/tests/compiler/import_local/import_many.leo new file mode 100644 index 0000000000..139deea8d2 --- /dev/null +++ b/tests/compiler/import_local/import_many.leo @@ -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; +} diff --git a/tests/compiler/import_local/import_weird_names.leo b/tests/compiler/import_local/import_weird_names.leo new file mode 100644 index 0000000000..2a2e169d7f --- /dev/null +++ b/tests/compiler/import_local/import_weird_names.leo @@ -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; +} diff --git a/tests/compiler/import_local/input/dummy.in b/tests/compiler/import_local/input/dummy.in new file mode 100644 index 0000000000..5686421617 --- /dev/null +++ b/tests/compiler/import_local/input/dummy.in @@ -0,0 +1,6 @@ +[main] +y: bool = true; +n: bool = false; + +[registers] +r0: bool = true; diff --git a/tests/compiler/import_local/local_imports/a-9.leo b/tests/compiler/import_local/local_imports/a-9.leo new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/compiler/import_local/local_imports/circuits.leo b/tests/compiler/import_local/local_imports/circuits.leo new file mode 100644 index 0000000000..f24226a9fd --- /dev/null +++ b/tests/compiler/import_local/local_imports/circuits.leo @@ -0,0 +1,8 @@ +circuit Point { + x: u32 + y: u32 +} + +function foo() -> u32 { + return 1u32; +} diff --git a/tests/compiler/import_local/local_imports/lib.leo b/tests/compiler/import_local/local_imports/lib.leo new file mode 100644 index 0000000000..a32e24032a --- /dev/null +++ b/tests/compiler/import_local/local_imports/lib.leo @@ -0,0 +1,3 @@ +function say_hello() -> [char; 5] { + return "hello"; +} diff --git a/tests/compiler/import_local/local_imports/nested/hello.leo b/tests/compiler/import_local/local_imports/nested/hello.leo new file mode 100644 index 0000000000..a32e24032a --- /dev/null +++ b/tests/compiler/import_local/local_imports/nested/hello.leo @@ -0,0 +1,3 @@ +function say_hello() -> [char; 5] { + return "hello"; +} diff --git a/tests/compiler/import/alias.leo b/tests/compiler/import_old/alias.leo similarity index 100% rename from tests/compiler/import/alias.leo rename to tests/compiler/import_old/alias.leo diff --git a/tests/compiler/import/basic.leo b/tests/compiler/import_old/basic.leo similarity index 100% rename from tests/compiler/import/basic.leo rename to tests/compiler/import_old/basic.leo diff --git a/tests/compiler/import/imports/a-9.leo b/tests/compiler/import_old/imports/a-9.leo similarity index 100% rename from tests/compiler/import/imports/a-9.leo rename to tests/compiler/import_old/imports/a-9.leo diff --git a/tests/compiler/import/imports/a0-f.leo b/tests/compiler/import_old/imports/a0-f.leo similarity index 100% rename from tests/compiler/import/imports/a0-f.leo rename to tests/compiler/import_old/imports/a0-f.leo diff --git a/tests/compiler/import/imports/bar/.gitignore b/tests/compiler/import_old/imports/bar/.gitignore similarity index 100% rename from tests/compiler/import/imports/bar/.gitignore rename to tests/compiler/import_old/imports/bar/.gitignore diff --git a/tests/compiler/import/imports/bar/Leo.toml b/tests/compiler/import_old/imports/bar/Leo.toml similarity index 100% rename from tests/compiler/import/imports/bar/Leo.toml rename to tests/compiler/import_old/imports/bar/Leo.toml diff --git a/tests/compiler/import/imports/bar/src/bat/bat.leo b/tests/compiler/import_old/imports/bar/src/bat/bat.leo similarity index 100% rename from tests/compiler/import/imports/bar/src/bat/bat.leo rename to tests/compiler/import_old/imports/bar/src/bat/bat.leo diff --git a/tests/compiler/import/imports/bar/src/baz.leo b/tests/compiler/import_old/imports/bar/src/baz.leo similarity index 100% rename from tests/compiler/import/imports/bar/src/baz.leo rename to tests/compiler/import_old/imports/bar/src/baz.leo diff --git a/tests/compiler/import/imports/bar/src/lib.leo b/tests/compiler/import_old/imports/bar/src/lib.leo similarity index 100% rename from tests/compiler/import/imports/bar/src/lib.leo rename to tests/compiler/import_old/imports/bar/src/lib.leo diff --git a/tests/compiler/import/imports/car/.gitignore b/tests/compiler/import_old/imports/car/.gitignore similarity index 100% rename from tests/compiler/import/imports/car/.gitignore rename to tests/compiler/import_old/imports/car/.gitignore diff --git a/tests/compiler/import/imports/car/Leo.toml b/tests/compiler/import_old/imports/car/Leo.toml similarity index 100% rename from tests/compiler/import/imports/car/Leo.toml rename to tests/compiler/import_old/imports/car/Leo.toml diff --git a/tests/compiler/import/imports/car/src/lib.leo b/tests/compiler/import_old/imports/car/src/lib.leo similarity index 100% rename from tests/compiler/import/imports/car/src/lib.leo rename to tests/compiler/import_old/imports/car/src/lib.leo diff --git a/tests/compiler/import/imports/hello-world.leo b/tests/compiler/import_old/imports/hello-world.leo similarity index 100% rename from tests/compiler/import/imports/hello-world.leo rename to tests/compiler/import_old/imports/hello-world.leo diff --git a/tests/compiler/import/imports/lib.leo b/tests/compiler/import_old/imports/lib.leo similarity index 100% rename from tests/compiler/import/imports/lib.leo rename to tests/compiler/import_old/imports/lib.leo diff --git a/tests/compiler/import/imports/test-import.leo b/tests/compiler/import_old/imports/test-import.leo similarity index 100% rename from tests/compiler/import/imports/test-import.leo rename to tests/compiler/import_old/imports/test-import.leo diff --git a/tests/compiler/import/input/dummy.in b/tests/compiler/import_old/input/dummy.in similarity index 100% rename from tests/compiler/import/input/dummy.in rename to tests/compiler/import_old/input/dummy.in diff --git a/tests/compiler/import/many_import.leo b/tests/compiler/import_old/many_import.leo similarity index 100% rename from tests/compiler/import/many_import.leo rename to tests/compiler/import_old/many_import.leo diff --git a/tests/compiler/import/many_import_star.leo b/tests/compiler/import_old/many_import_star.leo similarity index 100% rename from tests/compiler/import/many_import_star.leo rename to tests/compiler/import_old/many_import_star.leo diff --git a/tests/compiler/import/multiple.leo b/tests/compiler/import_old/multiple.leo similarity index 100% rename from tests/compiler/import/multiple.leo rename to tests/compiler/import_old/multiple.leo diff --git a/tests/compiler/import/names.leo b/tests/compiler/import_old/names.leo similarity index 100% rename from tests/compiler/import/names.leo rename to tests/compiler/import_old/names.leo diff --git a/tests/compiler/import/names_a_dash_fail.leo b/tests/compiler/import_old/names_a_dash_fail.leo similarity index 100% rename from tests/compiler/import/names_a_dash_fail.leo rename to tests/compiler/import_old/names_a_dash_fail.leo diff --git a/tests/compiler/import/names_dash_a_fail.leo b/tests/compiler/import_old/names_dash_a_fail.leo similarity index 100% rename from tests/compiler/import/names_dash_a_fail.leo rename to tests/compiler/import_old/names_dash_a_fail.leo diff --git a/tests/compiler/import/names_dollar_fail.leo b/tests/compiler/import_old/names_dollar_fail.leo similarity index 100% rename from tests/compiler/import/names_dollar_fail.leo rename to tests/compiler/import_old/names_dollar_fail.leo diff --git a/tests/compiler/import/names_underscore_fail.leo b/tests/compiler/import_old/names_underscore_fail.leo similarity index 100% rename from tests/compiler/import/names_underscore_fail.leo rename to tests/compiler/import_old/names_underscore_fail.leo diff --git a/tests/compiler/import/star.leo b/tests/compiler/import_old/star.leo similarity index 100% rename from tests/compiler/import/star.leo rename to tests/compiler/import_old/star.leo diff --git a/tests/compiler/import/star_fail.leo b/tests/compiler/import_old/star_fail.leo similarity index 100% rename from tests/compiler/import/star_fail.leo rename to tests/compiler/import_old/star_fail.leo diff --git a/tests/compiler/import/string_import.leo b/tests/compiler/import_old/string_import.leo similarity index 100% rename from tests/compiler/import/string_import.leo rename to tests/compiler/import_old/string_import.leo diff --git a/tests/expectations/compiler/compiler/import_dependency/tests/import_dependency_folder.leo.out b/tests/expectations/compiler/compiler/import_dependency/tests/import_dependency_folder.leo.out new file mode 100644 index 0000000000..1eeff43f07 --- /dev/null +++ b/tests/expectations/compiler/compiler/import_dependency/tests/import_dependency_folder.leo.out @@ -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 diff --git a/tests/expectations/compiler/compiler/import_local/import_all.leo.out b/tests/expectations/compiler/compiler/import_local/import_all.leo.out new file mode 100644 index 0000000000..af0f7a88be --- /dev/null +++ b/tests/expectations/compiler/compiler/import_local/import_all.leo.out @@ -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 diff --git a/tests/expectations/compiler/compiler/import_local/import_as.leo.out b/tests/expectations/compiler/compiler/import_local/import_as.leo.out new file mode 100644 index 0000000000..bc897c1c3f --- /dev/null +++ b/tests/expectations/compiler/compiler/import_local/import_as.leo.out @@ -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 diff --git a/tests/expectations/compiler/compiler/import_local/import_dir.leo.out b/tests/expectations/compiler/compiler/import_local/import_dir.leo.out new file mode 100644 index 0000000000..ebbd5184aa --- /dev/null +++ b/tests/expectations/compiler/compiler/import_local/import_dir.leo.out @@ -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 diff --git a/tests/expectations/compiler/compiler/import_local/import_files.leo.out b/tests/expectations/compiler/compiler/import_local/import_files.leo.out new file mode 100644 index 0000000000..aaaee96823 --- /dev/null +++ b/tests/expectations/compiler/compiler/import_local/import_files.leo.out @@ -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 diff --git a/tests/expectations/compiler/compiler/import_local/import_many.leo.out b/tests/expectations/compiler/compiler/import_local/import_many.leo.out new file mode 100644 index 0000000000..b379ba5f2e --- /dev/null +++ b/tests/expectations/compiler/compiler/import_local/import_many.leo.out @@ -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 diff --git a/tests/expectations/compiler/compiler/import_local/import_weird_names.leo.out b/tests/expectations/compiler/compiler/import_local/import_weird_names.leo.out new file mode 100644 index 0000000000..22e000786a --- /dev/null +++ b/tests/expectations/compiler/compiler/import_local/import_weird_names.leo.out @@ -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