diff options
author | Tina Müller <cpan2@tinita.de> | 2017-12-02 01:06:12 +0100 |
---|---|---|
committer | Tina Müller <cpan2@tinita.de> | 2017-12-02 22:23:23 +0100 |
commit | a6b251f1a7f46d0847bf58a3f61997b31f841434 (patch) | |
tree | 4944954bbfbb809ab74c84306ff6b35a94c6d1ce | |
parent | 87ac917f13bae9221af073183152e0fce34f41e3 (diff) | |
download | libyaml-git-a6b251f1a7f46d0847bf58a3f61997b31f841434.tar.gz |
Rewrite make test-suite
No recursive make anymore
Remove MY_LD_LIBRARY_PATH and friends
This is now done by the wrapper script
Remove LIBYAML_DIR variable
not needed anymore
Merge ReadMe.md files to one
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | ReadMe.md | 22 | ||||
-rw-r--r-- | src/Makefile | 54 | ||||
-rw-r--r-- | src/ReadMe.md | 34 | ||||
-rw-r--r-- | src/libyaml-emitter.c | 232 | ||||
-rw-r--r-- | src/libyaml-parser.c | 144 | ||||
-rwxr-xr-x | test/libyaml-emitter.t | 7 | ||||
-rwxr-xr-x | test/libyaml-parser.t | 2 |
8 files changed, 24 insertions, 485 deletions
@@ -1,7 +1,6 @@ .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 @@ -10,11 +9,8 @@ help: @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) +test: data + prove -lv test clean: rm -fr data @@ -22,9 +18,3 @@ clean: data: git clone $(TEST_SUITE_URL) $@ --branch=$@ -%/libyaml-parser %/libyaml-emitter: % - (cd $<; make clean build) - (cd $<; make clean build) - -libyaml-parser-emitter: - git clone $(GITHUB_ORG_URI)/$@ $@ @@ -1,17 +1,35 @@ LibYAML Test Runner =================== -Run libyaml-parser and libyaml-emitter against yaml-test-suite +Run run-parser-test-suite and run-emitter-test-suite against yaml-test-suite # Synopsis ``` make test +# Run tests from yaml-test-suite +make test-suite ``` # Overview See: -* https://github.com/yaml/libyaml * https://github.com/yaml/yaml-test-suite + +# Usage + +Print parse events for a YAML file (or stdin): +``` +../run-parser-test-suite file.yaml +../run-parser-test-suite < file.yaml +cat file.yaml | ../run-parser-test-suite +``` + +Print the YAML for a libyaml-parser events file (or stdin): +``` +../run-emitter-test-suite file.events +../run-emitter-test-suite < file.events +cat file.events | ../libyaml-run-test-suite +``` + diff --git a/src/Makefile b/src/Makefile deleted file mode 100644 index de0d49a..0000000 --- a/src/Makefile +++ /dev/null @@ -1,54 +0,0 @@ -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/src/ReadMe.md b/src/ReadMe.md deleted file mode 100644 index ced29cb..0000000 --- a/src/ReadMe.md +++ /dev/null @@ -1,34 +0,0 @@ -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/src/libyaml-emitter.c b/src/libyaml-emitter.c deleted file mode 100644 index 6c599e8..0000000 --- a/src/libyaml-emitter.c +++ /dev/null @@ -1,232 +0,0 @@ -#include <yaml.h> - -#include <stdlib.h> -#include <stdio.h> -#include <stdbool.h> -#include <assert.h> - -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 [<input-file>]\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/src/libyaml-parser.c b/src/libyaml-parser.c deleted file mode 100644 index b2c7f84..0000000 --- a/src/libyaml-parser.c +++ /dev/null @@ -1,144 +0,0 @@ -#include <yaml.h> -#include <stdlib.h> -#include <stdio.h> -#include <assert.h> - -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 [<input-file>]\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/test/libyaml-emitter.t b/test/libyaml-emitter.t index 2b12b3a..b092c6f 100755 --- a/test/libyaml-emitter.t +++ b/test/libyaml-emitter.t @@ -8,11 +8,6 @@ else ids=($(cut -d: -f1 < test/libyaml-emitter.list)) 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" @@ -20,7 +15,7 @@ for id in "${ids[@]}"; do [[ -e "$dir/in.yaml" ]] || continue want="$dir/out.yaml" [[ -e $want ]] || want="$dir/in.yaml" - ./src/libyaml-emitter "$dir/test.event" > /tmp/test.out || { + ../../tests/run-emitter-test-suite "$dir/test.event" > /tmp/test.out || { ( cat "$dir/test.event" cat "$want" diff --git a/test/libyaml-parser.t b/test/libyaml-parser.t index 1c3d0c4..6be2395 100755 --- a/test/libyaml-parser.t +++ b/test/libyaml-parser.t @@ -13,7 +13,7 @@ for id in "${ids[@]}"; do dir="data/$id" label="$id: $(< $dir/===)" [[ -e "$dir/in.yaml" ]] || continue - ./src/libyaml-parser "$dir/in.yaml" > /tmp/test.out || { + ../../tests/run-parser-test-suite "$dir/in.yaml" > /tmp/test.out || { ( cat "$dir/in.yaml" cat "$dir/test.event" |