2020-12-20 00:22:44 +01:00
|
|
|
//usr/bin/env cc -o test "$0" && ./test; exit
|
2020-12-20 00:36:22 +01:00
|
|
|
|
|
|
|
// (run this file directly with `./test.c` in most shells; if that
|
|
|
|
// doesn't work, run it with `sh test.c`)
|
|
|
|
|
2020-12-20 00:22:44 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-12-29 11:35:03 +01:00
|
|
|
#include <sys/stat.h>
|
2020-12-25 22:40:18 +01:00
|
|
|
|
|
|
|
#include <unistd.h>
|
2020-12-20 00:22:44 +01:00
|
|
|
#include <assert.h>
|
2020-12-23 05:34:01 +01:00
|
|
|
#include <wordexp.h>
|
2020-12-20 00:22:44 +01:00
|
|
|
|
2020-12-20 00:36:22 +01:00
|
|
|
int file_contents_equal(char* path, char* contents) {
|
2020-12-23 01:36:09 +01:00
|
|
|
// hehe: https://twitter.com/ianh_/status/1340450349065244675
|
|
|
|
setenv("path", path, 1);
|
|
|
|
setenv("contents", contents, 1);
|
|
|
|
return system("[ \"$contents\" == \"$(cat \"$path\")\" ]") == 0;
|
2020-12-20 00:36:22 +01:00
|
|
|
}
|
|
|
|
|
2020-12-25 22:40:18 +01:00
|
|
|
char* expand(char* phrase) { // expand path with wildcard
|
2020-12-23 05:34:01 +01:00
|
|
|
wordexp_t result; assert(wordexp(phrase, &result, 0) == 0);
|
|
|
|
return result.we_wordv[0];
|
|
|
|
}
|
|
|
|
|
2020-12-20 00:22:44 +01:00
|
|
|
// integration tests
|
2020-12-23 01:36:09 +01:00
|
|
|
int main() {
|
2020-12-29 11:35:03 +01:00
|
|
|
assert(system("node ../extension/background.js --unhandled-rejections=strict") == 0); // run quick local JS tests
|
2020-12-25 23:55:35 +01:00
|
|
|
|
2020-12-25 22:40:18 +01:00
|
|
|
// reload the extension so we know it's the latest code.
|
2020-12-29 11:35:03 +01:00
|
|
|
system("echo reload > ../fs/mnt/runtime/reload 2>/dev/null"); // this may error, but it should still have effect
|
|
|
|
// spin until the extension reloads.
|
|
|
|
struct stat st; while (stat("../fs/mnt/tabs", &st) != 0) {}
|
|
|
|
|
|
|
|
assert(file_contents_equal(expand("../fs/mnt/extensions/TabFS*/enabled"), "true"));
|
2020-12-25 22:40:18 +01:00
|
|
|
|
2020-12-26 00:42:38 +01:00
|
|
|
// FIXME: synthesize some kind of web page
|
2020-12-29 11:35:03 +01:00
|
|
|
assert(system("echo about:blank > ../fs/mnt/tabs/create") == 0);
|
2020-12-26 00:42:38 +01:00
|
|
|
// FIXME: race here
|
2020-12-29 11:35:03 +01:00
|
|
|
assert(file_contents_equal("../fs/mnt/tabs/last-focused/url.txt", "about:blank"));
|
|
|
|
assert(system("echo remove > ../fs/mnt/tabs/last-focused/control") == 0);
|
2020-12-23 05:34:01 +01:00
|
|
|
|
2020-12-20 00:22:44 +01:00
|
|
|
assert(1); printf("Done!\n");
|
|
|
|
}
|