diff --git a/.editorconfig b/.editorconfig index 82abb93..dc4c377 100644 --- a/.editorconfig +++ b/.editorconfig @@ -13,3 +13,7 @@ tab_width = 4 # Markup files [{*.html,*.xml,*.xml.in,*.yml}] tab_width = 2 + +# Don't insert new line in test asset files. +[/vamp/tests/assets/*] +insert_final_newline = false diff --git a/README.md b/README.md index c483fdd..7049919 100644 --- a/README.md +++ b/README.md @@ -9,3 +9,8 @@ - Fetch and install Vala dependencies from Git URLs - Integrate with Meson and Flatpak + +## vamp.json spec inspirations + +- npm: https://docs.npmjs.com/cli/v8/configuring-npm/package-json +- drakkar: https://github.com/valum-framework/drakkar diff --git a/cli/meson.build b/cli/meson.build new file mode 100644 index 0000000..9537275 --- /dev/null +++ b/cli/meson.build @@ -0,0 +1 @@ +subdir('src') diff --git a/src/main.vala b/cli/src/main.vala similarity index 100% rename from src/main.vala rename to cli/src/main.vala diff --git a/cli/src/meson.build b/cli/src/meson.build new file mode 100644 index 0000000..4c2ba35 --- /dev/null +++ b/cli/src/meson.build @@ -0,0 +1,9 @@ +cli_sources = [ + 'main.vala', +] + +executable('vamp', + cli_sources, + dependencies: [dependencies , vamp_dep], + install: true, +) diff --git a/meson.build b/meson.build index 5ed0e73..f67a743 100644 --- a/meson.build +++ b/meson.build @@ -1,12 +1,15 @@ project('vamp', 'vala', 'c', - version: '0.0.1') + version: '0.0.1' +) dependencies = [ - dependency('glib-2.0'), - dependency('gobject-2.0') + dependency('glib-2.0'), + dependency('gobject-2.0'), + dependency('gee-0.8'), + dependency('json-glib-1.0'), ] add_project_arguments(['--enable-experimental'], language: 'vala') -subdir('src') -subdir('tests') +subdir('vamp') +subdir('cli') diff --git a/src/meson.build b/src/meson.build deleted file mode 100644 index 6973d8b..0000000 --- a/src/meson.build +++ /dev/null @@ -1,8 +0,0 @@ -sources = [ - 'main.vala' -] - -executable('vamp', - sources, - dependencies: dependencies, - install: true) diff --git a/tests/UnitTests.vala b/tests/UnitTests.vala deleted file mode 100644 index f9c0d45..0000000 --- a/tests/UnitTests.vala +++ /dev/null @@ -1,17 +0,0 @@ -namespace Vamp { - class UnitTests { - public static int main (string[] args) { - Test.init (ref args); - - Test.add_func ("/vamp/foo", () => { - assert_null (null); - }); - - Test.add_func ("/vamp/bar", () => { - assert_true (true); - }); - - return Test.run (); - } - } -} diff --git a/tests/meson.build b/tests/meson.build deleted file mode 100644 index 7d3914e..0000000 --- a/tests/meson.build +++ /dev/null @@ -1,13 +0,0 @@ -if get_option('tests') - -test_sources = [ - 'UnitTests.vala' -] - -test_executable = executable('vamp-tests', test_sources, - dependencies: dependencies -) - -test('vamp-tests', test_executable) - -endif diff --git a/vamp/meson.build b/vamp/meson.build new file mode 100644 index 0000000..67d3858 --- /dev/null +++ b/vamp/meson.build @@ -0,0 +1,2 @@ +subdir('src') +subdir('tests') diff --git a/vamp/src/meson.build b/vamp/src/meson.build new file mode 100644 index 0000000..bdc0c89 --- /dev/null +++ b/vamp/src/meson.build @@ -0,0 +1,20 @@ +vamp_sources = [ + 'models/Bugs.vala', + 'models/FundingInfo.vala', + 'models/Package.vala', + 'models/Person.vala', + 'models/Repository.vala', +] + +vamp_lib = library( + 'vamp', + vamp_sources, + vala_header: 'vamp.h', + vala_vapi: 'vamp.vapi', + dependencies: dependencies, +) + +vamp_dep = declare_dependency( + include_directories: include_directories('.'), + link_with: vamp_lib, +) diff --git a/vamp/src/models/Bugs.vala b/vamp/src/models/Bugs.vala new file mode 100644 index 0000000..f523c7d --- /dev/null +++ b/vamp/src/models/Bugs.vala @@ -0,0 +1,18 @@ +public class Vamp.Bugs : GLib.Object { + public string url { get; set; } + public string email { get; set; } + + public static Bugs from_json (Json.Node node) { + assert (node.get_node_type () == Json.NodeType.OBJECT); + return (Bugs) Json.gobject_deserialize (typeof (Bugs), node); + } + + public Json.Node to_json () { + return Json.gobject_serialize (this); + } + + public bool equal (Vamp.Bugs other) { + return this.url == other.url + && this.email == other.email; + } +} diff --git a/vamp/src/models/FundingInfo.vala b/vamp/src/models/FundingInfo.vala new file mode 100644 index 0000000..d18427b --- /dev/null +++ b/vamp/src/models/FundingInfo.vala @@ -0,0 +1,75 @@ +public class Vamp.FundingInfo : Object { + public string funding_type { get; set; } + public string url { get; set; } + + public static FundingInfo from_json (Json.Node node) { + assert (node.get_node_type () == Json.NodeType.OBJECT); + var result = new FundingInfo (); + + var obj = node.get_object (); + obj.get_members ().foreach ((member_name) => { + switch (member_name) { + case "type": + result.funding_type = obj.get_string_member (member_name); + break; + + default: + result.set_property (member_name, obj.get_string_member (member_name)); + break; + } + }); + + return result; + } + + public static Gee.List list_from_json (Json.Node node) { + assert (node.get_node_type () == Json.NodeType.ARRAY); + + var array = node.get_array (); + var result = new Gee.ArrayList (); + + array.foreach_element ((_, __, element_node) => { + if (element_node.get_node_type () != Json.NodeType.OBJECT) { + return; + } + + result.add (FundingInfo.from_json (element_node)); + }); + + return result; + } + + public static Json.Node list_to_json (Gee.List list) { + var node_array = new Json.Array.sized (list.size); + + list.foreach ((element) => { + node_array.add_element (element.to_json ()); + return true; + }); + + var node = new Json.Node (Json.NodeType.ARRAY); + node.set_array (node_array); + return node; + } + + public Json.Node to_json () { + var obj = new Json.Object (); + if (this.funding_type != null) { + obj.set_string_member ("type", this.funding_type); + } + + if (this.url != null) { + obj.set_string_member ("url", this.url); + } + + var result = new Json.Node (Json.NodeType.OBJECT); + result.set_object (obj); + + return result; + } + + public bool equal (Vamp.FundingInfo other) { + return this.funding_type == other.funding_type + && this.url == other.url; + } +} diff --git a/vamp/src/models/Package.vala b/vamp/src/models/Package.vala new file mode 100644 index 0000000..391c82a --- /dev/null +++ b/vamp/src/models/Package.vala @@ -0,0 +1,251 @@ +public class Vamp.Package : Object, Json.Serializable { + public string name { get; set; } + public string version { get; set; } + public string description { get; set; } + public Gee.List keywords { get; set; } + public string homepage { get; set; } + public Bugs bugs { get; set; } + public string license { get; set; } + public Person author { get; set; } + public Gee.List contributors { get; set; } + public Gee.List funding { get; set; } + public Gee.List files { get; set; } + public Repository repository { get; set; } + public Gee.Map dependencies { get; set; } + public Gee.Map dev_dependencies { get; set; } + public Gee.Map optional_dependencies { get; set; } + + public static Package from_json (Json.Node node) { + assert (node.get_node_type () == Json.NodeType.OBJECT); + return (Package) Json.gobject_deserialize (typeof (Package), node); + } + + public Json.Node to_json () { + return Json.gobject_serialize (this); + } + + private bool deserialize_property ( + string property_name, + out Value @value, + ParamSpec pspec, + Json.Node property_node + ) { + switch (property_name) { + case "keywords": + if (property_node.get_node_type () != Json.NodeType.ARRAY) { + @value = {}; + return false; + } + + @value = string_list_from_json (property_node); + + return true; + + case "bugs": + if (property_node.get_node_type () == Json.NodeType.OBJECT) { + @value = Bugs.from_json (property_node); + return true; + } + + if (property_node.get_value_type () != Type.STRING) { + @value = {}; + return false; + } + + @value = new Bugs () { + url = property_node.get_string (), + }; + + return true; + + case "author": + if (property_node.get_node_type () == Json.NodeType.OBJECT) { + @value = Person.from_json (property_node); + return true; + } + + if (property_node.get_value_type () != Type.STRING) { + @value = {}; + return false; + } + + return Person.try_parse (property_node.get_string (), out @value); + + case "contributors": + if (property_node.get_node_type () != Json.NodeType.ARRAY) { + @value = {}; + return false; + } + + @value = Person.list_from_json (property_node); + + return true; + + case "funding": + if (property_node.get_node_type () != Json.NodeType.ARRAY) { + @value = {}; + return false; + } + + @value = FundingInfo.list_from_json (property_node); + + return true; + + case "files": + if (property_node.get_node_type () != Json.NodeType.ARRAY) { + @value = {}; + return false; + } + + @value = string_list_from_json (property_node); + + return true; + + case "repository": + if (property_node.get_node_type () != Json.NodeType.OBJECT) { + @value = {}; + return false; + } + + @value = Repository.from_json (property_node); + + return true; + + case "dependencies": + case "dev-dependencies": + case "optional-dependencies": + if (property_node.get_node_type () != Json.NodeType.OBJECT) { + @value = {}; + return false; + } + + @value = string_map_from_json (property_node); + + return true; + + default: + return default_deserialize_property ( + property_name, + out @value, + pspec, + property_node + ); + } + } + + private Json.Node serialize_property ( + string property_name, + Value value_to_serialize, + ParamSpec pspec + ) { + switch (property_name) { + case "keywords": + case "files": + Gee.List converted_value = (Gee.List)value_to_serialize.get_object (); + if (converted_value == null) { + return null; + } + + return string_list_to_json (converted_value); + + case "contributors": + Gee.List converted_value = (Gee.List)value_to_serialize.get_object (); + if (converted_value == null) { + return null; + } + + return Person.list_to_json (converted_value); + + case "funding": + Gee.List converted_value = (Gee.List)value_to_serialize.get_object (); + if (converted_value == null) { + return null; + } + + return FundingInfo.list_to_json (converted_value); + + case "repository": + Vamp.Repository converted_value = (Vamp.Repository)value_to_serialize.get_object (); + + if (converted_value == null) { + return null; + } + + return converted_value.to_json (); + + case "dependencies": + case "dev-dependencies": + case "optional-dependencies": + Gee.Map converted_value = (Gee.Map)value_to_serialize.get_object (); + + if (converted_value == null) { + return null; + } + + return string_map_to_json (converted_value); + + default: + return default_serialize_property ( + property_name, + value_to_serialize, + pspec + ); + } + } +} + +Json.Node string_list_to_json (Gee.List list) { + var node_array = new Json.Array.sized (list.size); + list.foreach ((element) => { + node_array.add_string_element (element); + return true; + }); + + var node = new Json.Node (Json.NodeType.ARRAY); + node.set_array (node_array); + + return node; +} + +Gee.List string_list_from_json (Json.Node node) { + assert (node.get_node_type () == Json.NodeType.ARRAY); + + var array = node.get_array (); + var result = new Gee.ArrayList (); + + array.foreach_element ((_, __, element_node) => { + if (element_node.get_value_type () != Type.STRING) { + return; + } + + result.add (element_node.get_string ()); + }); + + return result; +} + + +Json.Node string_map_to_json (Gee.Map map) { + var node_object = new Json.Object (); + map.entries.foreach ((entry) => { + node_object.set_string_member (entry.key, entry.value); + return true; + }); + + var node = new Json.Node (Json.NodeType.OBJECT); + node.set_object (node_object); + + return node; +} + +Gee.Map string_map_from_json (Json.Node node) { + assert (node.get_node_type () == Json.NodeType.OBJECT); + + var result = new Gee.HashMap (); + + node.get_object ().foreach_member ((obj, member_name, member_node) => { + result.set (member_name, member_node.get_string ()); + }); + + return result; +} diff --git a/vamp/src/models/Person.vala b/vamp/src/models/Person.vala new file mode 100644 index 0000000..15786a7 --- /dev/null +++ b/vamp/src/models/Person.vala @@ -0,0 +1,71 @@ +public class Vamp.Person : Object { + private static Regex regex = /^(.*)(?:\s)(<.*>)(?:\s)(\(.*\))/; // vala-lint=space-before-paren + + public string name { get; set; } + public string email { get; set; } + public string url { get; set; } + + public static Person from_json (Json.Node node) { + assert (node.get_node_type () == Json.NodeType.OBJECT); + return (Person) Json.gobject_deserialize (typeof (Person), node); + } + + public static Gee.List list_from_json (Json.Node node) { + assert (node.get_node_type () == Json.NodeType.ARRAY); + + var array = node.get_array (); + var result = new Gee.ArrayList (); + + array.foreach_element ((_, __, element_node) => { + if (element_node.get_node_type () != Json.NodeType.OBJECT) { + return; + } + + result.add (Person.from_json (element_node)); + }); + + return result; + + + } + + public static Json.Node list_to_json (Gee.List list) { + var node_array = new Json.Array.sized (list.size); + + list.foreach ((element) => { + node_array.add_element (element.to_json ()); + return true; + }); + + var node = new Json.Node (Json.NodeType.ARRAY); + node.set_array (node_array); + return node; + } + + public static bool try_parse (string str, out Person result) { + MatchInfo info; + + if (!Person.regex.match (str, 0, out info)) { + result = null; + return false; + } + + result = new Person () { + name = info.fetch (1), + email = info.fetch (2), + url = info.fetch (3), + }; + + return true; + } + + public Json.Node to_json () { + return Json.gobject_serialize (this); + } + + public bool equal (Vamp.Person other) { + return this.name == other.name + && this.email == other.email + && this.url == other.url; + } +} diff --git a/vamp/src/models/Repository.vala b/vamp/src/models/Repository.vala new file mode 100644 index 0000000..7ea0fb9 --- /dev/null +++ b/vamp/src/models/Repository.vala @@ -0,0 +1,48 @@ +public class Vamp.Repository : Object { + public string repository_type { get; set; } + public string url { get; set; } + public string directory { get; set; } + + public static Repository from_json (Json.Node node) { + assert (node.get_node_type () == Json.NodeType.OBJECT); + var result = new Repository (); + + var obj = node.get_object (); + obj.get_members ().foreach ((member_name) => { + switch (member_name) { + case "type": + result.repository_type = obj.get_string_member (member_name); + break; + + default: + result.set_property (member_name, obj.get_string_member (member_name)); + break; + } + }); + + return result; + } + + public Json.Node to_json () { + var obj = new Json.Object (); + + if (this.repository_type != null) { + obj.set_string_member ("type", this.repository_type); + } + + if (this.url != null) { + obj.set_string_member ("url", this.url); + } + + var result = new Json.Node (Json.NodeType.OBJECT); + result.set_object (obj); + + return result; + } + + public bool equal (Vamp.Repository other) { + return this.repository_type == other.repository_type + && this.url == other.url + && this.directory == other.directory; + } +} diff --git a/vamp/tests/UnitTests.vala b/vamp/tests/UnitTests.vala new file mode 100644 index 0000000..677d655 --- /dev/null +++ b/vamp/tests/UnitTests.vala @@ -0,0 +1,235 @@ +namespace Vamp { + class UnitTests { + public static int main (string[] args) { + Test.init (ref args); + + Test.add_func ("/vamp/deserialize_basic_config", () => { + string package_contents; + try { + FileUtils.get_contents (TestConfig.TEST_PACKAGE_FILE, out package_contents); + Vamp.Package package = deserialize_package_config (package_contents); + assert (package.name == "test-project"); + assert (package.version == "0.0.1"); + assert (package.description == "A Test Project"); + } catch (FileError e) { + error (e.message); + } + }); + + Test.add_func ("/vamp/deserialize_full_config", () => { + string package_contents; + try { + FileUtils.get_contents (TestConfig.FULL_TEST_PACKAGE_FILE, out package_contents); + Vamp.Package package = deserialize_package_config (package_contents); + assert (package.name == "test-project"); + assert (package.version == "0.0.1"); + assert (package.description == "A Test Project"); + assert (package.keywords.contains_all_array ({"test", "project", "fake", "mock"})); + assert (package.homepage == "https://wwww.test.com"); + + // We assert objects this way so that: + // 1. We know the exact value of each object property + // 2. We can easily update our asserts as we update the + // object's properties. + assert_full_config_bugs (package.bugs); + assert (package.license == "MIT"); + assert_full_config_author (package.author); + assert_full_config_contributors (package.contributors); + assert_full_config_funding (package.funding); + assert (package.files.contains_all_array ({"./main-module/**/*", "./extra-module/**/*"})); + assert_full_config_respository (package.repository); + assert_full_config_dependencies (package.dependencies); + assert_full_config_dev_dependencies (package.dev_dependencies); + assert_full_config_optional_dependencies (package.optional_dependencies); + } catch (FileError e) { + error (e.message); + } + }); + + Test.add_func ("/vamp/serialize_basic_config", () => { + Vamp.Package package = new Vamp.Package () { + name = "basic-project", + version = "1.0.0", + description = "A basic project", + }; + + var generator = new Json.Generator () { + pretty = true, + indent = 4, + }; + + generator.set_root (package.to_json ()); + + try { + string expected_content; + FileUtils.get_contents (TestConfig.BASIC_EXPECTED_TEST_PACKAGE_FILE, + out expected_content + ); + + assert (generator.to_data (null) == expected_content); + + } catch (Error e) { + error (e.message); + } + }); + + Test.add_func ("/vamp/serialize_full_config", () => { + Vamp.Package package = new Vamp.Package () { + name = "full-project", + version = "1.0.0", + description = "A full project", + keywords = new Gee.ArrayList.wrap ({"full", "project"}), + homepage = "https://www.full-project.com", + bugs = new Bugs () { + url = "https://www.full-project.com/bugs", + email = "bugs@full-project.com" + }, + license = "MIT", + author = new Person () { + name = "vamp-dev", + email = "vamp-dev@vamp.org", + url = "https://www.vamp-dev.com" + }, + contributors = new Gee.ArrayList.wrap ({ + new Person () { + name = "vamp-dev-2", + email = "vamp-dev-2@vamp.org", + url = "https://www.vamp-dev-2.com" + }, + new Person () { + name = "vamp-dev-3", + email = "vamp-dev-3@vamp.org", + url = "https://www.vamp-dev-3.com" + }, + }), + funding = new Gee.ArrayList.wrap ({ + new FundingInfo () { + funding_type = "individual", + url = "https://www.vamp.com/donate" + } + }), + files = new Gee.ArrayList.wrap ({ + "./main-module/**/*", + "./extra-module/**/*" + }), + repository = new Repository () { + repository_type = "git", + url = "https://www.notgithub.com/owner/project" + }, + }; + + var dependencies = new Gee.HashMap (); + dependencies["json-glib"] = "^1.0.0"; + package.dependencies = dependencies; + + var dev_dependencies = new Gee.HashMap (); + dev_dependencies["g-ir-compiler"] = "^1.2.0"; + package.dev_dependencies = dev_dependencies; + + var optional_dependencies = new Gee.HashMap (); + optional_dependencies["valadoc"] = "^0.56.0"; + package.optional_dependencies = optional_dependencies; + + var generator = new Json.Generator () { + pretty = true, + indent = 4, + }; + + generator.set_root (package.to_json ()); + try { + string expected_content; + FileUtils.get_contents (TestConfig.FULL_EXPECTED_TEST_PACKAGE_FILE, + out expected_content + ); + + assert (generator.to_data (null) == expected_content); + } catch (Error e) { + error (e.message); + } + }); + + return Test.run (); + } + + private static void assert_full_config_optional_dependencies (Gee.Map dependencies) { + assert (dependencies["valadoc"] == "^0.48.0"); + } + + private static void assert_full_config_dev_dependencies (Gee.Map dependencies) { + assert (dependencies["g-ir-compiler"] == "^1.6.0"); + } + + private static void assert_full_config_dependencies (Gee.Map dependencies) { + assert (dependencies["json-glib"] == "^1.6.0"); + } + + private static void assert_full_config_respository (Vamp.Repository repository) { + assert (repository.repository_type == "git"); + assert (repository.url == "https://www.notgithub.com/owner/project"); + } + + private static void assert_full_config_funding (Gee.List funding) { + for (int i = 0; i < funding.size; i++) { + FundingInfo funding_info = funding[i]; + switch (i) { + case 0: + assert (funding_info.funding_type == "individual"); + assert (funding_info.url == "https://www.vamp.com/donate"); + break; + } + + if (i == funding.size - 1 && i != 0) { + Test.message ("Test failed! - Did not parse 1 funding info item.\n" + + "Parsed: %d parsing info item(s).", i + 1 + ); + + Test.fail (); + } + } + } + + private static void assert_full_config_contributors (Gee.List contributors) { + for (int i = 0; i < contributors.size; i++) { + Person contributor = contributors[i]; + switch (i) { + case 0: + assert (contributor.name == "vamp-dev-2"); + assert (contributor.email == "vamp-dev-2@vamp.org"); + assert (contributor.url == "https://vamp-dev-2.com"); + break; + case 1: + assert (contributor.name == "vamp-dev-3"); + assert (contributor.email == "vamp-dev-3@vamp.org"); + assert (contributor.url == "https://vamp-dev-3.com"); + break; + } + + if (i == contributors.size - 1 && i != 1) { + Test.message ("Test failed! - Did not parse 2 contributors.\nParsed: %d contributor(s).", i + 1); + Test.fail (); + } + } + } + + private static void assert_full_config_author (Vamp.Person author) { + assert (author.name == "vamp-dev"); + assert (author.email == "vamp-dev@vamp.org"); + assert (author.url == "https://vamp-dev.com"); + } + + private static void assert_full_config_bugs (Vamp.Bugs bugs) { + assert (bugs.email == "bugs@test.com"); + assert (bugs.url == "https://www.notgithub.com/owner/project/issues"); + } + + private static Vamp.Package deserialize_package_config (string config_data) { + var parser = new Json.Parser (); + try { + parser.load_from_data (config_data); + return Vamp.Package.from_json (parser.get_root ()); + } catch (Error e) { + error ("Unable to parse the package config data: %s\n", e.message); + } + } + } +} diff --git a/vamp/tests/assets/expected-basic-vamp.json b/vamp/tests/assets/expected-basic-vamp.json new file mode 100644 index 0000000..5e33abe --- /dev/null +++ b/vamp/tests/assets/expected-basic-vamp.json @@ -0,0 +1,5 @@ +{ + "name" : "basic-project", + "version" : "1.0.0", + "description" : "A basic project" +} \ No newline at end of file diff --git a/vamp/tests/assets/expected-full-vamp.json b/vamp/tests/assets/expected-full-vamp.json new file mode 100644 index 0000000..6b7828e --- /dev/null +++ b/vamp/tests/assets/expected-full-vamp.json @@ -0,0 +1,55 @@ +{ + "name" : "full-project", + "version" : "1.0.0", + "description" : "A full project", + "keywords" : [ + "full", + "project" + ], + "homepage" : "https://www.full-project.com", + "bugs" : { + "url" : "https://www.full-project.com/bugs", + "email" : "bugs@full-project.com" + }, + "license" : "MIT", + "author" : { + "name" : "vamp-dev", + "email" : "vamp-dev@vamp.org", + "url" : "https://www.vamp-dev.com" + }, + "contributors" : [ + { + "name" : "vamp-dev-2", + "email" : "vamp-dev-2@vamp.org", + "url" : "https://www.vamp-dev-2.com" + }, + { + "name" : "vamp-dev-3", + "email" : "vamp-dev-3@vamp.org", + "url" : "https://www.vamp-dev-3.com" + } + ], + "funding" : [ + { + "type" : "individual", + "url" : "https://www.vamp.com/donate" + } + ], + "files" : [ + "./main-module/**/*", + "./extra-module/**/*" + ], + "repository" : { + "type" : "git", + "url" : "https://www.notgithub.com/owner/project" + }, + "dependencies" : { + "json-glib" : "^1.0.0" + }, + "dev-dependencies" : { + "g-ir-compiler" : "^1.2.0" + }, + "optional-dependencies" : { + "valadoc" : "^0.56.0" + } +} \ No newline at end of file diff --git a/vamp/tests/assets/full-vamp.json b/vamp/tests/assets/full-vamp.json new file mode 100644 index 0000000..63bd869 --- /dev/null +++ b/vamp/tests/assets/full-vamp.json @@ -0,0 +1,52 @@ +{ + "name": "test-project", + "version": "0.0.1", + "description": "A Test Project", + "keywords": ["test", "project", "fake", "mock"], + "homepage": "https://wwww.test.com", + "bugs": { + "url": "https://www.notgithub.com/owner/project/issues", + "email": "bugs@test.com" + }, + "license": "MIT", + "author": { + "name": "vamp-dev", + "email": "vamp-dev@vamp.org", + "url": "https://vamp-dev.com" + }, + "contributors": [ + { + "name": "vamp-dev-2", + "email": "vamp-dev-2@vamp.org", + "url": "https://vamp-dev-2.com" + }, + { + "name": "vamp-dev-3", + "email": "vamp-dev-3@vamp.org", + "url": "https://vamp-dev-3.com" + } + ], + "funding": [ + { + "type": "individual", + "url": "https://www.vamp.com/donate" + } + ], + "files": [ + "./main-module/**/*", + "./extra-module/**/*" + ], + "repository": { + "type": "git", + "url": "https://www.notgithub.com/owner/project" + }, + "dependencies": { + "json-glib": "^1.6.0" + }, + "dev_dependencies": { + "g-ir-compiler": "^1.6.0" + }, + "optional_dependencies": { + "valadoc": "^0.48.0" + } +} \ No newline at end of file diff --git a/vamp/tests/assets/vamp.json b/vamp/tests/assets/vamp.json new file mode 100644 index 0000000..782ebd8 --- /dev/null +++ b/vamp/tests/assets/vamp.json @@ -0,0 +1,5 @@ +{ + "name": "test-project", + "version": "0.0.1", + "description": "A Test Project" +} \ No newline at end of file diff --git a/vamp/tests/config.vapi.in b/vamp/tests/config.vapi.in new file mode 100644 index 0000000..4e93171 --- /dev/null +++ b/vamp/tests/config.vapi.in @@ -0,0 +1,10 @@ +[CCode (cheader_filename = "config.h", lower_case_cprefix = "")] +namespace TestConfig { + public const string TEST_PACKAGE_FILE; + + public const string FULL_TEST_PACKAGE_FILE; + + public const string BASIC_EXPECTED_TEST_PACKAGE_FILE; + + public const string FULL_EXPECTED_TEST_PACKAGE_FILE; +} diff --git a/vamp/tests/meson.build b/vamp/tests/meson.build new file mode 100644 index 0000000..9882188 --- /dev/null +++ b/vamp/tests/meson.build @@ -0,0 +1,43 @@ + +if get_option('tests') + configure_file ( + input: 'config.vapi.in', + output: 'config.vapi', + copy: true + ) + + configure_file ( + output: 'config.h', + configuration: { + 'TEST_PACKAGE_FILE': '"' + meson.current_source_dir() / 'assets/vamp.json"', + 'FULL_TEST_PACKAGE_FILE': '"' + meson.current_source_dir() / 'assets/full-vamp.json"', + 'BASIC_EXPECTED_TEST_PACKAGE_FILE': '"' + meson.current_source_dir() / 'assets/expected-basic-vamp.json"', + 'FULL_EXPECTED_TEST_PACKAGE_FILE': '"' + meson.current_source_dir() / 'assets/expected-full-vamp.json"', + } + ) + + vala_args = [ + '--vapidir', meson.current_build_dir(), + '--pkg', 'config' + ] + + test_sources = [ + 'UnitTests.vala' + ] + + test_dependencies = [ + vamp_dep, + ] + + foreach dep : dependencies + test_dependencies += dep + endforeach + + test_executable = executable('vamp-tests', test_sources, + dependencies: test_dependencies, + vala_args: vala_args + ) + + test('vamp-tests', test_executable) + +endif