Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail if run from under a target directory #346

Closed
lread opened this issue Oct 25, 2021 · 7 comments · Fixed by #351
Closed

Tests fail if run from under a target directory #346

lread opened this issue Oct 25, 2021 · 7 comments · Fixed by #351

Comments

@lread
Copy link

lread commented Oct 25, 2021

Expected behavior

As part of rewrite-clj canary testing, I extract a copy of refactor-nrepl source code somewhere beneath rewrite-clj's target directory.

When I run

make test

I should see all tests pass.

Actual behavior

I see the following test failures:

...

FAIL in (source-files-with-clj-like-extension-test) (core_test.clj:45)
expected: (pos? (count (filter (fn [f] (-> f .getPath (.endsWith extension))) result)))
  actual: (not (pos? 0))

lein test :only refactor-nrepl.core-test/source-files-with-clj-like-extension-test

FAIL in (source-files-with-clj-like-extension-test) (core_test.clj:45)
expected: (pos? (count (filter (fn [f] (-> f .getPath (.endsWith extension))) result)))
  actual: (not (pos? 0))

lein test :only refactor-nrepl.core-test/source-files-with-clj-like-extension-test

FAIL in (source-files-with-clj-like-extension-test) (core_test.clj:45)
expected: (pos? (count (filter (fn [f] (-> f .getPath (.endsWith extension))) result)))
  actual: (not (pos? 0))

...

FAIL in (sorts-by-frequencies) (form-init11474675976321826582.clj:32)
expected: (= (first utils) (quote refactor-nrepl.util))
  actual: (not (= nil refactor-nrepl.util))

lein test :only refactor-nrepl.ns.namespace-aliases-test/libspecs-are-cached

FAIL in (libspecs-are-cached) (form-init11474675976321826582.clj:42)
expected: (thrown-with-msg? Exception #"Expected!" (sut/namespace-aliases false))
  actual: nil

...

Ran 130 tests containing 29599 assertions.
5 failures, 0 errors.
Tests failed.
Error encountered performing task 'test' with profile(s): 'base,system,provided,dev,1.10,config'
Tests failed.
make: *** [test] Error 1

If I instead don't have target in my path all tests pass.

Steps to reproduce the problem

mkdir -p foobar/target
cd foobar/target
git clone https://github.com/clojure-emacs/refactor-nrepl.git
cd refactor-nrepl
git reset v3.0.0 --hard
make test

You will see tests fail, but if you then:

cd ../..
mv target ok
cd ok/refactor-nrepl
make test

You will see tests pass.

Environment & Version information

clj-refactor.el and refactor-nrepl version information

Running tests from v3.0.0 tag clone of this repository.

CIDER version information

n/a

Leiningen or Boot version

❯ lein --version
Leiningen 2.9.7 on Java 11.0.13 OpenJDK 64-Bit Server VM

Emacs version

n/a

Operating system

macOS 10.15.7

Diagnosis

This was working for refactor-nrepl 2.5.1.

I think the issue is likely caused by new classpath exclusion techniques:

(defn source-dirs-on-classpath
"Like `#'dirs-on-classpath`, but restricted to dirs that look like
(interesting) source/test dirs."
[]
(->> (dirs-on-classpath)
(remove (fn [^File f]
(let [s (-> f .toString)]
(or (-> s (.contains "resources"))
(-> s (.contains "target"))
(-> s (.contains ".gitlibs"))))))
(remove util/dir-outside-root-dir?)))

which excludes any path that contains target or resources (I'm guessing that .gitlibs is less important).

I raised this issue in case it might be affecting your broader user base.
If it is only affecting my particular use case, I can find a work-around for rewrite-clj canary testing.

@vemv
Copy link
Member

vemv commented Oct 25, 2021

Thanks for the heads up!

I extract a copy of refactor-nrepl source code somewhere beneath rewrite-clj's target directory

Honestly I don't think there's a legitimate use case for this. target/ is not where a given project's source is expected to reside.

refactor-nrepl intentionally excludes anything residing under target/ for both avoiding superfluous errors and speeding up analysis.

Therefore I'd recommend to run the test suite under a more realistic setting (which, can be argued, is an improvement for rewrite-clj's canary testing, i.e. not merely a workaround).

Cheers - V

@lread
Copy link
Author

lread commented Oct 25, 2021

Thanks for the reply @vemv.

Honestly I don't think there's a legitimate use case for this. target/ is not where the a given project's source is expected to reside.

I find that folks put stuff wherever they put stuff.
Build/test work happens under target, and this is test work for rewrite-clj.
But, I can do my canary tests under an alternate dir without any fuss at all.

My primary goal was to be a good citizen by alerting you to a potentially larger problem for your user base.
If this is not the case, please feel free to close this issue.

@vemv
Copy link
Member

vemv commented Oct 25, 2021

My primary goal was to be a good citizen by alerting you to a potentially larger problem for your user base.

Yes, understood and appreciated 👍

Have a great one!

@vemv vemv closed this as completed Oct 25, 2021
@lread
Copy link
Author

lread commented Oct 25, 2021

Who knows, poor old Timothy Arget, or Ryan Emert Steven Ources might have usernames that prohibit the use of refactor-nrepl! (more tongue in cheek than making a point, but still making a bit of a point).

@vemv
Copy link
Member

vemv commented Oct 25, 2021

That's a good call, .contains could be .endsWith

@vemv vemv reopened this Oct 25, 2021
@lread
Copy link
Author

lread commented Oct 25, 2021

All my best arguments are jokes. 🙂

lread added a commit to clj-commons/rewrite-clj that referenced this issue Oct 25, 2021
Upgrade to current version of kaocha.

test-libs
- Upgraded refactor-nrepl to v3.
  After much head-scratching I discovered that v3 of refactor-nrepl
  cannot be run anywhere under a target directory.
  As a good citizen, raised: clojure-emacs/refactor-nrepl#346
  The work-around is that test-libs work no longer happens under target, we now
  do the work under ./test-libs-work/.
  This pollutes the root dir a bit, but a tidy root dir is less
  important to me than testing against libs.
- Upgraded rewrite-edn to current release

Other changes to test-libs script:
- it is now a fatal error if our patching produces no changes
- searches for version strings now appropriately match versions with qualifiers
@lread
Copy link
Author

lread commented Oct 25, 2021

Another idle thought: I suppose it might be odd, but a CI server could plunk your code wherever too.

vemv added a commit that referenced this issue Nov 5, 2021
vemv added a commit that referenced this issue Nov 5, 2021
bbatsov pushed a commit that referenced this issue Nov 6, 2021
lread added a commit to clj-commons/rewrite-clj that referenced this issue Jan 11, 2022
Refactor-nrepl has addressed
clojure-emacs/refactor-nrepl#346
which allows us to move our test-libs work back under our
general purpose build target/ dir.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants