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

nitunit: conflicting name between modules and packages #2296

Open
xymus opened this issue Aug 26, 2016 · 1 comment
Open

nitunit: conflicting name between modules and packages #2296

xymus opened this issue Aug 26, 2016 · 1 comment
Labels

Comments

@xymus
Copy link
Contributor

xymus commented Aug 26, 2016

nitunit fails to parse tests in the module lib/json/serialization.nit. There appears to be an importation conflict between json::serialization and ::serialization.

Error: conflicting module files for `serialization`: `lib/json/serialization.nit`, `/home/xymus/projects/nit/lib/serialization/serialization.nit

To reproduce, you need to first remove the nitish from existing tests/examples:

$ git diff
diff --git a/lib/json/serialization.nit b/lib/json/serialization.nit
index e26b8ec..5330b3d 100644
--- a/lib/json/serialization.nit
+++ b/lib/json/serialization.nit
@@ -35,9 +35,7 @@
 #
 # ### Usage Example
 #
-# ~~~nitish
-# import json::serialization
-#
+# ~~~
 # class Person
 #     serialize
 #

$ nitunit lib/json/serialization.nit
[KO] json::serialization
     lib/json/serialization.nit:39,3--69,0: Compilation error in nitunit.out/serialization-1.nit
    # class Person
      ^
     Output
    nitunit.out/serialization-1.nit:3,8--20: Error: conflicting module files for `serialization`: `lib/json/serialization.nit`, `/home/xymus/projects/nit/lib/serialization/serialization.nit`

==== Docunits of module json::serialization [X] tests: 1 KO: 1
Docunits: Entities: 49; Documented ones: 23; With nitunits: 1; Failures: 1
Test suites: Classes: 0; Test Cases: 0
[FAILURE] 1/1 tests failed.
`nitunit.out` is not removed for investigation.
@privat
Copy link
Member

privat commented Aug 26, 2016

Docunits are collected and written as genuine nit source files.
However, nitunit assumes that the original module should be imported by these generated files, thus it injects a import originalmodule in the file, then invokes nitc.

The invoked nitc see the import originalmodule and have to find it. Problem: the generated file in a subdirectory unrelated to the originalmodule or its package so it cannot find it.
To solve this problem, nitunit just add a -I directoryof(originalmodule) to the nitc invocation, so nitc can look for the originalmodule in its pathib.

Unfortunately nitc fails and insults you if there is conflicts for modules accessible from the pathlib. lib/serialization is by default in the pathlib, and lib/json/serialization.nit was added thanks to the -I.

Some solutions:

  • stop injecting -I and force the programmer to always add the import in its nitunit

    PRO: no more conflict

    CON: a lot more module not found and angry programmers

  • inject a full path import, not a relative one. eg import json::serialization

    PRO: simple & better than now

    CON: won't work if the package of the module is not in the pathlib

  • same plus inject -I directory(package(othermodule))

    PRO: simple & better than now

    CON: might cause similar issue if the directory of the package contains crap that
    might conflict (not perfect solution)

  • extends the language to import a fixed file. eg import "lib/json/serialization.nit"

    PRO: simple

    CON/PRO?: C-like

    CON: need to extends the grammar and regenerate the parser

privat added a commit that referenced this issue Sep 1, 2016
…with default values

This PR fits in the ongoing work to improve deserializing from plain JSON objects.

The JSON deserialization engine no longer raises errors on missing attributes when a default value is available. Attributes may be missing because the JSON object come from a third-party API or
when loading serialized data from a previous version of the software. Default values include simple default values (`var x = 4`), lazy attributes and nullable types (which are set to `null`). This does not yet include `optional` attributes, more work would be needed.

The test/example can be activated when #2296 is fixed.

Pull-Request: #2302
Reviewed-by: Jean Privat <[email protected]>
Reviewed-by: Alexandre Terrasa <[email protected]>
xymus added a commit to xymus/nit that referenced this issue Sep 12, 2016
xymus added a commit to xymus/nit that referenced this issue Sep 12, 2016
xymus added a commit to xymus/nit that referenced this issue Sep 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants