From 73d05d80ae2c22a82439fc0cc4dc1fbfdc2bb1fa Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 5 Sep 2016 16:58:58 +0200 Subject: [PATCH 1/6] Remove version part from IDs --- imag-link/tests/link-test.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh index 31599cb8..3722565d 100644 --- a/imag-link/tests/link-test.sh +++ b/imag-link/tests/link-test.sh @@ -31,13 +31,13 @@ mktestentry() { } test_link_modificates() { - mktestentry "test~0.2.0" - mktestentry "test2~0.2.0" + mktestentry "test" + mktestentry "test2" - imag-link internal add --from "test~0.2.0" --to "test2~0.2.0" + imag-link internal add --from "test" --to "test2" - if [[ "$(default_entry)" -eq "$(cat_entry 'test~0.2.0')" ]] || - [[ "$(default_entry)" -eq "$(cat_entry 'test2~0.2.0')" ]] + if [[ "$(default_entry)" -eq "$(cat_entry 'test')" ]] || + [[ "$(default_entry)" -eq "$(cat_entry 'test2')" ]] then err "Entry was unmodified after linking" return 1; @@ -45,21 +45,21 @@ test_link_modificates() { } test_linking_links() { - mktestentry "test~0.2.0" - mktestentry "test2~0.2.0" + mktestentry "test" + mktestentry "test2" - imag-link internal add --from "test~0.2.0" --to "test2~0.2.0" + imag-link internal add --from "test" --to "test2" - if [[ "$(entry_linked_to '/test~0.2.0')" == "$(cat_entry 'test2~0.2.0')" ]]; + if [[ "$(entry_linked_to '/test')" == "$(cat_entry 'test2')" ]]; then - err "Linking to 'test~0.2.0' didn't succeed for 'test2~0.2.0'" - err $(cat_entry 'test2~0.2.0') + err "Linking to 'test' didn't succeed for 'test2'" + err $(cat_entry 'test2') fi - if [[ "$(entry_linked_to '/test2~0.2.0')" == "$(cat_entry 'test~0.2.0')" ]]; + if [[ "$(entry_linked_to '/test2')" == "$(cat_entry 'test')" ]]; then - err "Linking to 'test2~0.2.0' didn't succeed for 'test~0.2.0'" - err $(cat_entry 'test~0.2.0') + err "Linking to 'test2' didn't succeed for 'test'" + err $(cat_entry 'test') fi } From 47c5b7edf32c63f1893ee63262f71c28adedd68e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 5 Sep 2016 17:01:00 +0200 Subject: [PATCH 2/6] Fix string-compare --- imag-link/tests/link-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh index 3722565d..de7ff1e6 100644 --- a/imag-link/tests/link-test.sh +++ b/imag-link/tests/link-test.sh @@ -36,8 +36,8 @@ test_link_modificates() { imag-link internal add --from "test" --to "test2" - if [[ "$(default_entry)" -eq "$(cat_entry 'test')" ]] || - [[ "$(default_entry)" -eq "$(cat_entry 'test2')" ]] + if [ "$(default_entry)" == "$(cat_entry 'test')" ] || + [ "$(default_entry)" == "$(cat_entry 'test2')" ] then err "Entry was unmodified after linking" return 1; From 60de2eefec47df2a9fbbaaaa1fecb3a2df76631a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 6 Sep 2016 10:06:28 +0200 Subject: [PATCH 3/6] Fix store id specification --- imag-link/tests/link-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh index de7ff1e6..c11864a5 100644 --- a/imag-link/tests/link-test.sh +++ b/imag-link/tests/link-test.sh @@ -50,13 +50,13 @@ test_linking_links() { imag-link internal add --from "test" --to "test2" - if [[ "$(entry_linked_to '/test')" == "$(cat_entry 'test2')" ]]; + if [[ "$(entry_linked_to 'test')" == "$(cat_entry 'test2')" ]]; then err "Linking to 'test' didn't succeed for 'test2'" err $(cat_entry 'test2') fi - if [[ "$(entry_linked_to '/test2')" == "$(cat_entry 'test')" ]]; + if [[ "$(entry_linked_to 'test2')" == "$(cat_entry 'test')" ]]; then err "Linking to 'test2' didn't succeed for 'test'" err $(cat_entry 'test') From 2e6f833bf213cdc83073a03676820508f81a7faf Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 6 Sep 2016 10:26:47 +0200 Subject: [PATCH 4/6] Add test for linking the same entries twice --- imag-link/tests/link-test.sh | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh index c11864a5..9de309ac 100644 --- a/imag-link/tests/link-test.sh +++ b/imag-link/tests/link-test.sh @@ -63,7 +63,38 @@ test_linking_links() { fi } +test_multilinking() { + mktestentry "test" + mktestentry "test2" + + imag-link internal add --from "test" --to "test2" || { + err "Linking failed"; return 1 + } + + imag-link internal add --from "test" --to "test2" || { + err "Linking again failed"; return 1 + } + + local linked_to_test="$(entry_linked_to '"test"' | sha1sum)" + local linked_to_test2="$(entry_linked_to '"test2"' | sha1sum)" + local t2="$(cat_entry 'test2' | sha1sum)" + local t1="$(cat_entry 'test' | sha1sum)" + + if [ "${linked_to_test}" != "${t2}" ]; + then + err "Linking twice to 'test' didn't result in the expected output for 'test2'" + err "\n$(cat_entry 'test2')\n" + fi + + if [ "${linked_to_test2}" != "${t1}" ]; + then + err "Linking twice to 'test2' didn't result in the expected output for 'test'" + err "\n$(cat_entry 'test')\n" + fi +} + invoke_tests \ test_link_modificates \ - test_linking_links + test_linking_links \ + test_multilinking From 584ac3d46ed184db2e8aab4e6e537629ffe3a271 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 6 Sep 2016 10:45:36 +0200 Subject: [PATCH 5/6] Fix link test to check properly --- imag-link/tests/link-test.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imag-link/tests/link-test.sh b/imag-link/tests/link-test.sh index 9de309ac..1f422f96 100644 --- a/imag-link/tests/link-test.sh +++ b/imag-link/tests/link-test.sh @@ -50,16 +50,16 @@ test_linking_links() { imag-link internal add --from "test" --to "test2" - if [[ "$(entry_linked_to 'test')" == "$(cat_entry 'test2')" ]]; + if [[ "$(entry_linked_to '"test"')" != "$(cat_entry 'test2')" ]]; then err "Linking to 'test' didn't succeed for 'test2'" - err $(cat_entry 'test2') + err "\n$(cat_entry 'test2')\n" fi - if [[ "$(entry_linked_to 'test2')" == "$(cat_entry 'test')" ]]; + if [[ "$(entry_linked_to '"test2"')" != "$(cat_entry 'test')" ]]; then err "Linking to 'test2' didn't succeed for 'test'" - err $(cat_entry 'test') + err "\n$(cat_entry 'test')\n" fi } From 40014051ec7a451412ab39790971dcab83bd88e5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 6 Sep 2016 10:56:23 +0200 Subject: [PATCH 6/6] Bugfix: unique()ing the list of links That should happen _after_ they are all in the same format. This commit introduces overhead, as we clone() each string here for comparison and that should clearly be fixed. Though the bug-fix is more important at this point. --- libimagentrylink/src/internal.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libimagentrylink/src/internal.rs b/libimagentrylink/src/internal.rs index e6dddb6f..54d2b7de 100644 --- a/libimagentrylink/src/internal.rs +++ b/libimagentrylink/src/internal.rs @@ -100,8 +100,13 @@ impl InternalLinker for Entry { fn links_into_values(links: Vec) -> Vec> { links .into_iter() - .unique() .map(|s| s.without_base().to_str().map_err_into(LEK::InternalConversionError)) + .unique_by(|entry| { + match entry { + &Ok(ref e) => Some(e.clone()), + &Err(_) => None, + } + }) .map(|elem| elem.map(Value::String)) .sorted_by(|a, b| { match (a, b) {