@@ -799,6 +799,9 @@ static void test_all(const std::string & lang, std::function<void(const TestCase
799
799
}
800
800
801
801
int main () {
802
+ fprintf (stderr, " LLAMA_NODE_AVAILABLE = %s\n " , getenv (" LLAMA_NODE_AVAILABLE" ) ? " true" : " false" );
803
+ fprintf (stderr, " LLAMA_PYTHON_AVAILABLE = %s\n " , getenv (" LLAMA_PYTHON_AVAILABLE" ) ? " true" : " false" );
804
+
802
805
test_all (" C++" , [](const TestCase & tc) {
803
806
try {
804
807
tc.verify (json_schema_to_grammar (nlohmann::ordered_json::parse (tc.schema )));
@@ -808,18 +811,28 @@ int main() {
808
811
tc.verify_status (FAILURE);
809
812
}
810
813
});
811
- // test_all("Python", [](const TestCase & tc) {
812
- // write("test-json-schema-input.tmp", tc.schema);
813
- // tc.verify_status(std::system(
814
- // "python ./examples/json-schema-to-grammar.py test-json-schema-input.tmp > test-grammar-output.tmp") == 0 ? SUCCESS : FAILURE);
815
- // tc.verify(read("test-grammar-output.tmp"));
816
- // });
817
- // test_all("JavaScript", [](const TestCase & tc) {
818
- // write("test-json-schema-input.tmp", tc.schema);
819
- // tc.verify_status(std::system(
820
- // "node ./tests/run-json-schema-to-grammar.mjs test-json-schema-input.tmp > test-grammar-output.tmp") == 0 ? SUCCESS : FAILURE);
821
- // tc.verify(read("test-grammar-output.tmp"));
822
- // });
814
+
815
+ if (getenv (" LLAMA_PYTHON_AVAILABLE" ) || (std::system (" python --version" ) == 0 )) {
816
+ test_all (" Python" , [](const TestCase & tc) {
817
+ write (" test-json-schema-input.tmp" , tc.schema );
818
+ tc.verify_status (std::system (
819
+ " python ./examples/json-schema-to-grammar.py test-json-schema-input.tmp > test-grammar-output.tmp" ) == 0 ? SUCCESS : FAILURE);
820
+ tc.verify (read (" test-grammar-output.tmp" ));
821
+ });
822
+ } else {
823
+ fprintf (stderr, " \033 [33mWARNING: Python not found, skipping Python JSON schema -> grammar tests.\n\033 [0m" );
824
+ }
825
+
826
+ if (getenv (" LLAMA_NODE_AVAILABLE" ) || (std::system (" node --version" ) == 0 )) {
827
+ test_all (" JavaScript" , [](const TestCase & tc) {
828
+ write (" test-json-schema-input.tmp" , tc.schema );
829
+ tc.verify_status (std::system (
830
+ " node ./tests/run-json-schema-to-grammar.mjs test-json-schema-input.tmp > test-grammar-output.tmp" ) == 0 ? SUCCESS : FAILURE);
831
+ tc.verify (read (" test-grammar-output.tmp" ));
832
+ });
833
+ } else {
834
+ fprintf (stderr, " \033 [33mWARNING: Node not found, skipping JavaScript JSON schema -> grammar tests.\n\033 [0m" );
835
+ }
823
836
824
837
test_all (" Check Expectations Validity" , [](const TestCase & tc) {
825
838
if (tc.expected_status == SUCCESS) {
0 commit comments