tests: support `// vtest vflags: -prod` in `coutput_test.v`.

Use it, to add a `-prod` test for `$embed_file()`,
to prevent future codegen regressions.
pull/12077/head
Delyan Angelov 2021-10-05 15:43:33 +03:00
parent e23d61d99e
commit ccb5f1d563
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
5 changed files with 83 additions and 1 deletions

View File

@ -100,7 +100,8 @@ fn test_c_must_have_files() ? {
basename, path, relpath, must_have_relpath := target2paths(must_have_path, '.c.must_have') basename, path, relpath, must_have_relpath := target2paths(must_have_path, '.c.must_have')
print(term.colorize(term.magenta, 'v -o - $relpath') + ' matches all line paterns in ' + print(term.colorize(term.magenta, 'v -o - $relpath') + ' matches all line paterns in ' +
term.colorize(term.magenta, must_have_relpath) + ' ') term.colorize(term.magenta, must_have_relpath) + ' ')
compilation := os.execute('$vexe -o - $path') file_options := get_file_options(path)
compilation := os.execute('$vexe -o - $file_options.vflags $path')
ensure_compilation_succeeded(compilation) ensure_compilation_succeeded(compilation)
expected_lines := os.read_lines(must_have_path) or { [] } expected_lines := os.read_lines(must_have_path) or { [] }
generated_c_lines := compilation.output.split_into_lines() generated_c_lines := compilation.output.split_into_lines()
@ -172,3 +173,19 @@ fn target2paths(target_path string, postfix string) (string, string, string, str
target_relpath := vroot_relative(target_path) target_relpath := vroot_relative(target_path)
return basename, path, relpath, target_relpath return basename, path, relpath, target_relpath
} }
struct FileOptions {
mut:
vflags string
}
pub fn get_file_options(file string) FileOptions {
mut res := FileOptions{}
lines := os.read_lines(file) or { [] }
for line in lines {
if line.starts_with('// vtest vflags:') {
res.vflags = line.all_after(':').trim_space()
}
}
return res
}

View File

@ -0,0 +1,19 @@
typedef struct v__embed_file__EmbedFileData v__embed_file__EmbedFileData;
typedef struct v__embed_file__EmbedFileIndexEntry v__embed_file__EmbedFileIndexEntry;
struct v__embed_file__EmbedFileData {
struct v__embed_file__EmbedFileIndexEntry {
string v__embed_file__EmbedFileData_str(v__embed_file__EmbedFileData ed);
void v__embed_file__EmbedFileData_free(v__embed_file__EmbedFileData* ed);
byte* v__embed_file__EmbedFileData_data(v__embed_file__EmbedFileData* ed);
v__embed_file__EmbedFileIndexEntry* v__embed_file__find_index_entry_by_path(voidptr start, string path);
string v__embed_file__EmbedFileData_str(v__embed_file__EmbedFileData ed) {
string v__embed_file__EmbedFileData_to_string(v__embed_file__EmbedFileData* original) {
v__embed_file__EmbedFileIndexEntry* v__embed_file__find_index_entry_by_path(voidptr start, string path) {
v__embed_file__EmbedFileData my_source = (v__embed_file__EmbedFileData){
.path = _SLIT("embed.vv"),
// Initializations for module v.embed_file :

7
vlib/v/gen/c/testdata/embed.vv vendored 100644
View File

@ -0,0 +1,7 @@
fn main() {
mut my_source := $embed_file('embed.vv')
assert my_source.len > 0
s := my_source.to_string()
assert s.len > 0
print(s)
}

View File

@ -0,0 +1,31 @@
#define _VPROD (1)
// V embedded data:
static const unsigned char _v_embed_blob_0[138] = {
0x66,0x6e,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x20,0x7b,0x0a,0x09,0x6d,0x75,0x74,
const v__embed_file__EmbedFileIndexEntry _v_embed_file_index[] = {
{0, { .str=(byteptr)("embed.vv"), .len=7, .is_lit=1 }, _v_embed_blob_0},
{-1, { .str=(byteptr)(""), .len=0, .is_lit=1 }, NULL}
};
typedef struct v__embed_file__EmbedFileData v__embed_file__EmbedFileData;
typedef struct v__embed_file__EmbedFileIndexEntry v__embed_file__EmbedFileIndexEntry;
struct v__embed_file__EmbedFileData {
struct v__embed_file__EmbedFileIndexEntry {
string v__embed_file__EmbedFileData_str(v__embed_file__EmbedFileData ed);
void v__embed_file__EmbedFileData_free(v__embed_file__EmbedFileData* ed);
byte* v__embed_file__EmbedFileData_data(v__embed_file__EmbedFileData* ed);
v__embed_file__EmbedFileIndexEntry* v__embed_file__find_index_entry_by_path(voidptr start, string path);
string v__embed_file__EmbedFileData_str(v__embed_file__EmbedFileData ed) {
string v__embed_file__EmbedFileData_to_string(v__embed_file__EmbedFileData* original) {
v__embed_file__EmbedFileIndexEntry* v__embed_file__find_index_entry_by_path(voidptr start, string path) {
v__embed_file__EmbedFileData my_source = (v__embed_file__EmbedFileData){
.path = _SLIT("embed.vv"),
.compressed = v__embed_file__find_index_entry_by_path((voidptr)_v_embed_file_index, _SLIT("embed.vv"))->data,
// Initializations for module v.embed_file :

View File

@ -0,0 +1,8 @@
// vtest vflags: -prod
fn main() {
mut my_source := $embed_file('embed.vv')
assert my_source.len > 0
s := my_source.to_string()
assert s.len > 0
print(s)
}