From b001c76434145350b4e4baa0e78e46188c852081 Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Fri, 22 Oct 2021 05:04:57 -0700 Subject: [PATCH 1/9] Add Dockerfile and Docker usage instructions * Added Dockerfile to build minimal, multi-stage image * Updated README with build instructions Recording of local build/test: https://asciinema.org/a/Ql7Xc5fgxxvkFrjjcuMbR0npY Currently builds image size 85.8MB from local build on macOS ``` docker images REPOSITORY TAG IMAGE ID CREATED SIZE ion-cli 0.1.1 e81a9d863b95 49 minutes ago 85.8MB ``` --- .dockerignore | 8 ++++++++ Dockerfile | 13 +++++++++++++ README.md | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..8b160cc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +/target +/.idea + +*.md + +Dockerfile +LICENSE +NOTICE diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3017ee6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM rust:1.56-slim as builder +ENV builddeps="cmake git gcc g++ clang" +WORKDIR /usr/src/ion-cli +COPY . . +RUN apt-get update -y \ + && apt-get install -y ${builddeps} \ + && git submodule update --init --recursive +RUN cargo install --path . + +FROM debian:11.1-slim +COPY --from=builder /usr/local/cargo/bin/ion /usr/bin/ion +CMD /usr/bin/ion +VOLUME /data diff --git a/README.md b/README.md index dc3b744..5a1d967 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,39 @@ and the API is subject to change._ ion help ``` +### Docker Instructions + +1. Clone the repository (recursive clone not necessary) + ``` + git clone https://github.com/amzn/ion-cli.git + ``` +2. Step into the newly created directory + ``` + cd ion-cli + ``` +3. Install Docker (see OS specific instructions on the [Docker website](https://docs.docker.com/get-docker/)) +4. Build and run the image + ``` + # build the image + docker build -t : . + + + # run the CLI binary inside the Docker image + docker run -it --rm [optional flags...] : ion + + # examples: + + # build docker image with current release version + docker build -t ion-cli:0.1.1 . + + # print the help message + docker run -it --rm ion-cli:0.1.1 ion -V + + # mount current directory to /data volume and dump an ion file + docker run -it --rm -v $PWD:/data ion-cli:0.1.1 ion dump /data/test.ion + + ``` + ## Security See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. From 37bbc9b597b428ba0503bd5fbac365b1620d4372 Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Fri, 22 Oct 2021 05:27:29 -0700 Subject: [PATCH 2/9] Remove unnecessary gcc, g++ deps in builder img --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3017ee6..0cb1812 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM rust:1.56-slim as builder -ENV builddeps="cmake git gcc g++ clang" +ENV builddeps="cmake git clang" WORKDIR /usr/src/ion-cli COPY . . RUN apt-get update -y \ From 3d384f24bdc7d5c0446cd29a838d137d34a5704b Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Mon, 1 Nov 2021 21:38:53 -0700 Subject: [PATCH 3/9] Add build workflow, cleanup README --- .github/workflows/verify-docker-build.yml | 26 +++++++++++++++++++++++ Dockerfile | 2 +- README.md | 8 +++---- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/verify-docker-build.yml diff --git a/.github/workflows/verify-docker-build.yml b/.github/workflows/verify-docker-build.yml new file mode 100644 index 0000000..4a9e403 --- /dev/null +++ b/.github/workflows/verify-docker-build.yml @@ -0,0 +1,26 @@ +name: Verify Docker image builds +on: + push: + branches: + - master + + pull_request: + branches: + - master + +jobs: + push_to_registry: + name: Build docker image + runs-on: ubuntu-20.04 + steps: + - + name: Checkout repository + uses: actions/checkout@v2 + - + name: Setup Docker buildx + uses: docker/setup-buildx-action@v1 + - + name: Build image + run: docker buildx build -t ion-cli:test-build . + + diff --git a/Dockerfile b/Dockerfile index 0cb1812..faad53e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.56-slim as builder +FROM rust:1.56.1-slim-buster as builder ENV builddeps="cmake git clang" WORKDIR /usr/src/ion-cli COPY . . diff --git a/README.md b/README.md index 5a1d967..9e6a0cb 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ and the API is subject to change._ ``` This will put a copy of the `ion` executable in `~/.cargo/bin`. - **If this step fails:** You're likely missing one of `ion-c`'s dependencies. Make sure you have `cmake`, `gcc`, `g++`, and `libc++` installed. + **If this step fails:** You're likely missing one of `ion-c`'s dependencies. Make sure you have `cmake` and `clang` installed. 5. Confirm that `~/.cargo/bin` is on your `$PATH`. `rustup` will probably take care of this for you. @@ -35,15 +35,15 @@ and the API is subject to change._ ### Docker Instructions -1. Clone the repository (recursive clone not necessary) +1. Install Docker (see OS specific instructions on the [Docker website](https://docs.docker.com/get-docker/)) +2. Clone the repository (recursive clone not necessary) ``` git clone https://github.com/amzn/ion-cli.git ``` -2. Step into the newly created directory +3. Step into the newly created directory ``` cd ion-cli ``` -3. Install Docker (see OS specific instructions on the [Docker website](https://docs.docker.com/get-docker/)) 4. Build and run the image ``` # build the image From 5126b11c76cff3d256ef28e0f13cbdfb9400b1c8 Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Mon, 1 Nov 2021 21:48:52 -0700 Subject: [PATCH 4/9] Test: intentionally break build --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index faad53e..1a66ecd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM rust:1.56.1-slim-buster as builder -ENV builddeps="cmake git clang" +ENV builddeps="cmake git" WORKDIR /usr/src/ion-cli COPY . . RUN apt-get update -y \ From 16cf2b2732a14d83326527df5ce0bf6aad6990bb Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Mon, 1 Nov 2021 21:52:37 -0700 Subject: [PATCH 5/9] Fix build: re-add clang dep --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 1a66ecd..faad53e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM rust:1.56.1-slim-buster as builder -ENV builddeps="cmake git" +ENV builddeps="cmake git clang" WORKDIR /usr/src/ion-cli COPY . . RUN apt-get update -y \ From 2dae6ea636f8d21ee73335f64b519ca48237682d Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Mon, 1 Nov 2021 21:59:49 -0700 Subject: [PATCH 6/9] Add note about Debian dependencies to README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e6a0cb..a10b2ea 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ and the API is subject to change._ ``` This will put a copy of the `ion` executable in `~/.cargo/bin`. - **If this step fails:** You're likely missing one of `ion-c`'s dependencies. Make sure you have `cmake` and `clang` installed. + **If this step fails:** You're likely missing one of `ion-c`'s dependencies. Make sure you have `cmake`, `gcc`, `g++` and `clang` installed. On Debian-based Linux distributions, the only required dependencies are `cmake` and `clang`. 5. Confirm that `~/.cargo/bin` is on your `$PATH`. `rustup` will probably take care of this for you. From 7cae48365f1e527e1bd6a39c9bca8c36f504f4e0 Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Sun, 7 Nov 2021 22:42:03 -0700 Subject: [PATCH 7/9] Add basic, runnable tests --- Cargo.lock | 264 ++++++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 9 +- tests/cli.rs | 120 +++++++++++++++++++++++ 3 files changed, 380 insertions(+), 13 deletions(-) create mode 100644 tests/cli.rs diff --git a/Cargo.lock b/Cargo.lock index ad62490..77fbaea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,5 +1,7 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +version = 3 + [[package]] name = "aho-corasick" version = "0.7.15" @@ -21,6 +23,26 @@ version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "assert_cmd" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c98233c6673d8601ab23e77eb38f999c51100d46c5703b17288c57fddf3a1ffe" +dependencies = [ + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + [[package]] name = "atty" version = "0.2.14" @@ -91,6 +113,29 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "bitvec" +version = "0.19.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8942c8d352ae1838c9dda0b0ca2ab657696ef2232a20147cf1b30ae1a9cb4321" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", +] + [[package]] name = "byteorder" version = "1.4.2" @@ -119,7 +164,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27" dependencies = [ - "nom", + "nom 5.1.2", ] [[package]] @@ -204,6 +249,24 @@ dependencies = [ "syn", ] +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "env_logger" version = "0.7.1" @@ -217,6 +280,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "funty" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" + [[package]] name = "getrandom" version = "0.2.2" @@ -271,20 +340,22 @@ name = "ion-cli" version = "0.1.1" dependencies = [ "anyhow", + "assert_cmd", "clap", "cmake", "colored", "ion-rs", "libc", "memmap", + "rstest", "tempfile", ] [[package]] name = "ion-rs" -version = "0.3.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4041afcc61aa4e57c5b11dc3d0dee9bff91012b524a5f8140511d9ccc5768d46" +checksum = "f9b5511aa03f80ded9dd90d0244770cd7280a8eea1546fa25ea8f3e4dad0a541" dependencies = [ "base64", "bigdecimal", @@ -292,6 +363,9 @@ dependencies = [ "chrono", "delegate", "ion-c-sys", + "nom 6.1.2", + "num-bigint", + "num-traits", "thiserror", ] @@ -304,6 +378,15 @@ dependencies = [ "libc", ] +[[package]] +name = "itertools" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" +dependencies = [ + "either", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -316,6 +399,19 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" +[[package]] +name = "lexical-core" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe" +dependencies = [ + "arrayvec", + "bitflags 1.2.1", + "cfg-if 1.0.0", + "ryu", + "static_assertions", +] + [[package]] name = "libc" version = "0.2.83" @@ -343,9 +439,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.3.4" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "memmap" @@ -367,6 +463,19 @@ dependencies = [ "version_check", ] +[[package]] +name = "nom" +version = "6.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2" +dependencies = [ + "bitvec", + "funty", + "lexical-core", + "memchr", + "version_check", +] + [[package]] name = "num-bigint" version = "0.3.1" @@ -415,17 +524,53 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + [[package]] name = "ppv-lite86" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "predicates" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c6ce811d0b2e103743eec01db1c50612221f173084ce2f7941053e94b6bb474" +dependencies = [ + "difflib", + "itertools", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" + +[[package]] +name = "predicates-tree" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "338c7be2905b732ae3984a2f40032b5e94fd8f52505b186c7d4d68d193445df7" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" dependencies = [ "unicode-xid", ] @@ -438,13 +583,19 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" +checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" dependencies = [ "proc-macro2", ] +[[package]] +name = "radium" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8" + [[package]] name = "rand" version = "0.8.3" @@ -506,6 +657,12 @@ dependencies = [ "thread_local", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.22" @@ -521,18 +678,70 @@ dependencies = [ "winapi", ] +[[package]] +name = "rstest" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "041bb0202c14f6a158bbbf086afb03d0c6e975c2dec7d4912f8061ed44f290af" +dependencies = [ + "cfg-if 1.0.0", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "shlex" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strsim" version = "0.6.0" @@ -541,15 +750,21 @@ checksum = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" [[package]] name = "syn" -version = "1.0.60" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" +checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966" dependencies = [ "proc-macro2", "quote", "unicode-xid", ] +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tempfile" version = "3.2.0" @@ -573,6 +788,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termtree" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13a4ec180a2de59b57434704ccfad967f789b12737738798fa08798cd5824c16" + [[package]] name = "textwrap" version = "0.9.0" @@ -621,6 +842,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + [[package]] name = "unicode-width" version = "0.1.8" @@ -645,6 +872,15 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" @@ -690,3 +926,9 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" diff --git a/Cargo.toml b/Cargo.toml index f9135d5..306edbf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ keywords = ["format", "parse", "encode"] anyhow = "1.0" clap = "~2.27.0" colored = "2.0.0" -ion-rs = "0.3.1" +ion-rs = "~0.6.0" libc = "0.2" memmap = "0.7.0" tempfile = "3.2.0" @@ -23,7 +23,12 @@ tempfile = "3.2.0" [build-dependencies] cmake = "0.1.44" +[dev-dependencies] +rstest = "~0.10.0" +assert_cmd = "~1.0.5" +tempfile = "~3.2.0" + [[bin]] name = "ion" -test = false +test = true bench = false diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 0000000..1b8b20c --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,120 @@ +use anyhow::Result; +use ion_rs::value::owned::OwnedElement; +use ion_rs::value::reader::*; +use rstest::*; +use std::fs::File; +use std::io::{Read, Write}; +use std::time::Duration; +use tempfile::TempDir; +use assert_cmd::Command; + +enum FileMode { + /// Use `STDIN` or `STDOUT` + Default, + /// Use a named file + Named, +} + +struct TestCase> { + /// The text of the ion grammar to test + ion_text: S, + /// The expected Ion + expected_ion: OwnedElement, +} + +impl From<(&'static str, &'static str)> for TestCase<&'static str> { + /// Simple conversion for static `str` slices into a test case + fn from((ion_text, expected_ion): (&'static str, &'static str)) -> Self { + let expected_ion = element_reader().read_one(expected_ion.as_bytes()).unwrap(); + Self { + ion_text, + expected_ion + } + } +} + +#[rstest] +#[case::simple(( +r#" +{ + name: "Fido" +} +"#, +r#" +{ + name: "Fido" +} +"# +).into())] +fn run_it>( + #[case] test_case: TestCase, +#[values("", "binary", "text", "pretty")] format_flag: &str, +#[values(FileMode::Default, FileMode::Named)] input_mode: FileMode, +#[values(FileMode::Default, FileMode::Named)] output_mode: FileMode +) -> Result<()> { + + let TestCase { + ion_text, + expected_ion + } = test_case; + + let temp_dir = TempDir::new()?; + let input_path = temp_dir.path().join("INPUT.ion"); + let output_path = temp_dir.path().join("OUTPUT.ion"); + + let mut cmd = Command::cargo_bin("ion")?; + cmd.arg("dump").timeout(Duration::new(5, 0)); + if format_flag != "" { + cmd.arg("-f"); + cmd.arg(format_flag); + } + match output_mode { + FileMode::Default => { + // do nothing + }, + FileMode::Named => { + // tell driver to output to a file + cmd.arg("-o"); + cmd.arg(&output_path); + } + }; + + match input_mode { + FileMode::Default => { + // do nothing + cmd.write_stdin(ion_text.as_ref()); + }, + FileMode::Named => { + // dump our test data to input file + let mut input_file = File::create(&input_path)?; + input_file.write(ion_text.as_ref().as_bytes())?; + input_file.flush()?; + + // TODO: test multiple input files + + // make this the input for our driver + cmd.arg(input_path.to_str().unwrap()); + + } + }; + + let assert = cmd.assert(); + + let actual_ion = match output_mode { + FileMode::Default => { + let output = assert.get_output(); + element_reader().read_one(&output.stdout)? + } + FileMode::Named => { + let mut output_file = File::open(output_path)?; + let mut output_buffer = vec![]; + output_file.read_to_end(&mut output_buffer)?; + element_reader().read_one(&output_buffer)? + } + }; + + assert_eq!(expected_ion, actual_ion); + assert.success(); + + Ok(()) +} \ No newline at end of file From 6c5218a5c767c735e47a937c35e6f02331b63fcb Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Sun, 21 Nov 2021 22:58:04 -0700 Subject: [PATCH 8/9] Update ion-rs version, ion-c submodule and Dockerfile --- Cargo.lock | 157 --------------------------------------------------- Cargo.toml | 7 +-- Dockerfile | 2 +- ion-c | 2 +- tests/cli.rs | 120 --------------------------------------- 5 files changed, 3 insertions(+), 285 deletions(-) delete mode 100644 tests/cli.rs diff --git a/Cargo.lock b/Cargo.lock index 77fbaea..f56486f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,20 +29,6 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" -[[package]] -name = "assert_cmd" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c98233c6673d8601ab23e77eb38f999c51100d46c5703b17288c57fddf3a1ffe" -dependencies = [ - "bstr", - "doc-comment", - "predicates", - "predicates-core", - "predicates-tree", - "wait-timeout", -] - [[package]] name = "atty" version = "0.2.14" @@ -125,17 +111,6 @@ dependencies = [ "wyz", ] -[[package]] -name = "bstr" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" -dependencies = [ - "lazy_static", - "memchr", - "regex-automata", -] - [[package]] name = "byteorder" version = "1.4.2" @@ -249,24 +224,6 @@ dependencies = [ "syn", ] -[[package]] -name = "difflib" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" - -[[package]] -name = "doc-comment" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" - -[[package]] -name = "either" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" - [[package]] name = "env_logger" version = "0.7.1" @@ -340,14 +297,12 @@ name = "ion-cli" version = "0.1.1" dependencies = [ "anyhow", - "assert_cmd", "clap", "cmake", "colored", "ion-rs", "libc", "memmap", - "rstest", "tempfile", ] @@ -378,15 +333,6 @@ dependencies = [ "libc", ] -[[package]] -name = "itertools" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" -dependencies = [ - "either", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -524,48 +470,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - [[package]] name = "ppv-lite86" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" -[[package]] -name = "predicates" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c6ce811d0b2e103743eec01db1c50612221f173084ce2f7941053e94b6bb474" -dependencies = [ - "difflib", - "itertools", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451" - -[[package]] -name = "predicates-tree" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "338c7be2905b732ae3984a2f40032b5e94fd8f52505b186c7d4d68d193445df7" -dependencies = [ - "predicates-core", - "termtree", -] - [[package]] name = "proc-macro2" version = "1.0.32" @@ -657,12 +567,6 @@ dependencies = [ "thread_local", ] -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" - [[package]] name = "regex-syntax" version = "0.6.22" @@ -678,58 +582,18 @@ dependencies = [ "winapi", ] -[[package]] -name = "rstest" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "041bb0202c14f6a158bbbf086afb03d0c6e975c2dec7d4912f8061ed44f290af" -dependencies = [ - "cfg-if 1.0.0", - "proc-macro2", - "quote", - "rustc_version", - "syn", -] - [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" -[[package]] -name = "rustc_version" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" -dependencies = [ - "semver", -] - [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" -[[package]] -name = "semver" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] - [[package]] name = "shlex" version = "0.1.1" @@ -788,12 +652,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "termtree" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13a4ec180a2de59b57434704ccfad967f789b12737738798fa08798cd5824c16" - [[package]] name = "textwrap" version = "0.9.0" @@ -842,12 +700,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "ucd-trie" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" - [[package]] name = "unicode-width" version = "0.1.8" @@ -872,15 +724,6 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" -[[package]] -name = "wait-timeout" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" -dependencies = [ - "libc", -] - [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index 306edbf..71ef7f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,12 +23,7 @@ tempfile = "3.2.0" [build-dependencies] cmake = "0.1.44" -[dev-dependencies] -rstest = "~0.10.0" -assert_cmd = "~1.0.5" -tempfile = "~3.2.0" - [[bin]] name = "ion" -test = true +test = false bench = false diff --git a/Dockerfile b/Dockerfile index faad53e..4e08413 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,7 @@ COPY . . RUN apt-get update -y \ && apt-get install -y ${builddeps} \ && git submodule update --init --recursive -RUN cargo install --path . +RUN cargo install --verbose --path . FROM debian:11.1-slim COPY --from=builder /usr/local/cargo/bin/ion /usr/bin/ion diff --git a/ion-c b/ion-c index a9af6be..a1a953c 160000 --- a/ion-c +++ b/ion-c @@ -1 +1 @@ -Subproject commit a9af6be3f2ed38d4775257adfa5672c845cac361 +Subproject commit a1a953c7315a80c124269e5d2392fe5fe60bef04 diff --git a/tests/cli.rs b/tests/cli.rs deleted file mode 100644 index 1b8b20c..0000000 --- a/tests/cli.rs +++ /dev/null @@ -1,120 +0,0 @@ -use anyhow::Result; -use ion_rs::value::owned::OwnedElement; -use ion_rs::value::reader::*; -use rstest::*; -use std::fs::File; -use std::io::{Read, Write}; -use std::time::Duration; -use tempfile::TempDir; -use assert_cmd::Command; - -enum FileMode { - /// Use `STDIN` or `STDOUT` - Default, - /// Use a named file - Named, -} - -struct TestCase> { - /// The text of the ion grammar to test - ion_text: S, - /// The expected Ion - expected_ion: OwnedElement, -} - -impl From<(&'static str, &'static str)> for TestCase<&'static str> { - /// Simple conversion for static `str` slices into a test case - fn from((ion_text, expected_ion): (&'static str, &'static str)) -> Self { - let expected_ion = element_reader().read_one(expected_ion.as_bytes()).unwrap(); - Self { - ion_text, - expected_ion - } - } -} - -#[rstest] -#[case::simple(( -r#" -{ - name: "Fido" -} -"#, -r#" -{ - name: "Fido" -} -"# -).into())] -fn run_it>( - #[case] test_case: TestCase, -#[values("", "binary", "text", "pretty")] format_flag: &str, -#[values(FileMode::Default, FileMode::Named)] input_mode: FileMode, -#[values(FileMode::Default, FileMode::Named)] output_mode: FileMode -) -> Result<()> { - - let TestCase { - ion_text, - expected_ion - } = test_case; - - let temp_dir = TempDir::new()?; - let input_path = temp_dir.path().join("INPUT.ion"); - let output_path = temp_dir.path().join("OUTPUT.ion"); - - let mut cmd = Command::cargo_bin("ion")?; - cmd.arg("dump").timeout(Duration::new(5, 0)); - if format_flag != "" { - cmd.arg("-f"); - cmd.arg(format_flag); - } - match output_mode { - FileMode::Default => { - // do nothing - }, - FileMode::Named => { - // tell driver to output to a file - cmd.arg("-o"); - cmd.arg(&output_path); - } - }; - - match input_mode { - FileMode::Default => { - // do nothing - cmd.write_stdin(ion_text.as_ref()); - }, - FileMode::Named => { - // dump our test data to input file - let mut input_file = File::create(&input_path)?; - input_file.write(ion_text.as_ref().as_bytes())?; - input_file.flush()?; - - // TODO: test multiple input files - - // make this the input for our driver - cmd.arg(input_path.to_str().unwrap()); - - } - }; - - let assert = cmd.assert(); - - let actual_ion = match output_mode { - FileMode::Default => { - let output = assert.get_output(); - element_reader().read_one(&output.stdout)? - } - FileMode::Named => { - let mut output_file = File::open(output_path)?; - let mut output_buffer = vec![]; - output_file.read_to_end(&mut output_buffer)?; - element_reader().read_one(&output_buffer)? - } - }; - - assert_eq!(expected_ion, actual_ion); - assert.success(); - - Ok(()) -} \ No newline at end of file From 4cead8b94098ad3a558208ba6f8f29aa9cc9676e Mon Sep 17 00:00:00 2001 From: Cameron Durham Date: Mon, 7 Mar 2022 12:52:56 -0700 Subject: [PATCH 9/9] Add CLI driver tests and Github workflow --- .github/workflows/build.yml | 44 ++++++++++ Cargo.lock | 157 ++++++++++++++++++++++++++++++++++++ Cargo.toml | 7 +- tests/cli.rs | 146 +++++++++++++++++++++++++++++++++ 4 files changed, 353 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.yml create mode 100644 tests/cli.rs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1924ad3 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,44 @@ +name: CI Build + +on: [push, pull_request] + +jobs: + build: + name: Build and Test + runs-on: ${{ matrix.os }} + # We want to run on external PRs, but not on internal ones as push automatically builds + # H/T: https://github.com/Dart-Code/Dart-Code/commit/612732d5879730608baa9622bf7f5e5b7b51ae65 + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'amzn/ion-cli' + strategy: + matrix: + # TODO: add windows after fixing cmake version error issues + # see for example Windows build workflow: https://github.com/amzn/ion-rust/blob/a4b154cc0a5b5b661a45ac14d3719a501573d8f2/.github/workflows/rust.yml#L13-L28 + os: [ubuntu-latest, macos-latest] + + steps: + - name: Git Checkout + uses: actions/checkout@v2 + with: + submodules: recursive + - name: Rust Toolchain + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - name: Cargo Build + uses: actions-rs/cargo@v1 + with: + command: build + args: --verbose --workspace + - name: Cargo Test + uses: actions-rs/cargo@v1 + with: + command: test + args: --verbose --workspace -- --test-threads=1 + # TODO: run rustfmt and enable check + # - name: Rustfmt Check + # uses: actions-rs/cargo@v1 + # with: + # command: fmt + # args: --verbose -- --check diff --git a/Cargo.lock b/Cargo.lock index b92f146..6161174 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -35,6 +35,20 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" +[[package]] +name = "assert_cmd" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c98233c6673d8601ab23e77eb38f999c51100d46c5703b17288c57fddf3a1ffe" +dependencies = [ + "bstr", + "doc-comment", + "predicates", + "predicates-core", + "predicates-tree", + "wait-timeout", +] + [[package]] name = "atty" version = "0.2.14" @@ -117,6 +131,17 @@ dependencies = [ "wyz", ] +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", +] + [[package]] name = "byteorder" version = "1.4.2" @@ -230,6 +255,24 @@ dependencies = [ "syn", ] +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + [[package]] name = "env_logger" version = "0.7.1" @@ -303,6 +346,7 @@ name = "ion-cli" version = "0.2.0" dependencies = [ "anyhow", + "assert_cmd", "clap", "cmake", "colored", @@ -310,6 +354,7 @@ dependencies = [ "ion-schema", "libc", "memmap", + "rstest", "tempfile", ] @@ -373,6 +418,15 @@ dependencies = [ "libc", ] +[[package]] +name = "itertools" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +dependencies = [ + "either", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -510,12 +564,48 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" +[[package]] +name = "pest" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +dependencies = [ + "ucd-trie", +] + [[package]] name = "ppv-lite86" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "predicates" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5aab5be6e4732b473071984b3164dbbfb7a3674d30ea5ff44410b6bcd960c3c" +dependencies = [ + "difflib", + "itertools", + "predicates-core", +] + +[[package]] +name = "predicates-core" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da1c2388b1513e1b605fcec39a95e0a9e8ef088f71443ef37099fa9ae6673fcb" + +[[package]] +name = "predicates-tree" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d86de6de25020a36c6d3643a86d9a6a9f552107c0559c60ea03551b5e16c032" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "proc-macro2" version = "1.0.32" @@ -607,6 +697,12 @@ dependencies = [ "thread_local", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.22" @@ -622,18 +718,58 @@ dependencies = [ "winapi", ] +[[package]] +name = "rstest" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "041bb0202c14f6a158bbbf086afb03d0c6e975c2dec7d4912f8061ed44f290af" +dependencies = [ + "cfg-if 1.0.0", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + [[package]] name = "rustc-hash" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver", +] + [[package]] name = "ryu" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "shlex" version = "0.1.1" @@ -692,6 +828,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termtree" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b" + [[package]] name = "textwrap" version = "0.9.0" @@ -740,6 +882,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "ucd-trie" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" + [[package]] name = "unicode-width" version = "0.1.8" @@ -764,6 +912,15 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index ce75b3f..9b8dbad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,12 @@ ion-schema = "0.1.0" [build-dependencies] cmake = "0.1.44" +[dev-dependencies] +rstest = "~0.10.0" +assert_cmd = "~1.0.5" +tempfile = "~3.2.0" + [[bin]] name = "ion" -test = false +test = true bench = false diff --git a/tests/cli.rs b/tests/cli.rs new file mode 100644 index 0000000..f15e3c1 --- /dev/null +++ b/tests/cli.rs @@ -0,0 +1,146 @@ +use anyhow::Result; +use assert_cmd::Command; +use ion_rs::value::owned::OwnedElement; +use ion_rs::value::reader::*; +use rstest::*; +use std::fs::File; +use std::io::{Read, Write}; +use std::time::Duration; +use tempfile::TempDir; + +enum FileMode { + /// Use `STDIN` or `STDOUT` + Default, + /// Use a named file + Named, +} + +struct TestCase> { + /// The text of the ion payload to test + ion_text: S, + /// The expected Ion + expected_ion: OwnedElement, +} + +impl From<(&'static str, &'static str)> for TestCase<&'static str> { + /// Simple conversion for static `str` slices into a test case + fn from((ion_text, expected_ion): (&'static str, &'static str)) -> Self { + let expected_ion = element_reader().read_one(expected_ion.as_bytes()).unwrap(); + Self { + ion_text, + expected_ion, + } + } +} + +#[rstest] +#[case::simple(( +r#" +{ + name: "Fido", + + age: years::4, + + birthday: 2012-03-01T, + + toys: [ + ball, + rope, + ], + + weight: pounds::41.2, + + buzz: {{VG8gaW5maW5pdHkuLi4gYW5kIGJleW9uZCE=}}, +} +"#, +r#" +{ + name: "Fido", + + age: years::4, + + birthday: 2012-03-01T, + + toys: [ + ball, + rope, + ], + + weight: pounds::41.2, + + buzz: {{VG8gaW5maW5pdHkuLi4gYW5kIGJleW9uZCE=}}, +} +"# +).into())] +/// Calls the ion CLI binary dump command with a set of arguments the ion-cli is expected to support. +/// This does not verify specific formatting, only basic CLI behavior. +fn run_it>( + #[case] test_case: TestCase, + #[values("", "binary", "text", "pretty")] format_flag: &str, + #[values(FileMode::Default, FileMode::Named)] input_mode: FileMode, + #[values(FileMode::Default, FileMode::Named)] output_mode: FileMode, +) -> Result<()> { + let TestCase { + ion_text, + expected_ion, + } = test_case; + + let temp_dir = TempDir::new()?; + let input_path = temp_dir.path().join("INPUT.ion"); + let output_path = temp_dir.path().join("OUTPUT.ion"); + + let mut cmd = Command::cargo_bin("ion")?; + cmd.arg("dump").timeout(Duration::new(5, 0)); + if format_flag != "" { + cmd.arg("-f"); + cmd.arg(format_flag); + } + match output_mode { + FileMode::Default => { + // do nothing + } + FileMode::Named => { + // tell driver to output to a file + cmd.arg("-o"); + cmd.arg(&output_path); + } + }; + + match input_mode { + FileMode::Default => { + // do nothing + cmd.write_stdin(ion_text.as_ref()); + } + FileMode::Named => { + // dump our test data to input file + let mut input_file = File::create(&input_path)?; + input_file.write(ion_text.as_ref().as_bytes())?; + input_file.flush()?; + + // TODO: test multiple input files + + // make this the input for our driver + cmd.arg(input_path.to_str().unwrap()); + } + }; + + let assert = cmd.assert(); + + let actual_ion = match output_mode { + FileMode::Default => { + let output = assert.get_output(); + element_reader().read_one(&output.stdout)? + } + FileMode::Named => { + let mut output_file = File::open(output_path)?; + let mut output_buffer = vec![]; + output_file.read_to_end(&mut output_buffer)?; + element_reader().read_one(&output_buffer)? + } + }; + + assert_eq!(expected_ion, actual_ion); + assert.success(); + + Ok(()) +}