2021-01-21 01:27:36 +02:00
#if 0
2020-06-06 11:22:32 +03:00
# include "logging.hh"
# include "nixexpr.hh"
# include "util.hh"
2020-06-19 23:54:41 +03:00
# include <fstream>
2020-06-06 11:22:32 +03:00
# include <gtest/gtest.h>
namespace nix {
/* ----------------------------------------------------------------------------
* logEI
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2020-06-25 03:31:28 +03:00
const char * test_file =
2020-06-24 00:30:13 +03:00
" previous line of code \n "
" this is the problem line of code \n "
" next line of code \n " ;
2020-06-25 03:31:28 +03:00
const char * one_liner =
" this is the other problem line of code " ;
2020-06-24 00:30:13 +03:00
2020-06-06 11:22:32 +03:00
TEST ( logEI , catpuresBasicProperties ) {
MakeError ( TestError , Error ) ;
ErrorInfo : : programName = std : : optional ( " error-unit-test " ) ;
try {
throw TestError ( " an error for testing purposes " ) ;
} catch ( Error & e ) {
testing : : internal : : CaptureStderr ( ) ;
logger - > logEI ( e . info ( ) ) ;
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-16 10:44:19 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [31;1merror: \x1B [0m \x1B [34;1m --- TestError --- error-unit-test \x1B [0m \n an error for testing purposes \n " ) ;
2020-06-06 11:22:32 +03:00
}
}
libutil/logging: extend `internal-json` logger to make it more machine-readable
The new error-format is pretty nice from a UX point-of-view, however
it's fairly hard to parse the output e.g. for editor plugins such as
vim-ale[1] that use `nix-instantiate --parse` to determine syntax errors in
Nix expression files.
This patch extends the `internal-json` logger by adding the fields
`line`, `column` and `file` to easily locate an error in a file and the
field `raw_msg` which contains the error-message itself without
code-lines and additional helpers.
An exemplary output may look like this:
```
[nix-shell]$ ./inst/bin/nix-instantiate ~/test.nix --log-format minimal
{"action":"msg","column":1,"file":"/home/ma27/test.nix","level":0,"line":4,"raw_msg":"syntax error, unexpected IF, expecting $end","msg":"<full error-msg with code-lines etc>"}
```
[1] https://github.com/dense-analysis/ale
2020-07-22 00:38:18 +03:00
TEST ( logEI , jsonOutput ) {
SymbolTable testTable ;
auto problem_file = testTable . create ( " random.nix " ) ;
testing : : internal : : CaptureStderr ( ) ;
makeJSONLogger ( * logger ) - > logEI ( {
. name = " error name " ,
2021-01-21 01:27:36 +02:00
. msg = hintfmt ( " this hint has %1% templated %2%!! " ,
libutil/logging: extend `internal-json` logger to make it more machine-readable
The new error-format is pretty nice from a UX point-of-view, however
it's fairly hard to parse the output e.g. for editor plugins such as
vim-ale[1] that use `nix-instantiate --parse` to determine syntax errors in
Nix expression files.
This patch extends the `internal-json` logger by adding the fields
`line`, `column` and `file` to easily locate an error in a file and the
field `raw_msg` which contains the error-message itself without
code-lines and additional helpers.
An exemplary output may look like this:
```
[nix-shell]$ ./inst/bin/nix-instantiate ~/test.nix --log-format minimal
{"action":"msg","column":1,"file":"/home/ma27/test.nix","level":0,"line":4,"raw_msg":"syntax error, unexpected IF, expecting $end","msg":"<full error-msg with code-lines etc>"}
```
[1] https://github.com/dense-analysis/ale
2020-07-22 00:38:18 +03:00
" yellow " ,
" values " ) ,
. errPos = Pos ( foFile , problem_file , 02 , 13 )
} ) ;
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-12-22 17:23:57 +02:00
ASSERT_STREQ ( str . c_str ( ) , " @nix { \" action \" : \" msg \" , \" column \" :13, \" file \" : \" random.nix \" , \" level \" :0, \" line \" :2, \" msg \" : \" \\ u001b[31;1merror: \\ u001b[0m \\ u001b[34;1m --- error name --- error-unit-test \\ u001b[0m \\ n \\ u001b[34;1mat: \\ u001b[33;1m(2:13) \\ u001b[34;1m in file: \\ u001b[0mrandom.nix \\ n \\ nerror without any code lines. \\ n \\ nthis hint has \\ u001b[33;1myellow \\ u001b[0m templated \\ u001b[33;1mvalues \\ u001b[0m!! \" , \" raw_msg \" : \" this hint has \\ u001b[33;1myellow \\ u001b[0m templated \\ u001b[33;1mvalues \\ u001b[0m!! \" } \n " ) ;
libutil/logging: extend `internal-json` logger to make it more machine-readable
The new error-format is pretty nice from a UX point-of-view, however
it's fairly hard to parse the output e.g. for editor plugins such as
vim-ale[1] that use `nix-instantiate --parse` to determine syntax errors in
Nix expression files.
This patch extends the `internal-json` logger by adding the fields
`line`, `column` and `file` to easily locate an error in a file and the
field `raw_msg` which contains the error-message itself without
code-lines and additional helpers.
An exemplary output may look like this:
```
[nix-shell]$ ./inst/bin/nix-instantiate ~/test.nix --log-format minimal
{"action":"msg","column":1,"file":"/home/ma27/test.nix","level":0,"line":4,"raw_msg":"syntax error, unexpected IF, expecting $end","msg":"<full error-msg with code-lines etc>"}
```
[1] https://github.com/dense-analysis/ale
2020-07-22 00:38:18 +03:00
}
2020-06-06 11:22:32 +03:00
TEST ( logEI , appendingHintsToPreviousError ) {
MakeError ( TestError , Error ) ;
ErrorInfo : : programName = std : : optional ( " error-unit-test " ) ;
try {
auto e = Error ( " initial error " ) ;
throw TestError ( e . info ( ) ) ;
} catch ( Error & e ) {
ErrorInfo ei = e . info ( ) ;
2021-01-21 01:27:36 +02:00
ei . msg = hintfmt ( " %s; subsequent error message. " , normaltxt ( e . info ( ) . msg . str ( ) ) ) ;
2020-06-06 11:22:32 +03:00
testing : : internal : : CaptureStderr ( ) ;
logger - > logEI ( ei ) ;
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-22 20:32:20 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [31;1merror: \x1B [0m \x1B [34;1m --- TestError --- error-unit-test \x1B [0m \n initial error; subsequent error message. \n " ) ;
2020-06-06 11:22:32 +03:00
}
}
TEST ( logEI , picksUpSysErrorExitCode ) {
MakeError ( TestError , Error ) ;
ErrorInfo : : programName = std : : optional ( " error-unit-test " ) ;
try {
auto x = readFile ( - 1 ) ;
}
catch ( SysError & e ) {
testing : : internal : : CaptureStderr ( ) ;
logError ( e . info ( ) ) ;
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-22 20:32:20 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [31;1merror: \x1B [0m \x1B [34;1m --- SysError --- error-unit-test \x1B [0m \n statting file: \x1B [33;1mBad file descriptor \x1B [0m \n " ) ;
2020-06-06 11:22:32 +03:00
}
}
TEST ( logEI , loggingErrorOnInfoLevel ) {
testing : : internal : : CaptureStderr ( ) ;
logger - > logEI ( { . level = lvlInfo ,
2020-06-20 00:28:13 +03:00
. name = " Info name " ,
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-16 10:44:19 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [32;1minfo: \x1B [0m \x1B [34;1m --- Info name --- error-unit-test \x1B [0m \n Info description \n " ) ;
2020-06-06 11:22:32 +03:00
}
TEST ( logEI , loggingErrorOnTalkativeLevel ) {
2020-06-07 16:24:49 +03:00
verbosity = lvlTalkative ;
2020-06-06 11:22:32 +03:00
testing : : internal : : CaptureStderr ( ) ;
logger - > logEI ( { . level = lvlTalkative ,
. name = " Talkative name " ,
2020-06-20 00:28:13 +03:00
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-16 10:44:19 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [32;1mtalk: \x1B [0m \x1B [34;1m --- Talkative name --- error-unit-test \x1B [0m \n Talkative description \n " ) ;
2020-06-06 11:22:32 +03:00
}
TEST ( logEI , loggingErrorOnChattyLevel ) {
2020-06-07 16:24:49 +03:00
verbosity = lvlChatty ;
2020-06-06 11:22:32 +03:00
testing : : internal : : CaptureStderr ( ) ;
logger - > logEI ( { . level = lvlChatty ,
. name = " Chatty name " ,
2020-06-20 00:28:13 +03:00
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-16 10:44:19 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [32;1mchat: \x1B [0m \x1B [34;1m --- Chatty name --- error-unit-test \x1B [0m \n Talkative description \n " ) ;
2020-06-06 11:22:32 +03:00
}
TEST ( logEI , loggingErrorOnDebugLevel ) {
2020-06-07 16:24:49 +03:00
verbosity = lvlDebug ;
2020-06-06 11:22:32 +03:00
testing : : internal : : CaptureStderr ( ) ;
logger - > logEI ( { . level = lvlDebug ,
. name = " Debug name " ,
2020-06-20 00:28:13 +03:00
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-16 10:44:19 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [33;1mdebug: \x1B [0m \x1B [34;1m --- Debug name --- error-unit-test \x1B [0m \n Debug description \n " ) ;
2020-06-06 11:22:32 +03:00
}
TEST ( logEI , loggingErrorOnVomitLevel ) {
2020-06-07 16:24:49 +03:00
verbosity = lvlVomit ;
2020-06-06 11:22:32 +03:00
testing : : internal : : CaptureStderr ( ) ;
logger - > logEI ( { . level = lvlVomit ,
. name = " Vomit name " ,
2020-06-20 00:28:13 +03:00
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-16 10:44:19 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [32;1mvomit: \x1B [0m \x1B [34;1m --- Vomit name --- error-unit-test \x1B [0m \n Vomit description \n " ) ;
2020-06-06 11:22:32 +03:00
}
/* ----------------------------------------------------------------------------
* logError
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
TEST ( logError , logErrorWithoutHintOrCode ) {
testing : : internal : : CaptureStderr ( ) ;
logError ( {
. name = " name " ,
2020-06-20 00:28:13 +03:00
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-16 10:44:19 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [31;1merror: \x1B [0m \x1B [34;1m --- name --- error-unit-test \x1B [0m \n error description \n " ) ;
2020-06-06 11:22:32 +03:00
}
TEST ( logError , logErrorWithPreviousAndNextLinesOfCode ) {
SymbolTable testTable ;
2020-06-24 00:30:13 +03:00
auto problem_file = testTable . create ( test_file ) ;
2020-06-06 11:22:32 +03:00
testing : : internal : : CaptureStderr ( ) ;
logError ( {
. name = " error name " ,
2021-01-21 01:27:36 +02:00
. msg = hintfmt ( " this hint has %1% templated %2%!! " ,
2020-06-20 00:28:13 +03:00
" yellow " ,
" values " ) ,
2020-06-24 00:30:13 +03:00
. errPos = Pos ( foString , problem_file , 02 , 13 ) ,
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-07-01 07:05:21 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [31;1merror: \x1B [0m \x1B [34;1m --- error name --- error-unit-test \x1B [0m \n \x1B [34;1mat: \x1B [33;1m(2:13) \x1B [34;1m from string \x1B [0m \n \n error with code lines \n \n 1| previous line of code \n 2| this is the problem line of code \n | \x1B [31;1m^ \x1B [0m \n 3| next line of code \n \n this hint has \x1B [33;1myellow \x1B [0m templated \x1B [33;1mvalues \x1B [0m!! \n " ) ;
2020-06-06 11:22:32 +03:00
}
2020-06-24 00:30:13 +03:00
TEST ( logError , logErrorWithInvalidFile ) {
2020-06-06 11:22:32 +03:00
SymbolTable testTable ;
2020-06-24 00:30:13 +03:00
auto problem_file = testTable . create ( " invalid filename " ) ;
2020-06-06 11:22:32 +03:00
testing : : internal : : CaptureStderr ( ) ;
logError ( {
. name = " error name " ,
2021-01-21 01:27:36 +02:00
. msg = hintfmt ( " this hint has %1% templated %2%!! " ,
2020-06-20 00:28:13 +03:00
" yellow " ,
" values " ) ,
2020-06-24 00:30:13 +03:00
. errPos = Pos ( foFile , problem_file , 02 , 13 )
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-12-22 17:23:57 +02:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [31;1merror: \x1B [0m \x1B [34;1m --- error name --- error-unit-test \x1B [0m \n \x1B [34;1mat: \x1B [33;1m(2:13) \x1B [34;1m in file: \x1B [0minvalid filename \n \n error without any code lines. \n \n this hint has \x1B [33;1myellow \x1B [0m templated \x1B [33;1mvalues \x1B [0m!! \n " ) ;
2020-06-06 11:22:32 +03:00
}
TEST ( logError , logErrorWithOnlyHintAndName ) {
testing : : internal : : CaptureStderr ( ) ;
logError ( {
. name = " error name " ,
2021-01-21 01:27:36 +02:00
. msg = hintfmt ( " hint %1% " , " only " ) ,
2020-06-24 00:30:13 +03:00
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-24 00:30:13 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [31;1merror: \x1B [0m \x1B [34;1m --- error name --- error-unit-test \x1B [0m \n hint \x1B [33;1monly \x1B [0m \n " ) ;
2020-06-06 11:22:32 +03:00
}
/* ----------------------------------------------------------------------------
* logWarning
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
TEST ( logWarning , logWarningWithNameDescriptionAndHint ) {
testing : : internal : : CaptureStderr ( ) ;
logWarning ( {
2020-06-20 00:28:13 +03:00
. name = " name " ,
2021-01-21 01:27:36 +02:00
. msg = hintfmt ( " there was a %1% " , " warning " ) ,
2020-06-20 00:28:13 +03:00
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-24 00:30:13 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [33;1mwarning: \x1B [0m \x1B [34;1m --- name --- error-unit-test \x1B [0m \n warning description \n \n there was a \x1B [33;1mwarning \x1B [0m \n " ) ;
2020-06-06 11:22:32 +03:00
}
TEST ( logWarning , logWarningWithFileLineNumAndCode ) {
SymbolTable testTable ;
2020-06-24 00:30:13 +03:00
auto problem_file = testTable . create ( test_file ) ;
2020-06-06 11:22:32 +03:00
testing : : internal : : CaptureStderr ( ) ;
logWarning ( {
. name = " warning name " ,
2021-01-21 01:27:36 +02:00
. msg = hintfmt ( " this hint has %1% templated %2%!! " ,
2020-06-20 00:28:13 +03:00
" yellow " ,
" values " ) ,
2020-06-24 00:30:13 +03:00
. errPos = Pos ( foStdin , problem_file , 2 , 13 ) ,
} ) ;
2020-06-06 11:22:32 +03:00
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-06-24 00:30:13 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [33;1mwarning: \x1B [0m \x1B [34;1m --- warning name --- error-unit-test \x1B [0m \n \x1B [34;1mat: \x1B [33;1m(2:13) \x1B [34;1m from stdin \x1B [0m \n \n warning description \n \n 1| previous line of code \n 2| this is the problem line of code \n | \x1B [31;1m^ \x1B [0m \n 3| next line of code \n \n this hint has \x1B [33;1myellow \x1B [0m templated \x1B [33;1mvalues \x1B [0m!! \n " ) ;
2020-06-06 11:22:32 +03:00
}
2020-06-19 23:54:41 +03:00
/* ----------------------------------------------------------------------------
2020-06-25 03:31:28 +03:00
* traces
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
TEST ( addTrace , showTracesWithShowTrace ) {
SymbolTable testTable ;
auto problem_file = testTable . create ( test_file ) ;
auto oneliner_file = testTable . create ( one_liner ) ;
2020-07-06 19:51:48 +03:00
auto invalidfilename = testTable . create ( " invalid filename " ) ;
2020-06-25 03:31:28 +03:00
auto e = AssertionError ( ErrorInfo {
. name = " wat " ,
2021-01-21 01:27:36 +02:00
. msg = hintfmt ( " it has been %1% days since our last error " , " zero " ) ,
2020-06-25 03:31:28 +03:00
. errPos = Pos ( foString , problem_file , 2 , 13 ) ,
} ) ;
e . addTrace ( Pos ( foStdin , oneliner_file , 1 , 19 ) , " while trying to compute %1% " , 42 ) ;
2020-07-01 19:37:31 +03:00
e . addTrace ( std : : nullopt , " while doing something without a %1% " , " pos " ) ;
2020-07-06 19:51:48 +03:00
e . addTrace ( Pos ( foFile , invalidfilename , 100 , 1 ) , " missing %s " , " nix file " ) ;
2020-06-25 03:31:28 +03:00
testing : : internal : : CaptureStderr ( ) ;
2020-07-02 18:04:31 +03:00
loggerSettings . showTrace . assign ( true ) ;
2020-07-01 07:05:21 +03:00
2020-06-25 03:31:28 +03:00
logError ( e . info ( ) ) ;
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-12-22 17:23:57 +02:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [31;1merror: \x1B [0m \x1B [34;1m --- AssertionError --- error-unit-test \x1B [0m \n \x1B [34;1mat: \x1B [33;1m(2:13) \x1B [34;1m from string \x1B [0m \n \n show-traces \n \n 1| previous line of code \n 2| this is the problem line of code \n | \x1B [31;1m^ \x1B [0m \n 3| next line of code \n \n it has been \x1B [33;1mzero \x1B [0m days since our last error \n \x1B [34;1m---- show-trace ---- \x1B [0m \n \x1B [34;1mtrace: \x1B [0mwhile trying to compute \x1B [33;1m42 \x1B [0m \n \x1B [34;1mat: \x1B [33;1m(1:19) \x1B [34;1m from stdin \x1B [0m \n \n 1| this is the other problem line of code \n | \x1B [31;1m^ \x1B [0m \n \n \x1B [34;1mtrace: \x1B [0mwhile doing something without a \x1B [33;1mpos \x1B [0m \n \x1B [34;1mtrace: \x1B [0mmissing \x1B [33;1mnix file \x1B [0m \n \x1B [34;1mat: \x1B [33;1m(100:1) \x1B [34;1m in file: \x1B [0minvalid filename \n " ) ;
2020-06-25 03:31:28 +03:00
}
2020-06-25 18:23:12 +03:00
TEST ( addTrace , hideTracesWithoutShowTrace ) {
SymbolTable testTable ;
auto problem_file = testTable . create ( test_file ) ;
auto oneliner_file = testTable . create ( one_liner ) ;
2020-07-06 19:51:48 +03:00
auto invalidfilename = testTable . create ( " invalid filename " ) ;
2020-06-25 18:23:12 +03:00
auto e = AssertionError ( ErrorInfo {
. name = " wat " ,
2021-01-21 01:27:36 +02:00
. msg = hintfmt ( " it has been %1% days since our last error " , " zero " ) ,
2020-06-25 18:23:12 +03:00
. errPos = Pos ( foString , problem_file , 2 , 13 ) ,
} ) ;
e . addTrace ( Pos ( foStdin , oneliner_file , 1 , 19 ) , " while trying to compute %1% " , 42 ) ;
2020-07-01 19:37:31 +03:00
e . addTrace ( std : : nullopt , " while doing something without a %1% " , " pos " ) ;
2020-07-06 19:51:48 +03:00
e . addTrace ( Pos ( foFile , invalidfilename , 100 , 1 ) , " missing %s " , " nix file " ) ;
2020-06-25 18:23:12 +03:00
testing : : internal : : CaptureStderr ( ) ;
2020-07-02 18:04:31 +03:00
loggerSettings . showTrace . assign ( false ) ;
2020-07-01 07:05:21 +03:00
2020-06-25 18:23:12 +03:00
logError ( e . info ( ) ) ;
auto str = testing : : internal : : GetCapturedStderr ( ) ;
2020-07-06 19:51:48 +03:00
ASSERT_STREQ ( str . c_str ( ) , " \x1B [31;1merror: \x1B [0m \x1B [34;1m --- AssertionError --- error-unit-test \x1B [0m \n \x1B [34;1mat: \x1B [33;1m(2:13) \x1B [34;1m from string \x1B [0m \n \n hide traces \n \n 1| previous line of code \n 2| this is the problem line of code \n | \x1B [31;1m^ \x1B [0m \n 3| next line of code \n \n it has been \x1B [33;1mzero \x1B [0m days since our last error \n " ) ;
2020-06-25 18:23:12 +03:00
}
2020-07-06 19:51:48 +03:00
2020-06-25 03:31:28 +03:00
/* ----------------------------------------------------------------------------
2020-06-19 23:54:41 +03:00
* hintfmt
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
2020-06-20 00:28:13 +03:00
TEST ( hintfmt , percentStringWithoutArgs ) {
2020-06-19 23:54:41 +03:00
2020-06-20 00:28:13 +03:00
const char * teststr = " this is 100%s correct! " ;
2020-06-19 23:54:41 +03:00
2020-06-20 01:58:12 +03:00
ASSERT_STREQ (
hintfmt ( teststr ) . str ( ) . c_str ( ) ,
teststr ) ;
2020-06-19 23:54:41 +03:00
2020-06-20 00:28:13 +03:00
}
2020-06-19 23:54:41 +03:00
2020-06-20 01:46:49 +03:00
TEST ( hintfmt , fmtToHintfmt ) {
2020-06-20 01:58:12 +03:00
ASSERT_STREQ (
hintfmt ( fmt ( " the color of this this text is %1% " , " not yellow " ) ) . str ( ) . c_str ( ) ,
" the color of this this text is not yellow " ) ;
2020-06-20 01:46:49 +03:00
}
2020-06-20 00:28:13 +03:00
TEST ( hintfmt , tooFewArguments ) {
2020-06-19 23:54:41 +03:00
2020-06-20 00:28:13 +03:00
ASSERT_STREQ (
hintfmt ( " only one arg %1% %2% " , " fulfilled " ) . str ( ) . c_str ( ) ,
2021-09-14 11:38:10 +03:00
" only one arg " ANSI_WARNING " fulfilled " ANSI_NORMAL " " ) ;
2020-06-20 00:28:13 +03:00
}
TEST ( hintfmt , tooManyArguments ) {
ASSERT_STREQ (
hintfmt ( " what about this %1% %2% " , " %3% " , " one " , " two " ) . str ( ) . c_str ( ) ,
2021-09-14 11:38:10 +03:00
" what about this " ANSI_WARNING " %3% " ANSI_NORMAL " " ANSI_YELLOW " one " ANSI_NORMAL ) ;
2020-06-20 00:28:13 +03:00
}
2020-06-30 20:01:46 +03:00
/* ----------------------------------------------------------------------------
* ErrPos
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
TEST ( errpos , invalidPos ) {
// contains an invalid symbol, which we should not dereference!
Pos invalid ;
// constructing without access violation.
ErrPos ep ( invalid ) ;
2022-03-01 20:31:36 +02:00
2020-06-30 20:01:46 +03:00
// assignment without access violation.
ep = invalid ;
}
2020-06-06 11:22:32 +03:00
}
2021-01-21 01:27:36 +02:00
# endif