Ah sorry about that. I'm on a windows laptop and didn't have make, so was testing interactively and they were passing.
I cleaned that up and remove the f-* usage and verified under Ubuntu (on WSL) that the new tests are passing. I was getting some failures with unrelated tests, but also get those in master as well.

Unless I'm missing something it looks like test-ob-core/dir-mkdirp covers most other :dir usage.

I've remove the ID creation altogether and throw an error if org-attach-dir is nil at that point. The error directs the user to add :ID: or :DIR: and we don't need to do any guessing on their behalf. Implicit ID creation should likely live elsewhere anyway.


On Sat, Jun 11, 2022 at 5:49 AM Ihor Radchenko <yantar92@gmail.com> wrote:
Ryan Scott <ryan@vicarious-living.com> writes:

> Had no experience with the :DIR: property or writing unit tests for Org,
> but I think I've got both covered now.
> The ID creation prompting now only happens if there is no result from
> org-attach-dir, which should address the :DIR: case.

Thanks!

> Let me know if there's anything about those tests that I should modify.

Yeah. They do not pass, currently...
You can try yourself by running make test from Org git directory.

>> > +          ((or '(:dir . attach) '(:dir . "'attach"))
>> > +           (unless (org-id-get)
>> > +             (if (or noninteractive (y-or-n-p (format "Create ID for
>> entry \"%s\"?"
>> > +                                                      (org-get-heading
>> t t t t))))
>> > +                 (org-id-get-create)
>> > +               (error "Can't attach to entry \"%s\". Entry has no ID"
>> > +                      (org-get-heading t t t t))))

Unconditional ID creation for noninteractive is a bad idea. It is safer
to throw an error.

This code also generates warnings:


In end of data:
ob-core.el:2788:21: Warning: the function ‘org-id-get-create’ is not known to
    be defined.
ob-core.el:2787:58: Warning: the function ‘org-get-heading’ is not known to be
    defined.
ob-core.el:2785:23: Warning: the function ‘org-id-get’ is not known to be
    defined.
ob-core.el:2792:38: Warning: the function ‘org-attach-dir’ is not known to be
    defined.

Note that not all the ideas use org-id. Hence, `org-id-get-create' may
not be available during runtime. Adding (require 'org-id) is not a good
idea either (there will be other side-effects). So, if org-id is not
loaded, it will be better to just throw an error.

> +(ert-deftest test-ob-core/dir-attach ()
> +  "Test :dir header using special 'attach value"
> +  (should
> +   (org-test-with-temp-text-in-file
> +    "* Symbol
> +<point>#+begin_src elisp :dir 'attach :results file
> +(f-write-text \"attachment testing\" 'utf-8 \"test.txt\")

f-write-text requires f.el, which is external packages. You cannot use
it.

Also, while you are here, you can as well add tests for other possible
:dir settings.

Best,
Ihor