You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@joshua.apache.org by mj...@apache.org on 2016/09/18 00:14:00 UTC

[27/30] incubator-joshua git commit: don't crash test

don't crash test


Project: http://git-wip-us.apache.org/repos/asf/incubator-joshua/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-joshua/commit/a47d7272
Tree: http://git-wip-us.apache.org/repos/asf/incubator-joshua/tree/a47d7272
Diff: http://git-wip-us.apache.org/repos/asf/incubator-joshua/diff/a47d7272

Branch: refs/heads/7_confsystem
Commit: a47d72725a8ca97ed48d9f8279a949982462f69b
Parents: c602ba5
Author: Matt Post <po...@cs.jhu.edu>
Authored: Sat Sep 17 22:19:14 2016 +0200
Committer: Matt Post <po...@cs.jhu.edu>
Committed: Sat Sep 17 22:19:14 2016 +0200

----------------------------------------------------------------------
 .../joshua/decoder/cky/DoNotCrashTest.java      | 89 +++++++++++---------
 .../src/test/resources/decoder/dont-crash/input | 10 ---
 .../test/resources/decoder/dont-crash/test.sh   | 29 -------
 3 files changed, 47 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/a47d7272/joshua-core/src/test/java/org/apache/joshua/decoder/cky/DoNotCrashTest.java
----------------------------------------------------------------------
diff --git a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/DoNotCrashTest.java b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/DoNotCrashTest.java
index 4623040..2496a98 100644
--- a/joshua-core/src/test/java/org/apache/joshua/decoder/cky/DoNotCrashTest.java
+++ b/joshua-core/src/test/java/org/apache/joshua/decoder/cky/DoNotCrashTest.java
@@ -1,62 +1,67 @@
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
  *
- *  http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
  */
 package org.apache.joshua.decoder.cky;
 
 import static org.apache.joshua.decoder.cky.TestUtil.decodeList;
-import static org.apache.joshua.decoder.cky.TestUtil.loadStringsFromFile;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.joshua.decoder.Decoder;
-import org.apache.joshua.decoder.JoshuaConfiguration;
+
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
+import com.typesafe.config.Config;
+import com.typesafe.config.ConfigValueFactory;
+
+import static org.testng.Assert.assertEquals;
+
 public class DoNotCrashTest {
 
-	private JoshuaConfiguration joshuaConfig = null;
-	private Decoder decoder = null;
-
-	@BeforeMethod
-	public void setUp() throws Exception {
-		joshuaConfig = new JoshuaConfiguration();
-		decoder = new Decoder(joshuaConfig);
-	}
-
-	@AfterMethod
-	public void tearDown() throws Exception {
-		decoder.cleanUp();
-		decoder = null;
-	}
-
-	@Test
-	public void givenProblematicInput_whenDecoding_thenNoCrash() throws IOException {
-		// Given
-		List<String> inputStrings = loadStringsFromFile("src/test/resources/decoder/dont-crash/input");
-		
-		// When
-		decodeList(inputStrings, decoder, joshuaConfig);
-		
-		// Then
-		// Did not crash
-	}
+  private Decoder decoder = null;
+
+  private String[] NASTIES = { 
+      "[]", "[X]", "|||", "|", "(((", "|| | |", "|| |", "| asdf|", "||", "| ?| test" 
+  };
+
+  @BeforeMethod
+  public void setUp() throws Exception {
+    Config config = Decoder.getDefaultFlags()
+        .withValue("output_format", ConfigValueFactory.fromAnyRef("%s"));
+    decoder = new Decoder(config);
+  }
+
+  @AfterMethod
+  public void tearDown() throws Exception {
+    decoder.cleanUp();
+    decoder = null;
+  }
+
+  @Test
+  public void givenProblematicInput_whenDecoding_thenNoCrash() throws IOException {
+    List<String> inputs = new ArrayList<String>();
+    for (String nasty: this.NASTIES)
+      inputs.add(nasty);
+    
+    // When
+    List<String> outputs = decodeList(inputs, decoder);
 
+    // Then
+    assertEquals(outputs, inputs);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/a47d7272/joshua-core/src/test/resources/decoder/dont-crash/input
----------------------------------------------------------------------
diff --git a/joshua-core/src/test/resources/decoder/dont-crash/input b/joshua-core/src/test/resources/decoder/dont-crash/input
deleted file mode 100644
index 7a8d05e..0000000
--- a/joshua-core/src/test/resources/decoder/dont-crash/input
+++ /dev/null
@@ -1,10 +0,0 @@
-[]
-[X]
-|||
-|
-(((
-|| | |
-|| |
-| asdf|
-||
-| ?| test

http://git-wip-us.apache.org/repos/asf/incubator-joshua/blob/a47d7272/joshua-core/src/test/resources/decoder/dont-crash/test.sh
----------------------------------------------------------------------
diff --git a/joshua-core/src/test/resources/decoder/dont-crash/test.sh b/joshua-core/src/test/resources/decoder/dont-crash/test.sh
deleted file mode 100755
index 182ae82..0000000
--- a/joshua-core/src/test/resources/decoder/dont-crash/test.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-set -u
-
-cat input | $JOSHUA/bin/joshua-decoder -output-format %s > output 2> log
-
-diff -u output input > diff
-
-if [ $? -eq 0 ]; then
-    rm -f log output diff
-    exit 0
-else
-    exit 1
-fi