diff options
author | ridiculousfish <corydoras@ridiculousfish.com> | 2014-04-27 13:34:51 -0700 |
---|---|---|
committer | ridiculousfish <corydoras@ridiculousfish.com> | 2014-04-27 13:35:32 -0700 |
commit | 3b4794ae94157408de4cac33a50522be230feee0 (patch) | |
tree | 76d26d7b62244abed8bc44f4c91a27f3bf4c03a3 /fish_tests.cpp | |
parent | 6a94b51cbadb8609580fac5c693c02ca4ab39734 (diff) |
Implement atomic loading/saving of fishd file within fish, eventually
permitting removal of fishd. Universal variables test passes, others
fail.
Diffstat (limited to 'fish_tests.cpp')
-rw-r--r-- | fish_tests.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/fish_tests.cpp b/fish_tests.cpp index 382abb39..37991aa1 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -63,6 +63,7 @@ #include "pager.h" #include "input.h" #include "utf8.h" +#include "env_universal_common.h" static const char * const * s_arguments; static int s_test_run_count = 0; @@ -2159,6 +2160,62 @@ static void test_input() } } +#define UVARS_PER_THREAD 100 + +static int test_universal_helper(int *x) +{ + env_universal_t uvars(L"/tmp/fish_uvars_test/varsfile.txt"); + for (int j=0; j < UVARS_PER_THREAD; j++) + { + const wcstring key = format_string(L"key_%d_%d", *x, j); + const wcstring val = format_string(L"val_%d_%d", *x, j); + uvars.set(key, val, false); + bool saved = uvars.save(); + if (! saved) + { + err(L"Failed to save universal variables"); + } + fputc('.', stderr); + fflush(stderr); + } + return 0; +} + +static void test_universal() +{ + say(L"Testing universal variables"); + if (system("mkdir -p /tmp/fish_uvars_test/")) err(L"mkdir failed"); + + const int threads = 32; + for (int i=0; i < threads; i++) + { + iothread_perform(test_universal_helper, (void (*)(int *, int))NULL, new int(i)); + } + iothread_drain_all(); + + env_universal_t uvars(L"/tmp/fish_uvars_test/varsfile.txt"); + bool loaded = uvars.load(); + if (! loaded) + { + err(L"Failed to load universal variables"); + } + for (int i=0; i < threads; i++) + { + for (int j=0; j < UVARS_PER_THREAD; j++) + { + const wcstring key = format_string(L"key_%d_%d", i, j); + const wcstring val = format_string(L"val_%d_%d", i, j); + const env_var_t var = uvars.get(key); + if (var != val) + { + err(L"Wrong value for key %ls: %ls vs %ls\n", key.c_str(), val.c_str(), var.missing() ? L"<missing>" : var.c_str()); + } + } + } + + system("rm -Rf /tmp/fish_uvars_test"); +} + class history_tests_t { public: @@ -3211,6 +3268,7 @@ int main(int argc, char **argv) if (should_test_function("colors")) test_colors(); if (should_test_function("complete")) test_complete(); if (should_test_function("input")) test_input(); + if (should_test_function("universal")) test_universal(); if (should_test_function("completion_insertions")) test_completion_insertions(); if (should_test_function("autosuggestion_combining")) test_autosuggestion_combining(); if (should_test_function("autosuggest_suggest_special")) test_autosuggest_suggest_special(); |