import std::generic_os::setenv;
import std::generic_os::getenv;
import std::option;

#[test]
fn test_setenv() {
    // NB: Each test of setenv needs to use different variable names or the
    // tests will not be threadsafe
    setenv("NAME1", "VALUE");
    assert getenv("NAME1") == option::some("VALUE");
}

#[test]
fn test_setenv_overwrite() {
    setenv("NAME2", "1");
    setenv("NAME2", "2");
    assert getenv("NAME2") == option::some("2");
}

// Windows GetEnvironmentVariable requires some extra work to make sure
// the buffer the variable is copied into is the right size
#[test]
fn test_getenv_big() {
    auto s = "";
    auto i = 0;
    while (i < 100) {
        s += "aaaaaaaaaa";
        i += 1;
    }
    setenv("NAME3", s);
    assert getenv("NAME3") == option::some(s);
}

// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:

import std::generic_os::setenv;
import std::generic_os::getenv;
import std::option;

#[test]
fn test_setenv() {
    setenv("NAME", "VALUE");
    assert getenv("NAME") == option::some("VALUE");
}

#[test]
fn test_setenv_overwrite() {
    setenv("NAME", "1");
    setenv("NAME", "2");
    assert getenv("NAME") == option::some("2");
}

// Windows GetEnvironmentVariable requires some extra work to make sure
// the buffer the variable is copied into is the right size
#[test]
fn test_getenv_big() {
    auto s = "";
    auto i = 0;
    while (i < 100) {
        s += "aaaaaaaaaa";
        i += 1;
    }
    setenv("NAME", s);
    assert getenv("NAME") == option::some(s);
}

// Local Variables:
// mode: rust;
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
// End:

--- 
+++ 
@@ -4,15 +4,17 @@
 
 #[test]
 fn test_setenv() {
-    setenv("NAME", "VALUE");
-    assert getenv("NAME") == option::some("VALUE");
+    // NB: Each test of setenv needs to use different variable names or the
+    // tests will not be threadsafe
+    setenv("NAME1", "VALUE");
+    assert getenv("NAME1") == option::some("VALUE");
 }
 
 #[test]
 fn test_setenv_overwrite() {
-    setenv("NAME", "1");
-    setenv("NAME", "2");
-    assert getenv("NAME") == option::some("2");
+    setenv("NAME2", "1");
+    setenv("NAME2", "2");
+    assert getenv("NAME2") == option::some("2");
 }
 
 // Windows GetEnvironmentVariable requires some extra work to make sure
@@ -25,8 +27,8 @@
         s += "aaaaaaaaaa";
         i += 1;
     }
-    setenv("NAME", s);
-    assert getenv("NAME") == option::some(s);
+    setenv("NAME3", s);
+    assert getenv("NAME3") == option::some(s);
 }
 
 // Local Variables:
Make the setenv tests threadsafe(ish)
