Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeMirzayanov committed Sep 24, 2024
1 parent 96fd1b8 commit 558dd2e
Show file tree
Hide file tree
Showing 16 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion testlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -4917,7 +4917,7 @@ static inline void __testlib_ensure(bool cond, const char *msg) {
}

#define ensure(cond) __testlib_ensure((cond), "Condition failed: \"" #cond "\"")
#define STRINGIZE_DETAIL(x) #x
#define STRINGIZE_DETAIL(x) (#x)
#define STRINGIZE(x) STRINGIZE_DETAIL((x))
#define ensure_ext(cond) __testlib_ensure((cond), "Line " STRINGIZE(__LINE__) ": Condition failed: \"" #cond "\"")

Expand Down
18 changes: 18 additions & 0 deletions tests/test-008_format/files/test-format-format1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#if (__cplusplus >= 202002L && __has_include(<format>))
# include <format>
#endif

#include "testlib.h"

using namespace std;

int main(int argc, char** argv) {
registerGen(argc, argv, 1);

println(format("%d", 42));
println(format("hello, %s!", "hat"));
println(format("%s%d!", "'hat'", 42));
println(format("%s%d!", "'%s'", 42));

ensure(format("%f", 42.5).substr(0, 4) == "42.5");
}
18 changes: 18 additions & 0 deletions tests/test-008_format/files/test-format-format2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "testlib.h"

#if (__cplusplus >= 202002L && __has_include(<format>))
# include <format>
#endif

using namespace std;

int main(int argc, char** argv) {
registerGen(argc, argv, 1);

println(format("%d", 42));
println(format("hello, %s!", "hat"));
println(format("%s%d!", "'hat'", 42));
println(format("%s%d!", "'%s'", 42));

ensure(format("%f", 42.5).substr(0, 4) == "42.5");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Empty file.
4 changes: 4 additions & 0 deletions tests/test-008_format/refs/test-format-format1/r1/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
42
hello, hat!
'hat'42!
'%s'42!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Empty file.
4 changes: 4 additions & 0 deletions tests/test-008_format/refs/test-format-format1/r2/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
42
hello, hat!
'hat'42!
'%s'42!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Empty file.
4 changes: 4 additions & 0 deletions tests/test-008_format/refs/test-format-format2/r1/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
42
hello, hat!
'hat'42!
'%s'42!
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
Empty file.
4 changes: 4 additions & 0 deletions tests/test-008_format/refs/test-format-format2/r2/stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
42
hello, hat!
'hat'42!
'%s'42!
10 changes: 10 additions & 0 deletions tests/test-008_format/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ bash ../scripts/compile files/test-format.cpp
bash ../scripts/test-ref test-format/r1 ./test-format
bash ../scripts/test-ref test-format/r2 "$VALGRIND" ./test-format
rm -f test-format test-format.exe

bash ../scripts/compile files/test-format-format1.cpp
bash ../scripts/test-ref test-format-format1/r1 ./test-format-format1
bash ../scripts/test-ref test-format-format1/r2 "$VALGRIND" ./test-format-format1
rm -f test-format-format1 test-format-format1.exe

bash ../scripts/compile files/test-format-format2.cpp
bash ../scripts/test-ref test-format-format2/r1 ./test-format-format2
bash ../scripts/test-ref test-format-format2/r2 "$VALGRIND" ./test-format-format2
rm -f test-format-format2 test-format-format2.exe

0 comments on commit 558dd2e

Please sign in to comment.