From a05cbb202197d57e5e909e11dcbb859f11c48641 Mon Sep 17 00:00:00 2001 From: Andre Kuhlenschmidt Date: Fri, 31 May 2019 17:12:24 -0700 Subject: [PATCH] [guess-root] add tests to document the behavior of preexisting commands. Summary: This test documents how some commands use invalid roots as the starting place for searching for a valid root while others just reject the invalid root. It also provides a usage of the type-at-pos command where the optional file argument has been elided. Reviewed By: mvitousek Differential Revision: D15582376 fbshipit-source-id: 5851d038684e35d87f9729da29b38e91af12ed9e --- tests/guess-root/.testconfig | 2 ++ tests/guess-root/config/.flowconfig | 11 +++++++++ tests/guess-root/config/no-config/d2.js | 5 +++++ tests/guess-root/d0.js | 5 +++++ tests/guess-root/guess-root.exp | 30 +++++++++++++++++++++++++ tests/guess-root/no-config/d1.js | 5 +++++ tests/guess-root/test.sh | 25 +++++++++++++++++++++ 7 files changed, 83 insertions(+) create mode 100644 tests/guess-root/.testconfig create mode 100644 tests/guess-root/config/.flowconfig create mode 100644 tests/guess-root/config/no-config/d2.js create mode 100644 tests/guess-root/d0.js create mode 100644 tests/guess-root/guess-root.exp create mode 100644 tests/guess-root/no-config/d1.js create mode 100644 tests/guess-root/test.sh diff --git a/tests/guess-root/.testconfig b/tests/guess-root/.testconfig new file mode 100644 index 00000000000..7e0f5b794ef --- /dev/null +++ b/tests/guess-root/.testconfig @@ -0,0 +1,2 @@ +shell: test.sh +auto_start: false diff --git a/tests/guess-root/config/.flowconfig b/tests/guess-root/config/.flowconfig new file mode 100644 index 00000000000..1fed445333e --- /dev/null +++ b/tests/guess-root/config/.flowconfig @@ -0,0 +1,11 @@ +[ignore] + +[include] + +[libs] + +[lints] + +[options] + +[strict] diff --git a/tests/guess-root/config/no-config/d2.js b/tests/guess-root/config/no-config/d2.js new file mode 100644 index 00000000000..9c657602e8c --- /dev/null +++ b/tests/guess-root/config/no-config/d2.js @@ -0,0 +1,5 @@ +// @flow + +let y = 0; +function f(x = y) {} +function g({x = y}) {} diff --git a/tests/guess-root/d0.js b/tests/guess-root/d0.js new file mode 100644 index 00000000000..9c657602e8c --- /dev/null +++ b/tests/guess-root/d0.js @@ -0,0 +1,5 @@ +// @flow + +let y = 0; +function f(x = y) {} +function g({x = y}) {} diff --git a/tests/guess-root/guess-root.exp b/tests/guess-root/guess-root.exp new file mode 100644 index 00000000000..4cba84dcfd8 --- /dev/null +++ b/tests/guess-root/guess-root.exp @@ -0,0 +1,30 @@ +nothing +with file +with file and config +number +no-config/d2.js:3:5,3:5 +with bad root directory +number +-:3:5,3:5 +with bad root directory, and file +number +no-config/d2.js:3:5,3:5 +with bad root directory, and file +number +no-config/d2.js:3:5,3:5 +with file batch coverage + +Coverage results from 1 file(s): + +no-config/d2.js: 88.89% (8 of 9 expressions) + +----------------------------------- +Aggregate coverage statistics +----------------------------------- +Files : 1 +Expressions : + Covered : 8 + Total : 9 + Covered Percentage : 88.89% + +with bad root directory, and file batch coverage diff --git a/tests/guess-root/no-config/d1.js b/tests/guess-root/no-config/d1.js new file mode 100644 index 00000000000..9c657602e8c --- /dev/null +++ b/tests/guess-root/no-config/d1.js @@ -0,0 +1,5 @@ +// @flow + +let y = 0; +function f(x = y) {} +function g({x = y}) {} diff --git a/tests/guess-root/test.sh b/tests/guess-root/test.sh new file mode 100644 index 00000000000..5fbf5d033d9 --- /dev/null +++ b/tests/guess-root/test.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +echo "nothing" +assert_exit "$EXIT_COULD_NOT_FIND_FLOWCONFIG" "$FLOW" type-at-pos 3 5 < d0.js + +echo "with file" +assert_exit "$EXIT_COULD_NOT_FIND_FLOWCONFIG" "$FLOW" type-at-pos no-config/d1.js 3 5 + +echo "with file and config" +assert_ok "$FLOW" type-at-pos --strip-root config/no-config/d2.js 3 5 + +echo "with bad root directory" +assert_ok "$FLOW" type-at-pos --root ./config/no-config 3 5 < ./config/no-config/d2.js + +echo "with bad root directory, and file" +assert_ok "$FLOW" type-at-pos --strip-root --root ./config/no-config ./config/no-config/d2.js 3 5 + +echo "with bad root directory, and file" +assert_ok "$FLOW" type-at-pos --strip-root --root ./config/no-config ./config/no-config/d2.js 3 5 + +echo "with file batch coverage" +assert_ok "$FLOW" batch-coverage --strip-root ./config/no-config/d2.js + +echo "with bad root directory, and file batch coverage" +assert_exit "$EXIT_COULD_NOT_FIND_FLOWCONFIG" "$FLOW" batch-coverage --root ./config/no-config ./config/no-config/d2.js