Commit Graph

163 Commits

Author SHA1 Message Date
Louis Gesbert
a71b4e7f73 Some fixes to relative file lookups in modules and tests
This makes sure `catala module` finds the local runtime when run from the catala
source tree; and fixes lookup of the catala exec on custom uses of `clerk runtest`.
2023-08-31 17:55:36 +02:00
Louis Gesbert
17172cf47d Some fixes & cleanup after early review 2023-08-31 17:55:36 +02:00
Louis Gesbert
72882f82df Reformat 2023-08-31 17:55:36 +02:00
Louis Gesbert
edd6dce0d8 Disable recursive tests reset for now; remove rel paths in test out 2023-08-04 12:08:18 +02:00
Louis Gesbert
fa33d37d84 Clerk: split code for running tests from the main (Ninja) engine 2023-08-04 12:08:18 +02:00
Louis Gesbert
378669b09e Implement reversing the dependencies for tests
This works for the `--reset` option, but I have some doubts about it.
2023-08-04 12:08:18 +02:00
Louis Gesbert
ab365b25b3 Clerk: replace colordiff with diff --color
This should be available mostly everywhere now (first appeared in e.g. Ubuntu
18) and avoids the need for an additional run-time dependency.
2023-08-02 15:12:31 +02:00
Denis Merigoux
50113586e3 With @aminata-dev update Messages.Content 2023-07-12 11:55:11 +02:00
Louis Gesbert
98f712365e Restore full expression printing when --debug is set 2023-07-03 17:30:17 +02:00
Louis Gesbert
0f9ee2c72e Refacter the main Driver module
- Use separate functions for successive passes in module `Driver.Passes`
- Use other functions for end results printing in module `Driver.Commands`

As a consequence, it is much more flexible to use by plugins or libs and we no
longer need the complex polymorphic variant parameter.

This patch leverages previous changes to use Cmdliner subcommands and
effectively specialises the flags of each Catala subcommand.

Other changes include:

- an attempt to normalise the generic options and reduce the number of global
  references. Some are ok, like `debug` ; some would better be further cleaned up,
  e.g. the ones used by Proof backend were moved to a `Proof.globals` module and
  need discussion. The printer no longer relies on the global languages and prints
  money amounts in an agnostic way.
- the plugin directory is automatically guessed and loaded even in dev setups.
  Plugins are shown by the main `catala` command and listed in `catala --help`
- exception catching at the toplevel has been refactored a bit as well; return
  codes are normalised to follow the manpage and avoid codes >= 128 that are
  generally reserved for shells.

Update tests
2023-07-03 16:42:54 +02:00
Denis Merigoux
385e19b9e1 Formatting 2023-06-15 10:51:31 +02:00
Aminata-Dev
10d147a8b1 Messages renamed to Message (lighter syntax) 2023-06-13 11:50:56 +02:00
Louis Gesbert
c564e70636 Correctly setup ocolor on all output channels
(and some cleanup of the remaining deps to ANSITerminal)
2023-06-08 12:14:11 +02:00
Louis Gesbert
deaf40761e Use ocolor instead of ANSITerminal 2023-06-08 12:11:55 +02:00
Denis Merigoux
79801292e9
Fix most doc errors 2023-06-02 17:17:45 +02:00
Denis Merigoux
d1210cc0e4 The thing compiles 2023-06-02 10:50:33 +02:00
Denis Merigoux
4e6efe08da All renamings done, on with actual refactor 2023-06-02 10:50:33 +02:00
Denis Merigoux
0faa97b8fc Abstract messages interface 2023-06-02 10:50:29 +02:00
Denis Merigoux
eae61256ef
Adhere to the GNU standard for error messages 2023-05-04 19:19:19 +02:00
Louis Gesbert
7ae7c9ceaf Clerk: fix stale ninja files in /tmp not getting removed 2023-01-17 11:15:08 +01:00
Louis Gesbert
660e5775de Rename utils to catala_utils 2022-11-28 16:38:09 +01:00
Louis Gesbert
4ae392c900 AST refactoring
Many changes got bundled in here and would be too tedious to separate.

Closes #330

See changes in `shared_ast/definitions.ml` to check the main point.

- the biggest change is a modification of the struct and enum types in
  expressions: they are now stored as `Map`s throughout passes, and no longer
  converted to indexed lists after scopelang. Their accessors are also changed,
  and tuples only exist in Lcalc (they're used for closure conversion).

  This implied adding some more information in the contexts, to keep the mapping
  between struct fields and scope output variables. It should also be much more
  robust (no longer relying on assumptions upon different orderings).

- another very pervasive change is more cosmetic: the rewrite of the main AST to
  use inline records, labelling individual subfields.

- moved the checks for correct definitions and accesses of structures from
  `Scope_to_dcalc` to `Typing`

- defining some new shallow iterators in module `Shared_ast.Expr`, and
  factorising a few same-pass rewriting functions accordingly (closure
  conversion, optimisations, etc.)

- some smaller style improvements (ensuring we use the proper compare/equal
  functions instead of `=` in a few `when` closes, for example)
2022-11-17 18:16:09 +01:00
Louis Gesbert
0de73c4b9b Clerk: define strings used as variables just once 2022-10-04 14:50:37 +02:00
Louis Gesbert
6701b0760d Clerk inline tests: tiny improvements
- pass Catala options correctly in "clerk run-test"
- filter "OCAMLRUNPARAM" out of the environment (avoids backtraces getting
  included in test outputs)

I use the following function in Emacs to live-update a test output:

```elisp
(defun clerk-test-update ()
  (interactive nil)
  (let ((pos (point)))
    (delete-region (point-min) (point-max))
    (call-process
     "dune" nil t t
     "exec" "--display=quiet" "--no-print-directory" "--no-build" "clerk" "--"
     "runtest" "-e" "dune" "-c" "exec catala --no-build --"
     (buffer-file-name))
    (goto-char pos)))
```
2022-10-04 14:50:37 +02:00
Louis Gesbert
a291c202b9 Tests: use patdiff rather than colordiff if available 2022-10-04 14:50:37 +02:00
Louis Gesbert
3ceb9ec80c Clerk: don't stop on 1st error on tests 2022-09-26 14:24:49 +02:00
Louis Gesbert
8c1696d0ff Inline tests: cleanup trailing whitespace 2022-09-23 16:56:21 +02:00
Louis Gesbert
fe6fabb1b0 Clerk tests: update README 2022-09-23 16:41:22 +02:00
Louis Gesbert
005de24ee7 Inline tests: ensure proper escaping of output
and that the input is not truncated with --reset
2022-09-23 14:52:04 +02:00
Louis Gesbert
b9c0453fc9 Clerk tests: add ability to have tests with inlined output
Reduces the number of files, and makes tracking and diffing tests much easier.
2022-09-23 13:50:56 +02:00
Louis Gesbert
6cb8ee7916 Clerk: don't default to infinite ninja jobs 2022-09-20 11:30:29 +02:00
Emile Rolley
ba620fca28 ocamlformat: new break-infix rule 2022-08-05 10:55:48 +02:00
Louis Gesbert
bc8eda581c Add a script generating static builds
We have an obvious limitation: static builds won't support plugins. We
could resort to the classic method and do normal builds but on an old
distrib to dodge compatibility issues.

That would still be compatible with statically linking the more specific
libs, like e.g. z3.
2022-08-03 19:04:14 +02:00
Emile Rolley
d3d254033c feat(runtimes/jsoo): add a new class type duration with conv functions 2022-07-22 16:52:56 +02:00
Emile Rolley
0c180e12f9 refactor(runtimes): add runtime_ocaml and runtime_jsoo in the catala package 2022-07-22 16:52:56 +02:00
Louis Gesbert
5b1a6a2217 Fix ninja arguments order
works better when replacing 'ninja' with the alternate implementation 'samurai'
2022-07-20 12:05:19 +02:00
Emile Rolley
1d05b57bdd refactor(clerk): suffix the ninja build outputs with .PHONY instead of .out 2022-07-12 11:16:12 +02:00
Denis Merigoux
c5cb6f5c4d
Restore automatic rebuild of all tests by ninja
Also cleaned unused rule arg
2022-07-11 16:56:06 +02:00
Louis Gesbert
2e5050481d Register all existing tests through the new engine
I removed the '.out' extension for now to preserve the test output file names and avoid a million file renames.

This makes the patch easier to read, and we can do the rename easily in another patch afterwards, without mixing with semantic changes.

(beautiful script àlarrache:
```bash
for f in */*/output/*; do
  target_base=${f##*/}
  target_base=${target_base%%.*}
  echo $f | awk -F. '{
    f=$1"."$2; if ($4 == "") { mode=$3; id=$3 } else { scope="-s "$3; mode=$4; id=$3"."$4}
    printf "\n```catala-test {id=\"%s\"}\ncatala %s %s\n```\n",id,mode,scope;
  }' >> $(dirname $f)/../${target_base}.*; done
```
2022-07-08 17:06:20 +02:00
Denis Merigoux
66a7d2f7a3 Fix test encoding 2022-07-08 15:37:01 +02:00
Denis Merigoux
a78f649377
Add negative test 2022-07-08 14:16:02 +02:00
Denis Merigoux
bdbf202a8d
Minimal implementation of https://github.com/CatalaLang/catala/issues/192#issuecomment-1178750411 2022-07-08 14:10:25 +02:00
Louis Gesbert
30297b27b8 Add dune rule to build tests
This allows a new magic command: `dune test -w`
2022-05-25 18:33:20 +02:00
Louis Gesbert
9a95a3554c Add support for backend plugins using dynlink 2022-05-19 10:40:02 +02:00
Emile Rolley
144704f7fb refactor(compiler): add the Utils.File module
+ Adds wrapper functions for formatter of file/out_channel
	and uses it in both the compiler and the clerk drivers.
2022-05-19 10:04:34 +02:00
Louis Gesbert
faa5b32638 Merge remote-tracking branch 'origin/master' into allocations_logement 2022-05-12 15:22:17 +02:00
Louis Gesbert
f9fc1a8e8b Formatting: sync with master 2022-05-12 15:10:55 +02:00
Louis Gesbert
f17875f90e Formatting: some other personal preferences 2022-05-11 16:25:49 +02:00
Louis Gesbert
74c5629153 Formatting: reduce extra match-case indentation
2 is plenty enough, esp. for nested matches :)
2022-05-11 16:25:20 +02:00
Louis Gesbert
fa3693d813 Formatting: disable deprecated "smart" fun-decl option 2022-05-11 16:22:56 +02:00
Louis Gesbert
6cb0d581a6 Workaround some ocamlformat crashes
These files were not reformatted!
2022-05-11 16:21:07 +02:00
Louis Gesbert
6837af4e80 Upgrade Cmdliner dep 2022-05-09 11:39:18 +02:00
Denis Merigoux
a72944a3ec
Merge branch 'master' into allocations_logement 2022-05-05 14:27:48 +02:00
Denis Merigoux
78d5dfc194
Deprecated functions 2022-05-05 14:17:27 +02:00
Denis Merigoux
db35b09202
Use Re functions instead of Re.Pcre
Co-authored-by: Louis Gesbert <louis.gesbert@ocamlpro.com>
2022-05-05 14:14:44 +02:00
Denis Merigoux
f571ce9979
Rename tests correcly [skip ci] 2022-04-25 14:34:49 +02:00
Denis Merigoux
b3fae97f94
Correctly parse the -j option in Clerk 2022-04-14 16:56:10 +02:00
Denis Merigoux
171c3966f5
Pass some make flags to Clerk 2022-04-14 11:47:18 +02:00
Denis Merigoux
9d05dad3fb
Passing all tests! 2022-04-04 15:56:45 +02:00
Emile Rolley
7c1f4cc02d refactor: group common functions related to backend_option in the Cli module 2022-03-08 15:52:26 +01:00
Denis Merigoux
5bd66142a6
Big reformatting
ocamlformat 0.19.0 -> 0.20.1
100 -> 80 columns per line
Reestablished @emilerolley's smart fun break
2022-03-08 15:03:14 +01:00
Louis Gesbert
12ec65601d Use format strings directly in debug/error/log functions
This avoids many intermediate calls to e.g. `Format.asprintf`; should result in
some cases in "more correct" use of `Format`¹, avoid the computation of unused
debug strings, and make the code more readable.

¹ for `Format` to work as expected, all intermediate calls need to go through
it. Some cases of formatting to an intermediate string then printing through Format
again are still present, but this makes the situation better.
2022-03-08 13:04:27 +01:00
Denis Merigoux
c5d63148f8
Fix dune build -p catala @runtest 2022-03-08 11:28:42 +01:00
Emile Rolley
54e71bf3e3 fix(clerk): sort subdirectory names 2022-03-07 18:02:12 +01:00
Denis Merigoux
b9f46afcd7
Revert ocamlformat changes; creates too much conflict in other files
Changes in autoformatting should be made in a separate PR in a time where
there isn't too much pending PRs for the OCaml files
2022-03-07 11:09:47 +01:00
Emile Rolley
b0829148c7 format: add break-fun-decl in .ocamlformat 2022-02-26 19:53:56 +01:00
Emile Rolley
48118f46bb test(clerk): add test cases 2022-02-26 19:49:13 +01:00
Emile Rolley
f277f272d1 test(clerk): setup alcotest + two first tests 2022-02-25 20:30:05 +01:00
Emile Rolley
15bb52e37a fix(clerk): change the -o argument to a string instead of a flag
-> catch the Sys_error if the file can't be created.
2022-02-25 20:03:58 +01:00
Emile Rolley
f4ab6f5a96 build(clerk/opam): add a clerk opam package and a clerk.driver library to test 2022-02-25 18:14:07 +01:00
Emile Rolley
73576548c6 docs: update authors fields 2022-02-25 16:49:22 +01:00
Emile Rolley
bc7160d009 feat(clerk): add the output flag 2022-02-25 14:31:37 +01:00
Emile Rolley
ee6eb717c1 test(clerk): remove irelevant tests 2022-02-25 12:42:00 +01:00
Emile Rolley
3a6450b42f Merge branch 'master' into refactor-clerk-w-ninja 2022-02-25 12:31:16 +01:00
Emile Rolley
4a83360220 refactor(clerk): change to_string to format functions 2022-02-25 12:30:29 +01:00
Emile Rolley
da6ed6b044 docs(clerk): add documentation about clerk and the Ninja_utils module 2022-02-24 14:05:05 +01:00
Emile Rolley
64820a0b20 docs(clerk): update the README file 2022-02-22 18:59:07 +01:00
Emile Rolley
abeea09d7f feat(clerk): add support for multiple inputs
+ change the Makefile 'tests' rule to call only one time clerk
2022-02-22 18:06:12 +01:00
Alain
73fe2f876c Revert "Merge pull request #196 from CatalaLang/fixup-cmdliner"
fix cmdliner to 1.0.4

This reverts commit 8e1a1ccb63, reversing
changes made to 4812830a25.
2022-02-21 14:53:48 +01:00
Emile Rolley
8214ad2ce6 fix(clerk): catch the exception and print a warning msg when a unexistant file is found (e.g. symbolic links) 2022-02-21 14:52:03 +01:00
Emile Rolley
351c7346d6 refactor(clerk): factorize functions for building ninja rules
+ add "test cases" for Lcalc and Scalc backends.
	+ add support for Scalc and Lcalc and sort by alphabetical
	  order their type declarations.
2022-02-17 16:45:49 +01:00
Emile Rolley
7a4ef62ebe refactor(clerk): add Catala backend in the name of the output build 2022-02-17 14:56:45 +01:00
Emile Rolley
bbf4b540eb test(clerk): add 'tests' for clerk 2022-02-15 20:46:33 +01:00
Emile Rolley
e58c6c52b6
Merge branch 'master' into refactor-clerk-w-ninja 2022-02-15 20:36:15 +01:00
Emile Rolley
a9f949ffc9 refactor(clerk): add ninja support for remaining catala backends
TODO:
	 * Refactoring
	 * Manage scope + output backends
2022-02-15 20:32:17 +01:00
Denis Merigoux
b25f64c3ae
Improve printing 2022-02-14 17:01:34 +01:00
Denis Merigoux
ccd90bcbf6
Display nice finish message when ending 2022-02-14 14:43:38 +01:00
Emile Rolley
9f9b12578b refactor(clerk): print a result message when tests succeed 2022-02-14 14:00:40 +01:00
Denis Merigoux
f2dd642041
Restore Dcalc backend for clerk as it does not seem to produce bugs anymore? 2022-02-14 12:03:35 +01:00
Denis Merigoux
cf8557a7aa
Merge branch 'master' into emile_ninja 2022-02-14 11:56:34 +01:00
Emile Rolley
4fe85a6b05 refactor(clerk): add support to reset output with ninja
- removes unit testing setup for Ninja_utils as
	  it's not useful right now.
2022-02-14 11:49:48 +01:00
Emile Rolley
5417a64556 fix(clerk): add the Catala command to the build output name 2022-02-11 16:24:32 +01:00
Denis Merigoux
b6d9d7cf5f
Update Cmdliner with breaking changes 2022-02-10 22:57:07 +01:00
Emile Rolley
760930942c docs(clerk): add comments to ninja_utils.ml 2022-02-10 12:24:35 +01:00
Emile Rolley
d9d8987160 refactor(clerk): add support to some Catala backends through ninja
+ supported backends: Interpret, Scopelang, Dcalc, Proof, Typecheck
	+ some minor refactoring of clerk.ml
2022-02-10 12:05:20 +01:00
Emile Rolley
8d0c8a4e86 fix(clerk): add error redirection to the command of the test_scope rule 2022-02-08 16:11:54 +01:00
Emile Rolley
7b5035173f refactor(clerk): add support for directories with the ninja backend
- there is some issue with 'bad' tests
2022-02-08 15:45:20 +01:00
Emile Rolley
f5b9cd9794 refactor(clerk): add test_file_* build to factorize all scope tests for one given file 2022-02-08 14:29:12 +01:00
Emile Rolley
1c1b3f0ec2 docs(clerk): add a readme for the build_system folder 2022-02-08 12:56:04 +01:00
Emile Rolley
f79c652f82 test(clerk): add minimal unit testing structure 2022-02-08 12:45:52 +01:00