Replace std::cout with std::cerr in the error diagnostics handler#644
Replace std::cout with std::cerr in the error diagnostics handler#644SuperFola merged 4 commits intoArkScript-lang:devfrom
std::cout with std::cerr in the error diagnostics handler#644Conversation
This is half of the solution for ArkScript-lang#643 and is more than workable in principle, but still without color. Regarding color, I noticed that "termcolor" is one of the additional project modules, so I'll see what that leads to. Finally, I'll review the current tests to see if any already exist that test the output flow and any coloration. If not, I'll try to implement such test(s).
|
Hi, I'm not using termcolor to produce colored output, since I switched away from it a few months back for fmtlib. Does using the env var NOCOLOR work for your use case? |
|
Oh yeah, you misunderstood me. No problem. ✌ The target is color, but only on STDERR. |
|
The colored output is purely cosmetic, and I can look into that later. The most important thing is the output stream. I still try to run all the unit tests successfully, but the most striking part of the report always looks like this: ===============================================================================
Suite Debugger
tests: 1 | 1 failed
asserts: 10 | 6 passed | 4 failed
===============================================================================
Suite Diagnostics
tests: 3 | 3 failed
asserts: 490 | 184 passed | 306 failed
===============================================================================
Suite Parser
tests: 2 | 1 failed
asserts: 66 | 32 passed | 34 failed
===============================================================================
Suite Rosetta
tests: 1 | 1 failed
asserts: 80 | 79 passed | 1 failedBoth in this branch and in the base branch. That's why I'm starting to suspect there are quite a few tests that should actually be failing, or is that a complete misunderstanding? |
|
No test should be left failing, are you on windows perhaps? There might be edge cases with CR being added, since we compare files and outputs as strings from the compiler/vm; I thought I took care of it since it works on my own Windows 11 copy, and on the CI. |
Thank you, and no. I now know there is indeed a difference between recursively cloning with the first clone command and the second command after entering a cloned repository. The latter certainly paid off. UT starts =====================================================================
Running test "compile without error ir/plugin"... FAILED
Unexpected exception with message:
While processing file plugin.ark, couldn't import hash: file not found
Running test "compile without error ir/plugin"...
Running test "output expected IR for plugin"...
FAILED in: /Ark/tests/unittests/TestsHelper.cpp:125 - test condition: [false] @@ -1,1 +1,15 @@
-
+page_0
+ PLUGIN 0
+ PUSH_RETURN_ADDRESS L0
+ LOAD_CONST 1
+ LOAD_CONST 2
+ PUSH_RETURN_ADDRESS L1
+ LOAD_CONST 3
+ LOAD_FAST 0
+ CALL 1
+.L1:
+ EQ 0
+ BUILTIN 26
+ CALL 2
+.L0:
+ HALT 0
Function @ expected 2 arguments
Call
↳ (@ 5 0)
Signature
↳ (@ src idx)
Arguments
→ `src' (expected List), got 5 (Number)
→ `idx' (expected Number) ✓
Alternative 2:
Signature
↳ (@ src idx)
Arguments
→ `src' (expected String), got 5 (Number)
→ `idx' (expected Number) ✓
At IP: 3, PP: 0, SP: 2
DEBUG [IROptimizer] /Ark/src/arkreactor/Compiler/IntermediateRepresentation/IROptimizer.cpp(264:24) Loaded 140 rules
TRACE [Parser] process took 0.021ms
TRACE [ImportSolver] findAndReplaceImports took 0.006ms
TRACE [ImportSolver] process took 0.008ms
DEBUG [MacroProcessor] /Ark/src/arkreactor/Compiler/Macros/Processor.cpp(32:24) Processing macros...
TRACE [MacroProcessor] process took 0.003ms
TRACE [MacroProcessor] AST after processing macros
TRACE [NameResolution] process took 0.003ms
TRACE [NameResolution] AST after name resolution
TRACE [NameResolution] checkForUndefinedSymbol took 0.001ms
TRACE [ASTLowerer] process took 0.004ms
TRACE [IROptimizer] process took 0.002ms
TRACE [IRCompiler] process took 0.005ms
32 : Spc 48 : 0 64 : @ 80 : P 96 : ` 112 : p
33 : ! 49 : 1 65 : A 81 : Q 97 : a 113 : q
34 : " 50 : 2 66 : B 82 : R 98 : b 114 : r
35 : # 51 : 3 67 : C 83 : S 99 : c 115 : s
36 : $ 52 : 4 68 : D 84 : T 100 : d 116 : t
37 : % 53 : 5 69 : E 85 : U 101 : e 117 : u
38 : & 54 : 6 70 : F 86 : V 102 : f 118 : v
39 : ' 55 : 7 71 : G 87 : W 103 : g 119 : w
40 : ( 56 : 8 72 : H 88 : X 104 : h 120 : x
41 : ) 57 : 9 73 : I 89 : Y 105 : i 121 : y
42 : * 58 : : 74 : J 90 : Z 106 : j 122 : z
43 : + 59 : ; 75 : K 91 : [ 107 : k 123 : {
44 : , 60 : < 76 : L 92 : \ 108 : l 124 : |
45 : - 61 : = 77 : M 93 : ] 109 : m 125 : }
46 : . 62 : > 78 : N 94 : ^ 110 : n 126 : ~
47 : / 63 : ? 79 : O 95 : _ 111 : o 127 : Del
Data: ["Iron Man" "is" "Tony Stark"]
Generating callbacks
stored: Iron Man
Calling callback number 0: Iron Man
stored: is
Calling callback number 1: is
stored: Tony Stark
Calling callback number 2: Tony Stark
1
10
29
29
Generated partial functions for test_func (a b c) => (* a b c)
Expected arguments for test_func: 3, expected 3
Expected arguments for test_func1: 2, expected 2
Calling them: 6 6
Using macro foo (a b) => (+ a b): 3
Using macro constant var=12: 12
This was executed in a if macro, testing var == 12
This was executed in a if macro, testing (and true true)
Generated a function with a macro, a_func (a b) => (+ a b)
Calling (a_func 1 2): 3
Macro 'one', returns the 2nd argument given in [1 2] => 2
Macro 'one', returns the 2nd argument given in [1 3 4] => 3
Macro 'one', returns the 2nd argument given in [1 5 6 7 8] => 5
Macro 'last', returns the last argument given in [1 2] => 2
Macro 'last', returns the last argument given in [1 3 4] => 4
Macro 'last', returns the last argument given in [1 5 6 7 8] => 8
Testing macros in scopes and macro shadowing
(global) Reading macro 'test', expected 6, 6
(sub scope) Reading macro 'test', expected -4, -4
(global) Reading macro 'test', expected 6, 6
(subscope) Reading macro 'test', expected 555, 555
(subscope, undef test) Reading macro 'test', expected 6, 555
Demonstrating a threading macro
We expected calls to go like this: f1, f2, f3, f4
>>f1 hello.json
>>f2 hello.json-f1
>>f3 hello.json-f1-f2
>>f4 hello.json-f1-f2-f3
hello.json-f1-f2-f3-f4
10
5
16
8
4
2
Reached 1 in 6 iteration(s)
cannot divide by zero
FizzBuzz,1,2,Fizz,4,Buzz,Fizz,7,8,Fizz,Buzz,11,Fizz,13,14,FizzBuzz,16,17,Fizz,19,Buzz,Fizz,22,23,Fizz,Buzz,26,Fizz,28,29,FizzBuzz,31,32,Fizz,34,Buzz,Fizz,37,38,Fizz,Buzz,41,Fizz,43,44,FizzBuzz,46,47,Fizz,49,Buzz,Fizz,52,53,Fizz,Buzz,56,Fizz,58,59,FizzBuzz,61,62,Fizz,64,Buzz,Fizz,67,68,Fizz,Buzz,71,Fizz,73,74,FizzBuzz,76,77,Fizz,79,Buzz,Fizz,82,83,Fizz,Buzz,86,Fizz,88,89,FizzBuzz,91,92,Fizz,94,Buzz,Fizz,97,98,Fizz,
Factorial 6 (with loop and acc): 720
Bob's age: 0
Setting Bob's age to 10
New age: 10
John's age, didn't change: 12
Countdown 2
Countdown 1
Countdown 0
vm - 129 ✅ in 0.254ms
Code segment 170 (length: 36)
/Ark/tests/unittests/resources/LangSuite/builtins-tests.ark
6 0 06 00 00 39 STORE a
1 07 00 00 3a STORE_REF b
2 06 00 00 3b STORE c
3 02 00 00 02 LOAD_FAST_BY_INDEX (2)
4 02 00 00 01 LOAD_FAST_BY_INDEX (1)
5 02 00 00 00 LOAD_FAST_BY_INDEX (0)
6 71 2a 28 00 FUSED_MATH 42, 40, 0
7 0b 00 00 00 RET
8 0c 00 00 00 HALT
Version: 4.2.0
Timestamp: 1771987397
SHA256: 19290414cda62867bfc0dd0d72c2870617aef4edca40fd2a8145cbdca3a43574
Symbols table (length: 0)
Constants table (length: 1)
0) (String) test
Instruction locations table (length: 1)
PP, IP
0, 0 -> /Ark/tests/unittests/resources/DiagnosticsSuite/runtime/assert.ark:0
Code segment 0 (length: 20)
/Ark/tests/unittests/resources/DiagnosticsSuite/runtime/assert.ark
1 0 0d 00 00 04 PUSH_RETURN_ADDRESS
1 04 00 00 00 LOAD_CONST test (String)
2 11 00 00 00 BUILTIN false
3 55 00 20 1a CALL_BUILTIN assert, 2
4 0c 00 00 00 HALT
builtin - 29 ✅ in 2.370ms
operators - 145 ✅ in 0.658ms
module - 2 ✅ in 0.201ms
utf8 - 28 ✅ in 0.140ms
macro - 74 ✅ in 0.286ms
list - 81 ✅ in 0.335ms
string - 35 ✅ in 0.136ms
async - 9 ✅ in 111.876ms
====================
Successes: 532 - Failures: 0
cli - 7 ✅ in 0.736ms
dict - 106 ✅ in 0.880ms
events - 10 ✅ in 0.085ms
exceptions - 3 ✅ in 0.023ms
functional - 12 ✅ in 0.070ms
io - 19 ✅ in 0.823ms
lazy - 4 ✅ in 50.304ms
list - 144 ✅ in 0.970ms
macros - 12 ✅ in 0.045ms
math - 165 ✅ in 0.722ms
random - 18 ✅ in 0.066ms
range - 27 ✅ in 0.162ms
string - 106 ✅ in 1.443ms
switch - 3 ✅ in 0.006ms
sys - 6 ✅ in 0.022ms
====================
Successes: 642 - Failures: 0
1. first
2. second
3. third
1 0 1 1 3 6 15 36 91 232 603 1585 4213 11298 30537 83097 227475 625992 1730787 4805595 13393689 37458330 105089229 295673994 834086421 2358641376 6684761125 18985057351 54022715451 154000562758 439742222071 1257643249140
2, 3, 5, 7, 13, 17, 19, 23, 29, 37, 47, 59, 67, 79, 89, 127, 137, 139, 149, 157, 167, 179, 239, 257, 269, 347, 349, 359, 367, 379, 389, 457, 467, 479, 569, 1237, 1249, 1259, 1279, 1289, 1367, 1459, 1489, 1567, 1579, 1789, 2347, 2357, 2389, 2459, 2467, 2579, 2689, 2789, 3457, 3467, 3469, 4567, 4679, 4789, 5689, 12347, 12379, 12457, 12479, 12569, 12589, 12689, 13457, 13469, 13567, 13679, 13789, 15679, 23459, 23567, 23689, 23789, 25679, 34589, 34679, 123457, 123479, 124567, 124679, 125789, 134789, 145679, 234589, 235679, 235789, 245789, 345679, 345689, 1234789, 1235789, 1245689, 1456789, 12356789, 23456789
Tests run in 04.396s
Suite 'BytecodeReader': all tests passed (25 asserts in 1 tests)
Suite 'Debugger': all tests passed (10 asserts in 1 tests)
Suite 'Diagnostics': all tests passed (490 asserts in 3 tests)
Suite 'Embedding': all tests passed (56 asserts in 13 tests)
Suite 'Examples': all tests passed (18 asserts in 1 tests)
Suite 'Formatter': all tests passed (120 asserts in 2 tests)
Suite 'Lang': all tests passed (6 asserts in 2 tests)
Suite 'NameResolution': all tests passed (40 asserts in 10 tests)
Suite 'Optimizer': all tests passed (4 asserts in 1 tests)
Suite 'Parser': all tests passed (66 asserts in 2 tests)
Suite 'Repl': all tests passed (9 asserts in 2 tests)
Suite 'Rosetta': all tests passed (80 asserts in 1 tests)
Suite 'SharedLib': all tests passed (3 asserts in 2 tests)
Suite 'State': all tests passed (23 asserts in 4 tests)
Suite 'Tools': all tests passed (24 asserts in 6 tests)
Suite 'TypeChecker': all tests passed (52 asserts in 1 tests)
Suite 'Utf8': all tests passed (5 asserts in 2 tests)
Suite 'AST': all tests passed (22 asserts in 1 tests)
===============================================================================
Suite Compiler
tests: 5 | 1 failed
asserts: 101 | 99 passed | 2 failed
Completed =====================================================================However... it's not surprising that when I address one of the first errors related to |
|
You need to compile TestModule for the unit tests, it's a separate target ; I forget to mention it in the docs. And I think you fixed the tests errors that might have been due to the working directory in which you start the executable, which should be the root folder of the project. |
I had already done that, but the problem persisted, until now. 😉
|
|
Honestly, I don't really get those fuzz tests. They just keep running for hours, but what's the point if they keep going forever? What do you expect me to show you? |
|
Nothing, you don't have to run those. The CI usually does it, and I run them on my server a few times a year for big releases. There is also no need to commit the benchmark results for this kind of change, thanks for running them though! The fuzzing job fails on the CI due to the github token permissions, but that's only for writing a comment so it's okay. |
Say no more. Deal! |
|
It's funny how it took me less than a minute to fix it and a little over four days to get the tests in order, but that's all behind me now. Phew! 😂 Thank you for the assistance. |
|
The tests harness can be quite tricky to use... As I've been making it and running it, it's normal to me and I don't see its quirks anymore, but if you have tips / info to add to https://arkscript-lang.dev/docs/reference/testing_arkscript/, I'm all ears! |
Yes, I understand. You can expect more, as I've already encountered a few things. |
Description
This is half of the solution for #643 and is more than workable in principle, but still without color. Regarding color, I noticed that "termcolor" is one of the additional project modules, so I'll see what that leads to. Finally, I'll review the current tests to see if any already exist that test the output flow and any coloration. If not, I'll try to implement such test(s).
Closes #643
Checklist
I have added tests that prove my fix/feature is working