package som.tests;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.BeforeClass;
import org.junit.Test;

import som.vm.VmOptions;
import som.vm.VmSettings;


public class VMTests {
  @BeforeClass
  public static void enableInstrumentation() {
    System.setProperty(VmSettings.INSTRUMENTATION_PROP, "true");
  }

  @Test
  public void testProcessArgumentsNothing() {
    VmOptions opts = new VmOptions(new String[0]);
    assertEquals(opts.platformFile, VmOptions.STANDARD_PLATFORM_FILE);
    assertArrayEquals(opts.args, new String[0]);
  }

  @Test
  public void testProcessArgumentsWithPlatformFile() {
    VmOptions opts = new VmOptions(
        new String[] {"--platform", "foo.ns"});
    assertEquals(opts.platformFile, "foo.ns");
    assertArrayEquals(opts.args, new String[0]);
  }

  @Test
  public void testProcessArgumentsWithKernelFile() {
    VmOptions opts = new VmOptions(
        new String[] {"--kernel", "foo.ns"});
    assertEquals(opts.kernelFile, "foo.ns");
    assertArrayEquals(opts.args, new String[0]);
  }

  @Test
  public void testProcessArgumentsWithAppFile() {
    VmOptions opts = new VmOptions(
        new String[] {"app.ns"});
    assertEquals(opts.platformFile, VmOptions.STANDARD_PLATFORM_FILE);
    assertArrayEquals(opts.args, new String[] {"app.ns"});
  }

  @Test
  public void testProcessArgumentsWithAppFileAndArgs() {
    VmOptions opts = new VmOptions(
        new String[] {"app.ns", "Foo", "1", "2"});
    assertEquals(opts.platformFile, VmOptions.STANDARD_PLATFORM_FILE);
    assertArrayEquals(opts.args, new String[] {"app.ns", "Foo", "1", "2"});
  }

  @Test
  public void testProfileFlag() {
    VmOptions opts = new VmOptions(
        new String[] {"--profile"});
    assertEquals(opts.platformFile, VmOptions.STANDARD_PLATFORM_FILE);
    assertTrue(opts.profilingEnabled);
    assertArrayEquals(opts.args, new String[0]);
  }
}

@@ -1739,24 +1739,36 @@
 ileFlag() %7B%0A
+    try %7B%0A  
     VmOption
@@ -1791,32 +1791,34 @@
 ptions(%0A        
+  
 new String%5B%5D %7B%22-
@@ -1826,32 +1826,34 @@
 profile%22%7D);%0A    
+ 
+ 
 assertEquals(opt
@@ -1903,24 +1903,26 @@
 _FILE);%0A    
+  
 assertTrue(o
@@ -1944,24 +1944,26 @@
 abled);%0A    
+ 
+ 
 assertArrayE
@@ -1991,18 +1991,227 @@
 String%5B0%5D);%0A
+    %7D catch (IllegalStateException e) %7B%0A      assertTrue(%22If it fails, expect that it complains that instrumentation is not enabled%22,%0A          e.getMessage().contains(VmSettings.INSTRUMENTATION_PROP));%0A    %7D%0A
   %7D%0A%7D%0A

Make VmOptions test robust to instrumentation flag not set