From a672b0710919287ffbede8594c47aade35dd5874 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ingy=20d=C3=B6t=20Net?= Date: Thu, 29 Dec 2016 20:14:14 -0600 Subject: [PATCH] Include libyaml-test and libyaml-parser-emitter Before the `make test-suite` command would clone yaml/libyaml-test which would in tuen clone yaml/libyaml-parser-emitter. Now they are part of the repository since they are not really useful outside the repository. They still clone the data branch of yaml/yaml-test-suite. That is where all the actual test data resides. That belongs outside the repo because it is intended for all yaml frameworks. --- .gitignore | 98 +++++--- .indent.pro | 1 + Makefile.am | 11 +- tests/run-test-suite/Makefile | 29 +++ tests/run-test-suite/ReadMe.md | 17 ++ tests/run-test-suite/src/Makefile | 54 ++++ tests/run-test-suite/src/ReadMe.md | 34 +++ tests/run-test-suite/src/libyaml-emitter.c | 232 ++++++++++++++++++ tests/run-test-suite/src/libyaml-parser.c | 144 +++++++++++ .../src/test/example-2.27-invoice.events | 59 +++++ .../src/test/example-2.27-invoice.out | 26 ++ .../src/test/example-2.27-invoice.yaml | 29 +++ .../run-test-suite/src/test/libyaml-emitter.t | 26 ++ .../run-test-suite/src/test/libyaml-parser.t | 26 ++ .../run-test-suite/test/libyaml-emitter.skip | 31 +++ tests/run-test-suite/test/libyaml-emitter.t | 43 ++++ tests/run-test-suite/test/libyaml-parser.skip | 22 ++ tests/run-test-suite/test/libyaml-parser.t | 36 +++ tests/run-tests.sh | 12 +- 19 files changed, 876 insertions(+), 54 deletions(-) create mode 100644 .indent.pro create mode 100644 tests/run-test-suite/Makefile create mode 100644 tests/run-test-suite/ReadMe.md create mode 100644 tests/run-test-suite/src/Makefile create mode 100644 tests/run-test-suite/src/ReadMe.md create mode 100644 tests/run-test-suite/src/libyaml-emitter.c create mode 100644 tests/run-test-suite/src/libyaml-parser.c create mode 100644 tests/run-test-suite/src/test/example-2.27-invoice.events create mode 100644 tests/run-test-suite/src/test/example-2.27-invoice.out create mode 100644 tests/run-test-suite/src/test/example-2.27-invoice.yaml create mode 100644 tests/run-test-suite/src/test/libyaml-emitter.t create mode 100644 tests/run-test-suite/src/test/libyaml-parser.t create mode 100644 tests/run-test-suite/test/libyaml-emitter.skip create mode 100755 tests/run-test-suite/test/libyaml-emitter.t create mode 100644 tests/run-test-suite/test/libyaml-parser.skip create mode 100755 tests/run-test-suite/test/libyaml-parser.t diff --git a/.gitignore b/.gitignore index ee03052..f1a0b64 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,62 @@ -CMakeCache.txt -CMakeFiles/ -CTestTestfile.cmake -Makefile -Makefile.in -Testing/ -aclocal.m4 -autom4te.cache -cmake_install.cmake -configure -config -config.h -config.h.in -config.h.in~ -config.log -config.status -example-deconstructor -example-deconstructor-alt -example-reformatter -example-reformatter-alt -libtool -libyaml.a -libyaml-test/ -run-dumper -run-emitter -run-loader -run-parser -run-scanner -stamp-h1 -test-reader -test-version -tests/test-reader -tests/test-reader.log -tests/test-reader.trs -tests/test-suite.log -tests/test-version -tests/test-version.log -tests/test-version.trs -.deps -.libs +.deps/ +.libs/ +*~ +*.BAK *.la *.lo *.o *.pc +/CMakeCache.txt +/CMakeFiles/ +/CTestTestfile.cmake +/Makefile +Makefile.in +/Testing/ +/aclocal.m4 +/autom4te.cache +/cmake_install.cmake +/config +/config.h +/config.h.in +/config.h.in~ +/config.log +/config.status +/configure +/example-deconstructor +/example-deconstructor-alt +/example-reformatter +/example-reformatter-alt +/include/Makefile +/libtool +/libyaml.a +/run-dumper +/run-emitter +/run-loader +/run-parser +/run-scanner +/src/Makefile +/stamp-h1 +/test-reader +/test-version +/tests/Makefile +/tests/example-deconstructor +/tests/example-deconstructor-alt +/tests/example-reformatter +/tests/example-reformatter-alt +/tests/run-dumper +/tests/run-emitter +/tests/run-loader +/tests/run-parser +/tests/run-scanner +/tests/run-test-suite/data +tests/run-test-suite/src/libyaml/ +tests/run-test-suite/src/libyaml-emitter +tests/run-test-suite/src/libyaml-parser +/tests/test-reader +/tests/test-reader.log +/tests/test-reader.trs +/tests/test-suite.log +/tests/test-version +/tests/test-version.log +/tests/test-version.trs +/win32/Makefile diff --git a/.indent.pro b/.indent.pro new file mode 100644 index 0000000..d647720 --- /dev/null +++ b/.indent.pro @@ -0,0 +1 @@ +-kr -nut -nce -l250 diff --git a/Makefile.am b/Makefile.am index 1b47f33..6425b6b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -13,19 +13,18 @@ maintainer-clean-local: -find ${builddir} -name Makefile.in -exec rm -f '{}' ';' distclean-local: - -rm -fr libyaml-test + -make -C tests/run-test-suite clean .PHONY: bootstrap bootstrap: maintainer-clean ./bootstrap + ./configure + make test: all make -C tests check-TESTS -test-suite: libyaml-test - (export LIBYAML_DIR=$$PWD; make -C $< test) - -libyaml-test: - git clone https://github.com/yaml/$@ +test-suite: + (export LIBYAML_DIR=$$PWD; make -C tests/run-test-suite test) test-all: test test-suite diff --git a/tests/run-test-suite/Makefile b/tests/run-test-suite/Makefile new file mode 100644 index 0000000..bdf89f6 --- /dev/null +++ b/tests/run-test-suite/Makefile @@ -0,0 +1,29 @@ +.PHONY: test +GITHUB_ORG_URI := https://github.com/yaml +TEST_SUITE_URL := $(GITHUB_ORG_URI)/yaml-test-suite +LIBYAML_DIR ?= $(PWD)/libyaml-parser-emitter/libyaml + +default: help + +help: + @echo 'test - Run the tests' + @echo 'clean - Remove generated files' + @echo 'help - Show help' + +# Depends on parser and emitter but, building parser will also build emitter. +# Building twice makes things fail. Note: Some environments like on OS X, the +# shell resets the {DY,}LD_LIBRARY_PATH vars, so we work around it like so: +test: data src/libyaml-parser + (export MY_LD_LIBRARY_PATH=$(LIBYAML_DIR)/src/.libs; prove -lv test) + +clean: + rm -fr data + +data: + git clone $(TEST_SUITE_URL) $@ --branch=$@ + +%/libyaml-parser %/libyaml-emitter: % + (cd $<; make build) + +libyaml-parser-emitter: + git clone $(GITHUB_ORG_URI)/$@ $@ diff --git a/tests/run-test-suite/ReadMe.md b/tests/run-test-suite/ReadMe.md new file mode 100644 index 0000000..c1ef208 --- /dev/null +++ b/tests/run-test-suite/ReadMe.md @@ -0,0 +1,17 @@ +LibYAML Test Runner +=================== + +Run libyaml-parser and libyaml-emitter against yaml-test-suite + +# Synopsis + +``` +make test +``` + +# Overview + +See: + +* https://github.com/yaml/libyaml +* https://github.com/yaml/yaml-test-suite diff --git a/tests/run-test-suite/src/Makefile b/tests/run-test-suite/src/Makefile new file mode 100644 index 0000000..de0d49a --- /dev/null +++ b/tests/run-test-suite/src/Makefile @@ -0,0 +1,54 @@ +LIBYAML_DIR ?= libyaml +LIBYAML_REPO ?= https://github.com/yaml/libyaml +LIBYAML_BRANCH ?= master +define HELP +This Makefile supports the following targets: + + build - Build ./libyaml-parser and ./libyaml-emitter + test - Run tests + +endef +export HELP + +help: + @echo "$$HELP" + +build: touch libyaml-parser libyaml-emitter + +touch: +ifneq ($(LIBYAML_DIR),libyaml) + touch *.c +endif + +libyaml-%: $(LIBYAML_DIR)/tests/.libs/run-% + cp $< $@ + +$(LIBYAML_DIR)/tests/.libs/%: $(LIBYAML_DIR)/tests/%.c $(LIBYAML_DIR)/Makefile + make -C $(LIBYAML_DIR) +ifneq ($(LIBYAML_DIR),libyaml) + (cd $(LIBYAML_DIR) && git checkout tests/run-parser.c tests/run-emitter.c) +endif + +$(LIBYAML_DIR)/tests/run-%: libyaml-% $(LIBYAML_DIR) + cp $< $@ +.SECONDARY: \ + $(LIBYAML_DIR)/tests/run-parser.c \ + $(LIBYAML_DIR)/tests/run-emitter.c \ + $(LIBYAML_DIR)/tests/.libs/run-parser \ + $(LIBYAML_DIR)/tests/.libs/run-emitter + +$(LIBYAML_DIR)/Makefile: $(LIBYAML_DIR) + ( cd $< && ./bootstrap && ./configure ) + touch $@ + +$(LIBYAML_DIR): + git clone $(LIBYAML_REPO) $@ + sleep 1 + touch *.c + +.PHONY: test +test: build + prove -lv test/ + +clean: + rm -fr libyaml libyaml-parser libyaml-emitter diff --git a/tests/run-test-suite/src/ReadMe.md b/tests/run-test-suite/src/ReadMe.md new file mode 100644 index 0000000..ced29cb --- /dev/null +++ b/tests/run-test-suite/src/ReadMe.md @@ -0,0 +1,34 @@ +libyaml-parser-emitter +====================== + +Parser and Emitter CLI tools for libyaml + +# Synopsis + +``` +make build +make test +``` + +# Usage + +Print parse events for a YAML file (or stdin): +``` +./libyaml-parser file.yaml +./libyaml-parser < file.yaml +cat file.yaml | ./libyaml-parser +``` + +Print the YAML for a libyaml-parser events file (or stdin): +``` +./libyaml-emitter file.events +./libyaml-emitter < file.events +cat file.events | ./libyaml-emitter +``` + +# Build + +``` +export LIBYAML_DIR=/path/to/libyaml # Optional +make build +``` diff --git a/tests/run-test-suite/src/libyaml-emitter.c b/tests/run-test-suite/src/libyaml-emitter.c new file mode 100644 index 0000000..6c599e8 --- /dev/null +++ b/tests/run-test-suite/src/libyaml-emitter.c @@ -0,0 +1,232 @@ +#include + +#include +#include +#include +#include + +bool get_line(FILE * input, char *line); +char *get_anchor(char sigil, char *line, char *anchor); +char *get_tag(char *line, char *tag); +void get_value(char *line, char *value, int *style); + +int main(int argc, char *argv[]) +{ + FILE *input; + yaml_emitter_t emitter; + yaml_event_t event; + + int canonical = 0; + int unicode = 0; + char line[1024]; + + if (argc == 1) + input = stdin; + else if (argc == 2) + input = fopen(argv[1], "rb"); + else { + fprintf(stderr, "Usage: libyaml-emitter []\n"); + return 1; + } + assert(input); + + if (!yaml_emitter_initialize(&emitter)) { + fprintf(stderr, "Could not initalize the emitter object\n"); + return 1; + } + yaml_emitter_set_output_file(&emitter, stdout); + yaml_emitter_set_canonical(&emitter, canonical); + yaml_emitter_set_unicode(&emitter, unicode); + + while (get_line(input, line)) { + int ok; + char anchor[256]; + char tag[256]; + int implicit; + + if (strncmp(line, "+STR", 4) == 0) { + ok = yaml_stream_start_event_initialize(&event, YAML_UTF8_ENCODING); + } + else if (strncmp(line, "-STR", 4) == 0) { + ok = yaml_stream_end_event_initialize(&event); + } + else if (strncmp(line, "+DOC", 4) == 0) { + implicit = strncmp(line, "+DOC ---", 8) != 0; + ok = yaml_document_start_event_initialize(&event, NULL, NULL, NULL, implicit); + } + else if (strncmp(line, "-DOC", 4) == 0) { + implicit = strncmp(line, "-DOC ...", 8) != 0; + ok = yaml_document_end_event_initialize(&event, implicit); + } + else if (strncmp(line, "+MAP", 4) == 0) { + ok = yaml_mapping_start_event_initialize(&event, (yaml_char_t *) + get_anchor('&', line, anchor), (yaml_char_t *) + get_tag(line, tag), 0, YAML_BLOCK_MAPPING_STYLE); + } + else if (strncmp(line, "-MAP", 4) == 0) { + ok = yaml_mapping_end_event_initialize(&event); + } + else if (strncmp(line, "+SEQ", 4) == 0) { + ok = yaml_sequence_start_event_initialize(&event, (yaml_char_t *) + get_anchor('&', line, anchor), (yaml_char_t *) + get_tag(line, tag), 0, YAML_BLOCK_SEQUENCE_STYLE); + } + else if (strncmp(line, "-SEQ", 4) == 0) { + ok = yaml_sequence_end_event_initialize(&event); + } + else if (strncmp(line, "=VAL", 4) == 0) { + char value[1024]; + int style; + + get_value(line, value, &style); + implicit = (get_tag(line, tag) == NULL); + + ok = yaml_scalar_event_initialize(&event, (yaml_char_t *) + get_anchor('&', line, anchor), (yaml_char_t *) get_tag(line, tag), (yaml_char_t *) value, -1, implicit, implicit, style); + } + else if (strncmp(line, "=ALI", 4) == 0) { + ok = yaml_alias_event_initialize(&event, (yaml_char_t *) + get_anchor('*', line, anchor) + ); + } + else { + fprintf(stderr, "Unknown event: '%s'\n", line); + fflush(stdout); + return 1; + } + + if (!ok) + goto event_error; + if (!yaml_emitter_emit(&emitter, &event)) + goto emitter_error; + } + + assert(!fclose(input)); + yaml_emitter_delete(&emitter); + fflush(stdout); + + return 0; + + emitter_error: + switch (emitter.error) { + case YAML_MEMORY_ERROR: + fprintf(stderr, "Memory error: Not enough memory for emitting\n"); + break; + case YAML_WRITER_ERROR: + fprintf(stderr, "Writer error: %s\n", emitter.problem); + break; + case YAML_EMITTER_ERROR: + fprintf(stderr, "Emitter error: %s\n", emitter.problem); + break; + default: + /* + * Couldn't happen. + */ + fprintf(stderr, "Internal error\n"); + break; + } + yaml_emitter_delete(&emitter); + return 1; + + event_error: + fprintf(stderr, "Memory error: Not enough memory for creating an event\n"); + yaml_emitter_delete(&emitter); + return 1; +} + +bool get_line(FILE * input, char *line) +{ + char *newline; + + if (!fgets(line, 1024 - 1, input)) + return false; + + if ((newline = strchr(line, '\n')) == NULL) { + fprintf(stderr, "Line too long: '%s'", line); + abort(); + } + *newline = '\0'; + + return true; +} + +char *get_anchor(char sigil, char *line, char *anchor) +{ + char *start; + char *end; + if ((start = strchr(line, sigil)) == NULL) + return NULL; + start++; + if ((end = strchr(start, ' ')) == NULL) + end = line + strlen(line); + memcpy(anchor, start, end - start); + anchor[end - start] = '\0'; + return anchor; +} + +char *get_tag(char *line, char *tag) +{ + char *start; + char *end; + if ((start = strchr(line, '<')) == NULL) + return NULL; + if ((end = strchr(line, '>')) == NULL) + return NULL; + memcpy(tag, start + 1, end - start - 1); + tag[end - start - 1] = '\0'; + return tag; +} + +void get_value(char *line, char *value, int *style) +{ + int i = 0; + char *c; + char *start = NULL; + char *end = line + strlen(line); + + for (c = line + 4; c < end; c++) { + if (*c == ' ') { + start = c + 1; + if (*start == ':') + *style = YAML_PLAIN_SCALAR_STYLE; + else if (*start == '\'') + *style = YAML_SINGLE_QUOTED_SCALAR_STYLE; + else if (*start == '"') + *style = YAML_DOUBLE_QUOTED_SCALAR_STYLE; + else if (*start == '|') + *style = YAML_LITERAL_SCALAR_STYLE; + else if (*start == '>') + *style = YAML_FOLDED_SCALAR_STYLE; + else { + start = NULL; + continue; + } + start++; + break; + } + } + if (!start) + abort(); + + for (c = start; c < end; c++) { + if (*c == '\\') { + if (*++c == '\\') + value[i++] = '\\'; + else if (*c == '0') + value[i++] = '\0'; + else if (*c == 'b') + value[i++] = '\b'; + else if (*c == 'n') + value[i++] = '\n'; + else if (*c == 'r') + value[i++] = '\r'; + else if (*c == 't') + value[i++] = '\t'; + else + abort(); + } + else + value[i++] = *c; + } + value[i] = '\0'; +} diff --git a/tests/run-test-suite/src/libyaml-parser.c b/tests/run-test-suite/src/libyaml-parser.c new file mode 100644 index 0000000..b2c7f84 --- /dev/null +++ b/tests/run-test-suite/src/libyaml-parser.c @@ -0,0 +1,144 @@ +#include +#include +#include +#include + +void print_escaped(yaml_char_t * str, size_t length); + +int main(int argc, char *argv[]) +{ + FILE *input; + yaml_parser_t parser; + yaml_event_t event; + + if (argc == 1) + input = stdin; + else if (argc == 2) + input = fopen(argv[1], "rb"); + else { + fprintf(stderr, "Usage: libyaml-parser []\n"); + return 1; + } + assert(input); + + if (!yaml_parser_initialize(&parser)) { + fprintf(stderr, "Could not initialize the parser object\n"); + return 1; + } + yaml_parser_set_input_file(&parser, input); + + while (1) { + yaml_event_type_t type; + if (!yaml_parser_parse(&parser, &event)) { + fprintf(stderr, "Parse error: %s\n", parser.problem); + return 1; + } + type = event.type; + + if (type == YAML_NO_EVENT) + printf("???\n"); + else if (type == YAML_STREAM_START_EVENT) + printf("+STR\n"); + else if (type == YAML_STREAM_END_EVENT) + printf("-STR\n"); + else if (type == YAML_DOCUMENT_START_EVENT) { + printf("+DOC"); + if (!event.data.document_start.implicit) + printf(" ---"); + printf("\n"); + } + else if (type == YAML_DOCUMENT_END_EVENT) { + printf("-DOC"); + if (!event.data.document_end.implicit) + printf(" ..."); + printf("\n"); + } + else if (type == YAML_MAPPING_START_EVENT) { + printf("+MAP"); + if (event.data.mapping_start.anchor) + printf(" &%s", event.data.mapping_start.anchor); + if (event.data.mapping_start.tag) + printf(" <%s>", event.data.mapping_start.tag); + printf("\n"); + } + else if (type == YAML_MAPPING_END_EVENT) + printf("-MAP\n"); + else if (type == YAML_SEQUENCE_START_EVENT) { + printf("+SEQ"); + if (event.data.sequence_start.anchor) + printf(" &%s", event.data.sequence_start.anchor); + if (event.data.sequence_start.tag) + printf(" <%s>", event.data.sequence_start.tag); + printf("\n"); + } + else if (type == YAML_SEQUENCE_END_EVENT) + printf("-SEQ\n"); + else if (type == YAML_SCALAR_EVENT) { + printf("=VAL"); + if (event.data.scalar.anchor) + printf(" &%s", event.data.scalar.anchor); + if (event.data.scalar.tag) + printf(" <%s>", event.data.scalar.tag); + switch (event.data.scalar.style) { + case YAML_PLAIN_SCALAR_STYLE: + printf(" :"); + break; + case YAML_SINGLE_QUOTED_SCALAR_STYLE: + printf(" '"); + break; + case YAML_DOUBLE_QUOTED_SCALAR_STYLE: + printf(" \""); + break; + case YAML_LITERAL_SCALAR_STYLE: + printf(" |"); + break; + case YAML_FOLDED_SCALAR_STYLE: + printf(" >"); + break; + case YAML_ANY_SCALAR_STYLE: + abort(); + } + print_escaped(event.data.scalar.value, event.data.scalar.length); + printf("\n"); + } + else if (type == YAML_ALIAS_EVENT) + printf("=ALI *%s\n", event.data.alias.anchor); + else + abort(); + + yaml_event_delete(&event); + + if (type == YAML_STREAM_END_EVENT) + break; + } + + assert(!fclose(input)); + yaml_parser_delete(&parser); + fflush(stdout); + + return 0; +} + +void print_escaped(yaml_char_t * str, size_t length) +{ + int i; + char c; + + for (i = 0; i < length; i++) { + c = *(str + i); + if (c == '\\') + printf("\\\\"); + else if (c == '\0') + printf("\\0"); + else if (c == '\b') + printf("\\b"); + else if (c == '\n') + printf("\\n"); + else if (c == '\r') + printf("\\r"); + else if (c == '\t') + printf("\\t"); + else + printf("%c", c); + } +} diff --git a/tests/run-test-suite/src/test/example-2.27-invoice.events b/tests/run-test-suite/src/test/example-2.27-invoice.events new file mode 100644 index 0000000..fdd1b5f --- /dev/null +++ b/tests/run-test-suite/src/test/example-2.27-invoice.events @@ -0,0 +1,59 @@ ++STR ++DOC --- ++MAP +=VAL :invoice +=VAL :34843 +=VAL :date +=VAL :2001-01-23 +=VAL :bill-to ++MAP &id001 +=VAL :given +=VAL :Chris +=VAL :family +=VAL :Dumars +=VAL :address ++MAP +=VAL :lines +=VAL |458 Walkman Dr.\nSuite #292\n +=VAL :city +=VAL :Royal Oak +=VAL :state +=VAL :MI +=VAL :postal +=VAL :48046 +-MAP +-MAP +=VAL :ship-to +=ALI *id001 +=VAL :product ++SEQ ++MAP +=VAL :sku +=VAL :BL394D +=VAL :quantity +=VAL :4 +=VAL :description +=VAL :Basketball +=VAL :price +=VAL :450.00 +-MAP ++MAP +=VAL :sku +=VAL :BL4438H +=VAL :quantity +=VAL :1 +=VAL :description +=VAL :Super Hoop +=VAL :price +=VAL :2392.00 +-MAP +-SEQ +=VAL :tax +=VAL :251.42 +=VAL :total +=VAL :4443.52 +=VAL :comments +=VAL :Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. +-MAP +-DOC +-STR diff --git a/tests/run-test-suite/src/test/example-2.27-invoice.out b/tests/run-test-suite/src/test/example-2.27-invoice.out new file mode 100644 index 0000000..1a876c9 --- /dev/null +++ b/tests/run-test-suite/src/test/example-2.27-invoice.out @@ -0,0 +1,26 @@ +--- ! +invoice: 34843 +date: 2001-01-23 +bill-to: &id001 + given: Chris + family: Dumars + address: + lines: | + 458 Walkman Dr. + Suite #292 + city: Royal Oak + state: MI + postal: 48046 +ship-to: *id001 +product: +- sku: BL394D + quantity: 4 + description: Basketball + price: 450.00 +- sku: BL4438H + quantity: 1 + description: Super Hoop + price: 2392.00 +tax: 251.42 +total: 4443.52 +comments: Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338. diff --git a/tests/run-test-suite/src/test/example-2.27-invoice.yaml b/tests/run-test-suite/src/test/example-2.27-invoice.yaml new file mode 100644 index 0000000..4625739 --- /dev/null +++ b/tests/run-test-suite/src/test/example-2.27-invoice.yaml @@ -0,0 +1,29 @@ +--- ! +invoice: 34843 +date : 2001-01-23 +bill-to: &id001 + given : Chris + family : Dumars + address: + lines: | + 458 Walkman Dr. + Suite #292 + city : Royal Oak + state : MI + postal : 48046 +ship-to: *id001 +product: + - sku : BL394D + quantity : 4 + description : Basketball + price : 450.00 + - sku : BL4438H + quantity : 1 + description : Super Hoop + price : 2392.00 +tax : 251.42 +total: 4443.52 +comments: + Late afternoon is best. + Backup contact is Nancy + Billsmer @ 338-4338. diff --git a/tests/run-test-suite/src/test/libyaml-emitter.t b/tests/run-test-suite/src/test/libyaml-emitter.t new file mode 100644 index 0000000..7afd5f0 --- /dev/null +++ b/tests/run-test-suite/src/test/libyaml-emitter.t @@ -0,0 +1,26 @@ +#!/bin/bash + +got=$(mktemp) + +count=0 +for test in test/*.events; do + want=${test//.events/.out} + label="Emitting '$test' equals '$want'" + rc=0 + ./libyaml-emitter $test > $got || rc=$? + if [[ $rc -ne 0 ]]; then + echo "not ok $((++count)) - Error code $rc" + continue + fi + rc=0 + diff=$(diff -u $want $got) || rc=$? + if [[ $rc -eq 0 ]]; then + echo "ok $((++count)) - $label" + else + echo "not ok $((++count)) - $label" + diff=${diff//$'\n'/$'\n'# } + echo "# $diff" + fi +done + +echo "1..$count" diff --git a/tests/run-test-suite/src/test/libyaml-parser.t b/tests/run-test-suite/src/test/libyaml-parser.t new file mode 100644 index 0000000..40c56da --- /dev/null +++ b/tests/run-test-suite/src/test/libyaml-parser.t @@ -0,0 +1,26 @@ +#!/bin/bash + +got=$(mktemp) + +count=0 +for test in test/*.yaml; do + want=${test//.yaml/.events} + label="Parsing '$test' equals '$want'" + rc=0 + ./libyaml-parser $test > $got || rc=$? + if [[ $rc -ne 0 ]]; then + echo "not ok $((++count)) - Error code $rc" + continue + fi + rc=0 + diff=$(diff -u $want $got) || rc=$? + if [[ $rc -eq 0 ]]; then + echo "ok $((++count)) - $label" + else + echo "not ok $((++count)) - $label" + diff=${diff//$'\n'/$'\n'# } + echo "# $diff" + fi +done + +echo "1..$count" diff --git a/tests/run-test-suite/test/libyaml-emitter.skip b/tests/run-test-suite/test/libyaml-emitter.skip new file mode 100644 index 0000000..7ceb1ce --- /dev/null +++ b/tests/run-test-suite/test/libyaml-emitter.skip @@ -0,0 +1,31 @@ +27NA # %YAML 1.2 +2JQS # Null key emission not supported in libyaml +2SXE # Colon in anchor +2XXW # Emits space after colon for null mapping value +35KP # Not adding tags to multiple docs +4ABK # Null key +5TYM # No libyaml-emitter %TAG support yet +5WE3 # Emits space after colon for null mapping value +6BCT # Tab after dash in sequence. XXX? +6CK3 # No libyaml-emitter %TAG support yet +6LVF # Unknown directive +6M2F # Null key +6ZKB # %YAML 1.2 +7W2P # Emits space after colon for null mapping value +8KHE # Emits space after colon for null mapping value +8MK2 # Emits '!<%21> a' for '! a' +C2DT # Emits space after colon for null mapping value +DFF7 # Null key +FH7J # Null key && Emits space after colon for null mapping value +FRK4 # Null key +JTV5 # Emits space after colon for null mapping value +KZN9 # Null key +LE5A # Emits space after colon for null mapping value +NHX8 # Null key +PW8X # Null key && Emits space after colon for null mapping value +S3PD # Null key +S4JQ # Emits '!<%21> a' for '! a' +UT92 # Emits space after --- for null document +W42U # Emits space after - for null sequence entry +W4TN # Emits space after --- for null document +WZ62 # Null key value diff --git a/tests/run-test-suite/test/libyaml-emitter.t b/tests/run-test-suite/test/libyaml-emitter.t new file mode 100755 index 0000000..fb8a634 --- /dev/null +++ b/tests/run-test-suite/test/libyaml-emitter.t @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -e + +if [[ $# -gt 0 ]]; then + ids=("$@") +else + ids=(`find data | grep '/===$' | cut -d/ -f2 | sort`) +fi + +# Some environments like on OS X, the shell resets the following vars, so we +# work around it like so: +export LD_LIBRARY_PATH="${MY_LD_LIBRARY_PATH:?}" +export DYLD_LIBRARY_PATH="${MY_LD_LIBRARY_PATH:?}" + +count=0 +for id in "${ids[@]}"; do + dir="data/$id" + label="$id: $(< $dir/===)" + [[ -e "$dir/in.yaml" ]] || continue + if grep "$id" test/libyaml-emitter.skip >/dev/null; then + echo "ok $((++count)) # SKIP $label" + continue + fi + want="$dir/out.yaml" + [[ -e $want ]] || want="$dir/in.yaml" + ./src/libyaml-emitter "$dir/test.event" > /tmp/test.out || { + ( + cat "$dir/test.event" + cat "$want" + ) | sed 's/^/# /' + } + ok=true + output="$(${DIFF:-diff} -u $want /tmp/test.out)" || ok=false + if $ok; then + echo "ok $((++count)) $label" + else + echo "not ok $((++count)) $label" + echo "$output" | sed 's/^/# /' + fi +done + +echo "1..$count" diff --git a/tests/run-test-suite/test/libyaml-parser.skip b/tests/run-test-suite/test/libyaml-parser.skip new file mode 100644 index 0000000..35f7e9b --- /dev/null +++ b/tests/run-test-suite/test/libyaml-parser.skip @@ -0,0 +1,22 @@ +27NA # %YAML 1.2 +2JQS # Null keys +2SXE # Colon in anchor +4ABK # Null key +6BCT # Test probably bad. tab after dash in sequence +6LVF # Unknown directive +6M2F # Null key +6ZKB # %YAML 1.2 +A2M4 # Tab after dash in sequence. XXX? +BEC7 # %YAML 1.3 +DBG4 # Colon in flow scalar +FRK4 # XXX Why is explicit key in flow? +KZN9 # Null key +M7A3 # libyaml wants explicit --- for docs after ... +N782 # --- and ... as flow values +NHX8 # Null key +R4YG # Tab char in possible indentation in folded scalar +RTP8 # %YAML 1.2 +S3PD # Null key +UT92 # Multiline plain key in flow does not work +W4TN # %YAML 1.2 +WZ62 # Tagged empty values in flow mapping do not work diff --git a/tests/run-test-suite/test/libyaml-parser.t b/tests/run-test-suite/test/libyaml-parser.t new file mode 100755 index 0000000..c891df9 --- /dev/null +++ b/tests/run-test-suite/test/libyaml-parser.t @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -e + +if [[ $# -gt 0 ]]; then + ids=("$@") +else + ids=(`find data | grep '/===$' | cut -d/ -f2 | sort`) +fi + +count=0 +for id in "${ids[@]}"; do + dir="data/$id" + label="$id: $(< $dir/===)" + [[ -e "$dir/in.yaml" ]] || continue + if grep "$id" test/libyaml-parser.skip >/dev/null; then + echo "ok $((++count)) # SKIP $label" + continue + fi + ./src/libyaml-parser "$dir/in.yaml" > /tmp/test.out || { + ( + cat "$dir/in.yaml" + cat "$dir/test.event" + ) | sed 's/^/# /' + } + ok=true + output="$(${DIFF:-diff} -u $dir/test.event /tmp/test.out)" || ok=false + if $ok; then + echo "ok $((++count)) $label" + else + echo "not ok $((++count)) $label" + echo "$output" | sed 's/^/# /' + fi +done + +echo "1..$count" diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 6ef04a1..3336900 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -3,28 +3,24 @@ set -e main() { - bootstrap + clean + ./bootstrap + ./configure make test-all clean cmake . - make make test -} -bootstrap() { clean - - ./bootstrap - ./configure } clean() { git clean -d -x -f - rm -fr libyaml-test + rm -fr tests/run-test-suite/data } main "$@" -- 2.45.1